Resumed session inside a git worktree acts as the root worktree (commits land on root's branch)

Status Open
Reported on v2.1.217
Maintainer reply None cached
Activity 0 comments · opened Jul 22, 2026

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

  1. A session is started with its cwd inside worktree X (branch feat-x).
  2. The session is later resumed (new process / --resume).
  3. The resumed session's git context is the root worktree, not X.
  4. git commit therefore writes to the root worktree's HEAD branch, not feat-x.
  5. 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)

  1. Create a repo with a root worktree on root-branch and a linked worktree wt (git worktree add) on feat-x.
  2. Start a Claude Code session with cwd inside wt.
  3. Resume that session (restart / --resume).
  4. Have it make any commit.
  5. Observe the commit landed on root-branch (root worktree) rather than feat-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.

View original on GitHub ↗