[BUG] Project path encoding collision: different paths can map to the same project directory
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?
Claude Code encodes project paths by replacing /, -, and _ all with - when creating project directories under ~/.claude/projects/. This is a lossy encoding that can cause different project paths to map to the same directory.
For example:
- /home/user/project/spec-rl/ → -home-user-project-spec-rl
- /home/user/project/spec/rl/ → -home-user-project-spec-rl
Both produce the same encoded directory name, so two different projects would share memory, settings, and CLAUDE.md.
Similarly with underscores:
- /home/user/my_project/ → -home-user-my-project
- /home/user/my-project/ → -home-user-my-project
What Should Happen?
Each unique project path should map to a unique project directory. The encoding should be injective.
Error Messages/Logs
Steps to Reproduce
- mkdir -p ~/test/spec-rl && mkdir -p ~/test/spec/rl
- Run Claude Code in ~/test/spec-rl, save a memory
- Run Claude Code in ~/test/spec/rl
- Both sessions use the same ~/.claude/projects/ directory
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.77
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
Other
Additional Information
Possible fix: use a delimiter that doesn't appear in path components,
e.g. encode each segment separately or use double-dash -- as separator
so /home/user/spec-rl → -home--user--spec-rl
vs /home/user/spec/rl → -home--user--spec--rl.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗