Git worktrees of the same repo share the same project identity, causing cross-worktree path confusion

Status Closed — duplicate
Maintainer reply None cached
Activity 3 comments · opened Mar 5, 2026 · closed Mar 9, 2026

Description

When using multiple git worktrees for the same repository, Claude Code resolves all worktrees to the same project identity. This causes path confusion and memory/context bleeding between worktrees.

Reproduction steps

  1. Create multiple git worktrees from the same repo:

``
~/dev/code/backend/backend_main (main branch)
~/dev/code/backend/backend_skills (feature branch)
~/dev/code/backend/backend_feature (another feature branch)
``

  1. Start Claude Code from backend_skills worktree
  1. Observe the auto memory directory path in the system prompt:

``
/Users/<user>/.claude/projects/-Users-<user>-dev-code-backend-backend-main/memory/
`
This points to
backend-main, **not** backend_skills`.

Expected behavior

Each worktree should be treated as a separate project with its own:

  • Memory directory (based on the worktree path, not the resolved git root)
  • Project identity

Actual behavior

  • All worktrees share the same project directory key (mapped to backend-main)
  • Claude frequently navigates to sibling worktree directories (backend_main/, backend_feature/) instead of staying in the current worktree
  • Memory files saved in one worktree would be loaded in another
  • This issue does not occur on worktrees with unique repo paths (e.g., standalone clones)

Additional context

  • OS: macOS (Darwin 25.3.0)
  • A CLAUDE.md rule explicitly instructs Claude to stay within the worktree root, but the system-level project resolution overrides this in practice by anchoring the project identity to the wrong path.
  • The sandbox write permissions also reference backend_main instead of the current worktree, reinforcing the wrong path context.

View original on GitHub ↗

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