Path encoding collision causes session loss on directory reorganization

Resolved 💬 5 comments Opened Jan 26, 2026 by MyronKoch Closed Mar 1, 2026

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

  1. Create a directory with hyphens in the path: /tmp/foo-bar/project
  2. Run Claude Code, have a conversation
  3. Rename the directory structure: mv /tmp/foo-bar /tmp/foo && mkdir -p /tmp/foo/bar
  4. Move project: mv /tmp/foo/project /tmp/foo/bar/
  5. Navigate to new location and run claude --continue
  6. 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

  1. Use lossless encoding: Consider URL-encoding or base64 for path segments, or use a delimiter that can't appear in filenames (like \x00 internally, stored as hex)
  1. Better error messaging: When no sessions found, suggest checking ~/.claude/projects/ for similarly-named folders
  1. Session discovery: Add claude sessions list command to show all sessions across all projects with their original paths
  1. 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

View original on GitHub ↗

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