Worktree sessions inherit additional directories from base repo without remapping

Resolved 💬 2 comments Opened Apr 5, 2026 by is-primary-dev Closed May 15, 2026

Summary

When a Claude Desktop project has additional working directories configured, and a worktree session is created from that project, the additional directories still point to the base repo paths instead of being remapped to the worktree. This causes file operations to silently target the wrong git tree.

Environment

  • Claude Code version: 2.1.87
  • Platform: Windows 11 Pro
  • Entrypoint: Claude Desktop

Reproduction

  1. Open a Claude Desktop project at C:\repo\myproject
  2. Add additional working directories (e.g., C:\repo\myproject\src\foo, C:\repo\myproject\src\bar)
  3. Create a worktree session — primary working directory changes to C:\repo\myproject\.claude\worktrees\<name>
  4. Check the system prompt environment section

Expected: Additional directories are remapped to worktree equivalents:

Primary working directory: C:\repo\myproject\.claude\worktrees\<name>
Additional working directories:
  - C:\repo\myproject\.claude\worktrees\<name>\src\foo
  - C:\repo\myproject\.claude\worktrees\<name>\src\bar

Actual: Additional directories still point to the base repo:

Primary working directory: C:\repo\myproject\.claude\worktrees\<name>
Additional working directories:
  - C:\repo\myproject\src\foo
  - C:\repo\myproject\src\bar
  - C:\repo\myproject

Impact

  • Read/Write tools operate on the wrong git tree. When the model uses paths from the additional directories list, it reads/writes files in the base repo (on main) instead of the worktree branch. Changes don't show up in git status for the worktree.
  • Silent failure. There's no error — the files exist at both paths (same repo content). The problem only becomes visible at commit time when git status shows a clean worktree despite extensive file modifications.
  • Wasted tokens on redo. Discovering the issue at commit time requires restoring the base repo to clean state and redoing all file operations at the correct worktree paths.

Transcript evidence

The session transcript shows the cwd field alternating on every message:

  • User messages (from Claude Desktop): cwd = base repo path
  • System messages (worktree correction): cwd = worktree path

The worktree system correctly overrides the primary cwd for tool execution, but the additional directories list is never rewritten.

git-worktrees.json has the mapping

The baseRepo field in git-worktrees.json already provides the information needed to remap:

{
  "name": "keen-knuth",
  "path": "C:\repo\.claude\worktrees\keen-knuth",
  "baseRepo": "C:\repo",
  "branch": "claude/keen-knuth"
}

Any additional directory starting with baseRepo could be remapped by replacing the baseRepo prefix with the worktree path.

View original on GitHub ↗

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