fix(claudecode): encode dots in project key to match Claude Code CLI behavior#820
Open
Re-TinyLin wants to merge 1 commit intochenhg5:mainfrom
Open
fix(claudecode): encode dots in project key to match Claude Code CLI behavior#820Re-TinyLin wants to merge 1 commit intochenhg5:mainfrom
Re-TinyLin wants to merge 1 commit intochenhg5:mainfrom
Conversation
…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>
chenhg5
approved these changes
Apr 30, 2026
Owner
chenhg5
left a comment
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
encodeClaudeProjectKeyfunction 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/projectThe encoded candidate key becomes:
-home-user.name-projectwhile the actual on-disk directory is:
-home-user-name-projectThe primary lookup, all legacy candidates, and the fallback scan all miss because they all derive from the same
encodeClaudeProjectKeyoutput. As a result,findProjectDirreturns"",ListSessionsreturnsnil, and/listand/switchshow "No sessions found".Fix
Extend the replacement set in
encodeClaudeProjectKeyto 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 passTestEncodeClaudeProjectKeycase: "path with dots (e.g. username in home dir)"TestFindProjectDir_DotInPathregression test — creates a mock~/.claude/projects/-home-user-name-project/directory and assertsfindProjectDirresolves the dotted work dirgo test ./...passes/listreturned "No sessions found"; after the fix sessions are visibleCo-Authored-By: Claude Opus 4.7 noreply@anthropic.com
🤖 Generated with Claude Code