Session directory slug encoding replaces underscores with hyphens (undocumented)
Description
Claude Code's session directory slugs (stored at ~/.claude/projects/) replace both / and _ with - when encoding the project path. The / → - replacement is intuitive, but the _ → - replacement is undocumented and causes issues when programmatically resolving session directories from project paths.
Example
Project path: /home/chris/2_project-files/projects/m2-clients/101-cal
Expected slug (replace only /): -home-chris-2_project-files-projects-m2-clients-101-cal
Actual slug: -home-chris-2-project-files-projects-m2-clients-101-cal
The underscore in 2_project-files becomes a hyphen in the slug.
Impact
Any tooling that needs to map a filesystem path to its Claude Code session directory (e.g., session mining scripts, analytics tools) must know about this undocumented encoding rule. A naive path.replace("/", "-") fails silently — the slug doesn't match, so the session directory appears not to exist.
Request
Document the slug encoding algorithm, or expose it as a CLI utility (e.g., claude session-dir --path /some/project).
Environment
- Claude Code version: current (Feb 2026)
- OS: Debian 12 / DietPi on Raspberry Pi 5 (ARM64)
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗