Path encoding collision causes session loss on directory reorganization
Description
When working directories contain hyphens in their names, the path-to-folder encoding scheme can cause sessions to become inaccessible after filesystem reorganization, and in edge cases, could cause unrelated projects to collide.
Root Cause
Claude Code encodes working directory paths by replacing / with - to create project folder names in ~/.claude/projects/. This encoding is lossy when directory names contain hyphens:
/Volumes/ARCHIVE/M1-CLEANUP/M1-SALVAGE/project → -Volumes-ARCHIVE-M1-CLEANUP-M1-SALVAGE-project
/Volumes/ARCHIVE/M1/CLEANUP-M1/SALVAGE/project → -Volumes-ARCHIVE-M1-CLEANUP-M1-SALVAGE-project
Both paths encode to the same folder name, making decoding ambiguous.
Reproduction Steps
- Create a directory with hyphens in the path:
/tmp/foo-bar/project - Run Claude Code, have a conversation
- Rename the directory structure:
mv /tmp/foo-bar /tmp/foo && mkdir -p /tmp/foo/bar - Move project:
mv /tmp/foo/project /tmp/foo/bar/ - Navigate to new location and run
claude --continue - Sessions appear "lost" even though data exists in
~/.claude/projects/
Impact
- Data appears lost: Users see "no sessions found" when data is actually intact
- Confusing error: No indication that sessions exist under a different encoded path
- External drives: Particularly affects external drives that may remount at different paths
- Potential collision: Two genuinely different projects could theoretically share session data
Real-World Case
User had 93MB of session history from /Volumes/ARCHIVE/M1-CLEANUP/M1-SALVAGE/sDEALIO. After reorganizing to /Volumes/ARCHIVE/M1/CLEANUP-M1/SALVAGE/sDEALIO, sessions appeared lost. Data was intact but path matching failed.
Suggested Improvements
- Use lossless encoding: Consider URL-encoding or base64 for path segments, or use a delimiter that can't appear in filenames (like
\x00internally, stored as hex)
- Better error messaging: When no sessions found, suggest checking
~/.claude/projects/for similarly-named folders
- Session discovery: Add
claude sessions listcommand to show all sessions across all projects with their original paths
- Path association: Allow manually associating a project folder with the current working directory
Environment
- Claude Code: Latest (January 2026)
- macOS: Darwin 25.2.0
- Discovered during external drive session recovery
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗