Auto memory saved in git worktrees is silently orphaned when worktree is deleted
Bug description
When working in a git worktree, Claude Code's auto memory (MEMORY.md) is saved to a project directory derived from the worktree's CWD path, not the main repository path. This means:
- Memories saved during worktree sessions are invisible to sessions in the main repo
- When the worktree is deleted, the memories are orphaned — they exist in a project directory for a path that no longer exists
This is a silent data loss issue. The user gets no warning that their memories are being saved to an ephemeral location.
Steps to reproduce
- Open Claude Code in a repo:
cd ~/myrepo && claude - Save a memory: "Remember that the API uses pagination"
- Verify memory is saved to
~/.claude/projects/-Users-me-myrepo/memory/MEMORY.md - Create and enter a worktree: use
EnterWorktreeorclaude -w my-feature - Save another memory: "The auth module uses JWT tokens"
- Check where it was saved:
~/.claude/projects/-Users-me-myrepo--claude-worktrees-my-feature/memory/MEMORY.md - Exit and delete the worktree
- Open Claude Code in the main repo again
- The JWT memory from step 5 is gone — it's in the orphaned project directory
Expected behavior
Memories saved during a worktree session should be accessible from the main repo, since worktrees are just different views of the same repository. Options:
- Save to the main repo's project directory (preferred — worktrees share the same
.git). This would also resolve the duplicate-loading issues in #16600, #24283, and #27082, since there would be only one project directory for the repo regardless of which worktree is the CWD. - At minimum, warn the user that memories will be lost when the worktree is deleted
Actual behavior
Memories are silently saved to a worktree-path-specific project directory with no indication they won't persist.
Additional context
Related but distinct from:
- #16600 (memory traversal should respect worktree boundaries — about duplicate loading)
- #24283 (memory files loaded twice — about duplicate loading causing quota exhaustion)
- #27082 (CLAUDE.md loaded twice — about duplicate context)
Those issues are about files being loaded twice (from both worktree and main repo). This issue is about the opposite problem: memories being saved to only the worktree location and becoming inaccessible from the main repo.
Environment
- Claude Code version: 2.1.49
- OS: macOS 15.4
- Git worktree created via
EnterWorktreetool orclaude -w
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗