[BUG] Auto memory is orphaned in git worktrees due to inconsistent path resolution between sessions
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:
- Always resolve to the main git root (and migrate/merge existing worktree-specific memory folders), or
- 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
- Create a git worktree from a repository:
cd ~/src/myprojectgit worktree add ../myproject-worktrees/feature-branch feature-branch
- Open Claude Code in the worktree directory:
cd ~/src/myproject-worktrees/feature-branchclaude
- 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/. - Start a new Claude Code session in the same worktree directory.
- Observe that the system prompt now points to
~/.claude/projects/-home-user-src-myproject/memory/(the main repo path), which is empty. - 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.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗