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:

  1. I committed work to master (c4e4d39)
  2. I used EnterWorktree to create a new worktree for a separate task
  3. The new worktree branched from an older commit (e19a8aa) — the HEAD of a previous worktree, not master's HEAD
  4. All work done in the new worktree was based on stale code
  5. Attempting git merge into master resulted in 9 conflicts
  6. 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:

  1. Always branch from the main repo's HEAD (e.g., master or main), regardless of which worktree the session is currently in
  2. Warn the user when the session's HEAD differs from the main branch, and ask which commit to branch from
  3. 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

View original on GitHub ↗

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