[BUG] # Bug Report: Project directory key converts underscores to hyphens, causing ambiguous path mapping

Resolved 💬 3 comments Opened Mar 26, 2026 by ArgoGach Closed Mar 30, 2026

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 version: 2.1.82
Platform: Linux (Linux Mint 22.3)

Summary

When Claude Code generates the project directory key under ~/.claude/projects/, it converts underscores in the working directory path to hyphens, in addition to replacing path separators (/) with hyphens. This produces an ambiguous key that cannot be round-tripped back to a unique filesystem path.

What Should Happen?

Expected Behavior

The project key should only replace path separator characters (/) with hyphens. Underscores are valid directory name characters and should be preserved:

/opt/Agent_risshq_pm  →  -opt-Agent_risshq_pm   ✓

Error Messages/Logs

Steps to Reproduce

Steps to Reproduce

  1. Create a working directory with an underscore in the name:

``
mkdir /opt/Agent_risshq_pm
``

  1. Start Claude Code from that directory:

``
cd /opt/Agent_risshq_pm && claude
``

  1. Observe the project directory created under ~/.claude/projects/:

``
ls ~/.claude/projects/
# → -opt-Agent-risshq-pm ← underscores converted to hyphens
``

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.82

Platform

Anthropic API

Operating System

Other Linux

Terminal/Shell

Xterm

Additional Information

Actual Behavior

Underscores are also converted to hyphens:

/opt/Agent_risshq_pm  →  -opt-Agent-risshq-pm   ✗

Why This Is a Problem

The hyphenated key is ambiguous — it maps equally to multiple distinct paths:

  • /opt/Agent_risshq_pm
  • /opt/Agent/risshq_pm

This means Claude Code cannot reliably determine which filesystem path a project key corresponds to.

Impact

  • On first launch from the underscore-named directory, Claude Code creates a new empty project directory (the hyphenated key) instead of finding the existing project directory (the underscore key).
  • All previously written memory, session history, and project context in the underscore-keyed directory is silently unreachable.
  • Users who rename their Claude project directory to match the expected key (e.g. -opt-Agent_risshq_pm) will find it is never used, because Claude Code always generates the hyphenated key at startup.

Workaround

Avoid underscores in working directory names. Use hyphens instead (e.g. /opt/Agent-risshq-pm), so the generated key is unambiguous and matches the filesystem path.

Additional Notes

The bug appears to manifest at startup before CLAUDE.md is loaded, so it cannot be worked around via project configuration.

View original on GitHub ↗

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