Resumed session inside a git worktree acts as the root worktree (commits land on root's branch)
Summary
A Claude Code session that was started inside a non-root git worktree, when later resumed, behaves as though it is operating in the root worktree. Git commits it makes land on whatever branch the root worktree has checked out, instead of the branch of the worktree the session was actually started in. Because the mis-targeting is silent, unrelated feature work slowly accumulates on the root branch.
Environment
- Claude Code 2.1.217
- Windows 11 Pro (win32), PowerShell + Git Bash
- Monorepo with ~40 linked worktrees under
.claude/worktrees/; the root worktree sits on its own branch and is not used for real work
Impact
Over weeks, the root worktree's branch silently accumulated 10+ commits that belong to other feature branches — e.g. a design doc that belongs on a repertoire branch, and shared data-registry updates that belong on the integration branch. The commits were stranded on the root branch and absent from their intended branches. Recovering required a manual audit of every root-branch-unique commit (which are genuinely unique vs already present elsewhere) followed by selective salvage/discard.
Observed behavior
- A session is started with its cwd inside worktree
X(branchfeat-x). - The session is later resumed (new process /
--resume). - The resumed session's git context is the root worktree, not
X. git committherefore writes to the root worktree's HEAD branch, notfeat-x.- The user never intends to commit from the root worktree, so these commits are unintentional and misplaced.
Expected behavior
A resumed session should retain the worktree it was originally started in. Its working directory — and therefore the branch its commits target — should remain the original worktree, never silently fall back to the repository's root/main worktree.
Repro (approximate — the resume trigger is the key ingredient)
- Create a repo with a root worktree on
root-branchand a linked worktreewt(git worktree add) onfeat-x. - Start a Claude Code session with cwd inside
wt. - Resume that session (restart /
--resume). - Have it make any commit.
- Observe the commit landed on
root-branch(root worktree) rather thanfeat-x.
Workaround
Park the root worktree on a throwaway branch (e.g. do-not-commit-here) so stray commits are obvious and trivially discarded (git reset/branch delete) instead of polluting a real branch. This contains the damage but does not stop the mis-targeting itself.