fix(worktree-paths): include dot in project path encoding regex#2329
fix(worktree-paths): include dot in project path encoding regex#2329Yeachan-Heo merged 2 commits intoYeachan-Heo:devfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 616c0c1d80
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| function encodeProjectPath(projectPath: string): string { | ||
| return projectPath.replace(/[\\/]/g, '-'); | ||
| return projectPath.replace(/[\\/\\.]/g, '-'); |
There was a problem hiding this comment.
Preserve backslash matching in project-path encoder
The updated regex in encodeProjectPath no longer matches Windows path separators. In a character class, \/ escapes /, so /[\/\.]/g effectively matches only / and .; it leaves \ untouched. On Windows (or any \-separated path input), project roots will be encoded incorrectly, so searchSessionHistory will look in the wrong ~/.claude/projects/* directory and miss transcripts.
Useful? React with 👍 / 👎.
Claude Code encodes project directory paths by replacing both path separators (/ \) AND dots (.) with dashes (-). The encoding regex at worktree-paths.ts Strategy 2/3 and session-history-search only replaced separators, missing dots entirely. This caused transcript path resolution to fail silently for any project path containing dots (hidden dirs like .config/, .claude/ worktrees/, or version segments like .v2). Empirically verified: Claude Code v2.1.92 encodes /private/tmp/.omc-dot-test.v2 as -private-tmp--omc-dot-test-v2 (dots replaced with dashes). Also fixes the incorrect JSDoc at line 568 which claimed "dots are preserved" while line 587 correctly documented the dot-to-dash encoding. Fixes Yeachan-Heo#2291 Constraint: Must match Claude Code actual encoding behavior Rejected: Shared utility extraction | minimizes diff for this fix Confidence: high Scope-risk: narrow Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use /[/\\.]/g consistently across both files instead of mixing [\\/\\.] and [/\\.] styles. Both are functionally identical (verified: both match backslash, slash, and dot), but the /[/\\.]/g form is clearer and matches the worktree-paths pattern. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
616c0c1 to
a5e0f7f
Compare
|
Addressed the Codex review in a5e0f7f — normalized Both forms are functionally equivalent (both match /[\\/\\.]/g.test('\\') // true
/[/\\.]/g.test('\\') // trueThe |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a5e0f7fcfe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Encode the main project root the same way Claude Code does: | ||
| // replace path separators with `-`, replace dots with `-`. | ||
| const encodedMain = mainProjectRoot.replace(/[/\\]/g, '-'); | ||
| const encodedMain = mainProjectRoot.replace(/[/\\.]/g, '-'); |
There was a problem hiding this comment.
Escape backslash in encoded project-path regex
resolveTranscriptPath now uses mainProjectRoot.replace(/[/\\.]/g, '-') in intent, but the committed pattern is [/\\.] written as /[/\\.]/? Actually at this line it is /[/\\.]/ in source rendered as /[/\.]/, which does not match \\ separators in JS regex literals. On Windows worktree/main-repo paths, backslashes remain unencoded, so the computed ~/.claude/projects/<encoded> directory is wrong and transcript lookup fails. This same regression appears in the other updated encoder sites in this commit, so path resolution/search can miss existing sessions for \\-separated paths.
Useful? React with 👍 / 👎.
Summary
.to the encoding regex so project paths containing dots are encoded correctly, matching Claude Code's actual behaviorProblem
resolveTranscriptPathStrategy 2/3 andsession-history-searchencode project paths with/[/\]/g(slashes only), but Claude Code also replaces.with-.Empirical proof: Claude Code v2.1.92 encodes
/private/tmp/.omc-dot-test.v2as-private-tmp--omc-dot-test-v2(dots replaced). The current code would produce-private-tmp-.omc-dot-test.v2(dots preserved) — which never matches the actual directory name.This affects any path with
.— hidden dirs (.config/,.claude/worktrees/), version segments (.v2).Fix
Applied to 3 locations + fixed incorrect JSDoc claiming "dots are preserved".
Test plan
resolve-transcript-path.test.tspassesFixes #2291