EnterWorktree branches from session CWD HEAD, not main branch HEAD
Resolved 💬 3 comments Opened Mar 11, 2026 by micon4sure Closed Mar 15, 2026
Bug
When a Claude Code session is operating inside an existing worktree (or has previously used EnterWorktree), calling EnterWorktree again creates the new worktree branched from the session's current working directory HEAD, not from the main repo's actual branch HEAD (e.g., master).
This means if the session's CWD is in a worktree that's behind master (e.g., because commits were made to master after the worktree was created), the new worktree silently branches from a stale commit.
Impact
In my case:
- I committed work to master (
c4e4d39) - I used
EnterWorktreeto create a new worktree for a separate task - The new worktree branched from an older commit (
e19a8aa) — the HEAD of a previous worktree, not master's HEAD - All work done in the new worktree was based on stale code
- Attempting
git mergeinto master resulted in 9 conflicts - Had to abort the merge and manually re-apply all changes directly on master
This silently wasted significant time and tokens — the work had to be redone.
Expected behavior
EnterWorktree should either:
- Always branch from the main repo's HEAD (e.g.,
masterormain), regardless of which worktree the session is currently in - Warn the user when the session's HEAD differs from the main branch, and ask which commit to branch from
- Accept a base ref parameter so the user can explicitly specify what to branch from
Environment
- Claude Code CLI on WSL2 (Linux)
- Git repo with multiple worktrees
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗