Auto memory saved in git worktrees is silently orphaned when worktree is deleted

Resolved 💬 3 comments Opened Feb 24, 2026 by gkatz2 Closed Feb 24, 2026

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:

  1. Memories saved during worktree sessions are invisible to sessions in the main repo
  2. 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

  1. Open Claude Code in a repo: cd ~/myrepo && claude
  2. Save a memory: "Remember that the API uses pagination"
  3. Verify memory is saved to ~/.claude/projects/-Users-me-myrepo/memory/MEMORY.md
  4. Create and enter a worktree: use EnterWorktree or claude -w my-feature
  5. Save another memory: "The auth module uses JWT tokens"
  6. Check where it was saved: ~/.claude/projects/-Users-me-myrepo--claude-worktrees-my-feature/memory/MEMORY.md
  7. Exit and delete the worktree
  8. Open Claude Code in the main repo again
  9. 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 EnterWorktree tool or claude -w

View original on GitHub ↗

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