[BUG] Auto memory is orphaned in git worktrees due to inconsistent path resolution between sessions

Resolved 💬 2 comments Opened Mar 16, 2026 by Perlover Closed Mar 16, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Auto memory data becomes inaccessible when working in a git worktree. Claude Code stores conversation sessions and memory files in a directory derived from the worktree's absolute path (e.g., ~/.claude/projects/-home-user-src-myproject-worktrees-feature-branch/memory/). However, in subsequent sessions, the system
prompt points the LLM to a memory directory derived from the main repository's git root (e.g., ~/.claude/projects/-home-user-src-myproject/memory/). This means memories saved in earlier worktree sessions are silently orphaned and never read back.

What Should Happen?

Memory resolution should be consistent: the path used for reading memories in the system prompt should match the path where memories were previously written. Either:

  1. Always resolve to the main git root (and migrate/merge existing worktree-specific memory folders), or
  2. Always use the worktree-specific CWD-based path for both reading and writing.

All worktrees of the same repo sharing a single memory folder (option 1) seems like the better design, since project knowledge, user preferences, and feedback apply across branches.

Error Messages/Logs

Steps to Reproduce

  1. Create a git worktree from a repository:

cd ~/src/myproject
git worktree add ../myproject-worktrees/feature-branch feature-branch

  1. Open Claude Code in the worktree directory:

cd ~/src/myproject-worktrees/feature-branch
claude

  1. Ask Claude to remember something (e.g., "Remember that I prefer strict TypeScript typing"). Claude saves a memory file to ~/.claude/projects/-home-user-src-myproject-worktrees-feature-branch/memory/.
  2. Start a new Claude Code session in the same worktree directory.
  3. Observe that the system prompt now points to ~/.claude/projects/-home-user-src-myproject/memory/ (the main repo path), which is empty.
  4. The memory saved in step 3 is never loaded — it's orphaned in the worktree-specific folder.

You can verify by listing both directories:

ls ~/.claude/projects/-home-user-src-myproject/memory/
# empty

ls ~/.claude/projects/-home-user-src-myproject-worktrees-feature-branch/memory/
# contains MEMORY.md and saved memory files

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.76

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

Xterm

Additional Information

  • The /memory → "Open Auto Memory Folder" command also opens the main repo path, not the worktree-specific one.
  • Conversation session files (.jsonl) are stored in the worktree-specific directory, adding to the inconsistency.
  • This likely indicates a change in path resolution logic between versions — an older version derived the path from CWD directly, while the current version resolves through git root. Existing worktree memory data was not migrated.
  • Tested on Linux (Ubuntu), Claude Code CLI.

View original on GitHub ↗

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