Relocating a project dir (symlink / new mount) orphans all session history, memory & context — project keyed by raw cwd path
Summary
Claude Code stores per-project state (session transcripts, MEMORY.md, todos, scratchpad) under ~/.claude/projects/<slug>, where <slug> is derived from the literal absolute working-directory path. When a project's directory is relocated — e.g. ~/dev becomes a symlink to an external drive /Volumes/SanDisk2/dev, or the tree is moved to a new mount — Claude Code treats it as a brand-new project. The entire prior session history, memory, and context are orphaned under the old path slug, and storage fragments across multiple slugs (-Users-<user>-dev-... vs -Volumes-SanDisk2-dev-...) for what is the same repo.
Repro
- Have a project at
~/dev/foowith accumulated session history +MEMORY.md. - Move
~/devto an external drive and symlink it back (~/dev -> /Volumes/SanDisk2/dev), or otherwise reach the same project via a different absolute path. - Start Claude Code in the project.
- A new
~/.claude/projects/<new-slug>is created; prior sessions / memory / todos under the old slug are not carried over; the same conversation can even appear under two different slugs.
Impact
- Continuity loss across all projects after a directory move.
MEMORY.mdand recalled context silently not applied (they live under the old slug).- Duplicated/fragmented project dirs; very confusing.
- Compounds with git: stale remote-tracking refs after the move fake "N commits ahead / diverged" until
git fetch, andfatal: not a git repository ... GIT_DISCOVERY_ACROSS_FILESYSTEM not seterrors appear for repos under the/Volumesmount.
Suggested fix
Key project identity by something stable instead of the raw cwd path:
- resolve symlinks /
realpathconsistently when computing the project slug, and/or - derive identity from the git remote URL or a persisted
.claude/project-id, and/or - detect when the same repo appears under a new path and offer to migrate/merge the existing project storage.
Environment
- macOS (darwin), Claude Code CLI.
~/devsymlinked to an external volume/Volumes/SanDisk2/dev.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗