Skip to content

fix(worktree-paths): include dot in project path encoding regex#2329

Merged
Yeachan-Heo merged 2 commits intoYeachan-Heo:devfrom
shaun0927:fix/worktree-dot-encoding
Apr 7, 2026
Merged

fix(worktree-paths): include dot in project path encoding regex#2329
Yeachan-Heo merged 2 commits intoYeachan-Heo:devfrom
shaun0927:fix/worktree-dot-encoding

Conversation

@shaun0927
Copy link
Copy Markdown
Contributor

@shaun0927 shaun0927 commented Apr 7, 2026

Summary

  • Add . to the encoding regex so project paths containing dots are encoded correctly, matching Claude Code's actual behavior

Problem

resolveTranscriptPath Strategy 2/3 and session-history-search encode 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.v2 as -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

-const encodedMain = mainProjectRoot.replace(/[/\]/g, '-');
+const encodedMain = mainProjectRoot.replace(/[/\.]/g, '-');

Applied to 3 locations + fixed incorrect JSDoc claiming "dots are preserved".

Test plan

  • Existing resolve-transcript-path.test.ts passes
  • HUD correctly resolves transcript for worktree paths containing dots

Fixes #2291

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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, '-');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

shaun0927 and others added 2 commits April 7, 2026 23:08
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>
@shaun0927 shaun0927 force-pushed the fix/worktree-dot-encoding branch from 616c0c1 to a5e0f7f Compare April 7, 2026 14:08
@shaun0927
Copy link
Copy Markdown
Contributor Author

Addressed the Codex review in a5e0f7f — normalized encodeProjectPath regex from /[\\/\\.]/g to /[/\\.]/g for consistency with worktree-paths.ts.

Both forms are functionally equivalent (both match \, /, and .), verified in Node.js:

/[\\/\\.]/g.test('\\') // true
/[/\\.]/g.test('\\')   // true

The /[/\\.]/g form is clearer, so I normalized to avoid confusion.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 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, '-');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

@Yeachan-Heo Yeachan-Heo merged commit 8cd6fc6 into Yeachan-Heo:dev Apr 7, 2026
14 checks passed
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