Feature: Enter/resume existing worktrees, configurable branch naming, hook removal control
Context
I'm building a Claude Code plugin (benkruger/flow) that manages multi-session feature development through an 8-phase lifecycle. Each feature lives in a git worktree that persists across 2-10+ Claude Code sessions.
I investigated using Claude Code's built-in worktree support (EnterWorktree, isolation: "worktree", WorktreeCreate/WorktreeRemove hooks) and found three gaps that prevent integration. The built-in support is designed for ephemeral, single-session agent isolation — which is great for that use case — but doesn't support persistent, multi-session worktree lifecycles.
Requests
1. Enter/resume existing worktree tool
EnterWorktree only creates new worktrees. There is no way to switch a session into an already-existing worktree. For multi-session workflows, session 1 creates the worktree, but sessions 2+ have no platform-level mechanism to re-enter it. The main benefit of EnterWorktree — platform-level directory tracking that survives context compaction — is lost after the first session.
Proposed: A ResumeWorktree tool (or a parameter on EnterWorktree) that switches the session into an existing worktree by path or branch name without creating a new one.
2. Configurable branch naming (no worktree- prefix)
EnterWorktree(name="invoice-pdf-export") creates branch worktree-invoice-pdf-export. The worktree- prefix is hardcoded. Plugins and workflows that manage their own branch naming conventions (state files keyed by branch name, PR branch naming, etc.) need to control the full branch name.
Proposed: Either a branch parameter on EnterWorktree to specify the exact branch name, or a configuration option to disable the prefix.
3. Hook control over worktree removal
WorktreeRemove hooks are informational — they cannot prevent removal. The "keep or remove?" prompt on session exit is the only removal mechanism, and it fires every time. For multi-session features, this means:
- The user is asked to keep/remove on every session exit (noisy)
- An accidental "remove" destroys in-progress work with no recovery
WorktreeCreate already supports exit code 2 to abort creation. The same pattern on WorktreeRemove would let plugins with multi-session lifecycles block accidental cleanup.
Proposed: Let WorktreeRemove hooks return exit code 2 to block removal (matching the WorktreeCreate pattern). Alternatively, a flag on EnterWorktree to opt out of the session-exit removal prompt entirely.
Impact
With all three features, plugins could use EnterWorktree/ResumeWorktree for platform-level directory tracking while keeping their own branch naming, state management, and cleanup lifecycle. The platform-level tracking surviving context compaction is the key benefit — it's something plugins currently can't replicate with instructions alone.
Showing cached comments. Read the full discussion on GitHub ↗
7 Comments
these would be great additions, working around these limitations is a bit annoying
@benkruger Does
WorktreeCreatehook work for you when it comes from a plugin and when user usesclaude --worktree {branch-name}?A
PreToolUsehook on Agent can implement custom worktree management:For listing and entering existing worktrees via a UserPromptSubmit hook:
There are certain problems with that, e.g. project auto-memory feature only works with Claude's built-in worktrees. Otherwise Claude considers separate worktrees as separate projects. But maybe they'll improve that too at some point.
Edit: Apparently this is fixed. They now share memories even without Claude's built-in worktrees.
+1 on the resume-existing-worktree ask. My use case is reviewing two open PRs side by side, each in its own Desktop window, and there's currently no way to get the second session into an already-checked-out worktree without dropping to the shell.
When I select this checkbox, I want the branch & worktree to have a meaningful name, e.g.
authorName/task_id-short_description<img width="209" height="62" alt="Image" src="https://github.com/user-attachments/assets/f453e535-e227-49de-a05e-0d4edc65a086" />
+1 on configurable worktree names, these whatchamacall'em are confusing.