Worktree session lands in a different folder's leftover worktree (cwd doesn't match selected project)

Status Closed — not planned
Reported on v2.1.209
Maintainer reply None cached
Activity 1 comment · opened Jul 18, 2026 · closed Oct 2, 2026

What happens

I have a monorepo whose subdirectories each open their own Claude Code sessions with "create worktree" enabled. Opening a new session for subdirectory B (worktree enabled) silently placed the session's working directory inside a leftover worktree belonging to a different subdirectory A (A/.claude/worktrees/<unrelated-old-task-name>), checked out on an old, unrelated branch.

The session UI header/footer correctly show project B, but the actual cwd is under A. The worktree directory name, the git branch name, and the session title are all three mutually inconsistent — strongly suggesting an existing worktree is being reused instead of a fresh one created under B.

Why it matters

Anything that infers context from cwd breaks. My SessionStart hook parses the cwd path to decide which subdirectory's memory/persona to load. Because cwd pointed at A, the entire session ran with A's identity/context while the UI claimed it was B. It took a long conversation before the mismatch was noticed.

Expected

Opening a worktree session for folder B should create/use a worktree under B (B/.claude/worktrees/...) on a branch tied to this session — never silently land in another folder's unrelated leftover worktree.

Environment

  • Claude Code 2.1.209, Windows 11
  • Monorepo with many nested .claude/worktrees/ directories across subdirectories (created by earlier sessions)

Repro sketch

  1. Monorepo with subdirs A and B, each having had prior worktree sessions (so both A/.claude/worktrees/* and B/.claude/worktrees/* exist)
  2. New session -> select folder B -> enable worktree
  3. Observe cwd landing in an existing A/.claude/worktrees/<old> on an unrelated branch, instead of a new worktree under B

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗