Feature: Enter/resume existing worktrees, configurable branch naming, hook removal control

Open 💬 7 comments Opened Mar 7, 2026 by benkruger

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.

View original on GitHub ↗

This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗