Worktrees should share the same project directory as the main repo

Open 💬 9 comments Opened Mar 14, 2026 by fbaltor

Problem

When using git worktrees (either via claude --worktree or manually created), Claude Code creates a separate project directory in ~/.claude/projects/ for each worktree path. This splits conversation history, auto-memory, and project-level settings across multiple isolated directories — even though the worktrees are branches of the same repository.

For example, working in ~/project and then creating a worktree at ~/project-feature-branch produces:

~/.claude/projects/-home-user-project/           # main
~/.claude/projects/-home-user-project-feature-branch/  # worktree — separate conversations, memory, settings

This means:

  • Auto-memory is fragmented — memories saved in a worktree session are invisible to main repo sessions and vice versa
  • Conversation history is split — the /resume picker may show sessions across worktrees, but project-level context is lost
  • Project settings diverge — each worktree gets its own project config

Over time this creates significant knowledge fragmentation, especially for teams using worktrees for parallel development (e.g., running multiple Claude Code sessions in tmux panes on different branches).

Proposed Solution

Detect when a working directory is a git worktree and resolve the project directory to the main worktree's path instead of the current working directory path.

Git already provides this via:

git worktree list --porcelain  # lists all worktrees and identifies the main one
git rev-parse --git-common-dir  # resolves to the shared .git dir

All worktrees of the same repo would then share:

  • ~/.claude/projects/<main-repo-path>/memory/
  • ~/.claude/projects/<main-repo-path>/*.jsonl (conversations)
  • ~/.claude/projects/<main-repo-path>/ (project-level settings)

Alternative: opt-in configuration

If automatic detection is too opinionated, a configuration option would also work:

// ~/.claude/settings.json or project CLAUDE.md
{
  "projectDirectoryStrategy": "git-root"  // vs default "working-directory"
}

Current Workaround

Manually moving .jsonl files, UUID session directories, and memory files from worktree project directories into the main project directory, then deleting the empty source directories. This works but needs to be repeated after every worktree session.

Environment

  • Claude Code CLI
  • Linux (also applicable to macOS)

View original on GitHub ↗

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