Skip to content

fix(claudecode): encode dots in project key to match Claude Code CLI behavior#820

Open
Re-TinyLin wants to merge 1 commit intochenhg5:mainfrom
Re-TinyLin:fix/encode-project-key-dots
Open

fix(claudecode): encode dots in project key to match Claude Code CLI behavior#820
Re-TinyLin wants to merge 1 commit intochenhg5:mainfrom
Re-TinyLin:fix/encode-project-key-dots

Conversation

@Re-TinyLin
Copy link
Copy Markdown

Summary

The encodeClaudeProjectKey function currently collapses /, :, _, space, ~, and non-ASCII to -, but the Claude Code CLI also collapses dots (.) to - when creating on-disk project keys under ~/.claude/projects/. This causes a mismatch for home directory paths containing dotted usernames like:

/home/user.name/project

The encoded candidate key becomes:

-home-user.name-project

while the actual on-disk directory is:

-home-user-name-project

The primary lookup, all legacy candidates, and the fallback scan all miss because they all derive from the same encodeClaudeProjectKey output. As a result, findProjectDir returns "", ListSessions returns nil, and /list and /switch show "No sessions found".

Fix

Extend the replacement set in encodeClaudeProjectKey to also collapse '.' to '-'. The function is the single source of truth for path encoding, so this one edit fixes both the primary candidate and the fallback scan. The docstring has been updated to reflect the new step (dot handling is inserted as step 4, renumbering the others).

This complements PR #706 (which fixed the space and ~ variants of issue #500) by covering the remaining dot character case.

Test plan

  • go test ./agent/claudecode/ -run 'TestEncodeClaudeProjectKey|TestFindProjectDir' -v — all pass
  • One new TestEncodeClaudeProjectKey case: "path with dots (e.g. username in home dir)"
  • New TestFindProjectDir_DotInPath regression test — creates a mock ~/.claude/projects/-home-user-name-project/ directory and asserts findProjectDir resolves the dotted work dir
  • All pre-existing test cases still pass unchanged
  • Full suite: go test ./... passes
  • Manual confirmation on Linux with a dotted-username home dir: before the fix /list returned "No sessions found"; after the fix sessions are visible

Co-Authored-By: Claude Opus 4.7 noreply@anthropic.com
🤖 Generated with Claude Code

…behavior

Claude Code CLI replaces dots (.) with hyphens (-) in project directory
keys alongside / : _ space and ~, but encodeClaudeProjectKey did not
collapse dots. This caused findProjectDir to miss the on-disk directory
for paths like /home/user.name/project (common with dotted usernames),
making /list always return "No sessions found".

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown
Owner

@chenhg5 chenhg5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Clean, well-scoped fix that aligns encodeClaudeProjectKey with the actual Claude Code CLI behavior for paths containing dots (e.g., /home/user.name/project). This complements PR #706 by covering the remaining special character case.


Correctness: The fix adds . to the replacement set, matching Claude CLI's on-disk encoding. Both primary lookup and fallback scan are now fixed via the single source of truth.

Tests: Excellent coverage — new unit test case for dotted paths and a dedicated regression test TestFindProjectDir_DotInPath that simulates the real scenario.

Documentation: Docstring updated with correct step numbering.

CI: All checks pass.


Verdict: APPROVED — Ready to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants