Skip to content

fix(parser): use Claude cwd for Windows project paths - #245

Merged
iamtoruk merged 2 commits into
mainfrom
fix/windows-canonical-cwd
May 6, 2026
Merged

iamtoruk merged 2 commits into
mainfrom
fix/windows-canonical-cwd

Conversation

@iamtoruk

@iamtoruk iamtoruk commented May 6, 2026

Copy link
Copy Markdown
Member

Supersedes #228 (cross-fork PR by @ozymandiashh — original commit preserved as the first commit here, follow-up commit applies review fixes).

Summary

Closes #217. Claude Code stores project sessions under sanitized directory slugs that are lossy on Windows: C:\AI_LAB\OPENCLAW becomes a slug like c--AI-LAB-OPENCLAW, and the slug → path round-trip turns it into c//AI/LAB/OPENCLAW (every - becomes /, eats underscores). Combined with drive-letter case differences and forward/backward slash variants in real cwds, one project ends up split into 3+ rows in CodeBurn output.

This PR reads the canonical cwd already stored inside each Claude JSONL session, uses it as projectPath, and groups sessions by a normalized path key (backslash → /, strip trailing /, lowercase).

What changed (from #228)

  • Extract the first valid cwd from each Claude JSONL session.
  • Use cwd as projectPath for Claude project rollups instead of the slug-derived reconstruction.
  • Group sessions by normalized path key so C:\AI_LAB\OPENCLAW, c:\AI_LAB\OPENCLAW, and c:/AI_LAB/OPENCLAW/ collapse into one project rollup.
  • Preserve slug-derived fallback for old or malformed sessions without cwd.

Review fix on top of #228

Adversarial probe found that when a slug contains both cwd-bearing and no-cwd sessions, scanProjectDirs created two ProjectSummary entries sharing the same dirName (one keyed on cwd, one keyed on slug). They later merged in parseAllSessions by p.project, and whichever entry was created first set projectPath. So a project with an alphabetically-early no-cwd session silently kept the lossy slug-derived projectPath even though a clean canonical cwd was available on later sessions in the same directory.

Added a consolidation step at the end of scanProjectDirs that folds slug-keyed entries into the cwd-keyed entry sharing the same dirName, so canonical cwd always wins regardless of file iteration order.

Tests

Two test cases added on top of the original two:

  • Mixed cwd / no-cwd in same slug — alphabetically-first file has no cwd, second has C:\AI_LAB\OPENCLAW. Asserts projectPath is the canonical Windows path, not c//AI/LAB/OPENCLAW.
  • Null / empty / whitespace / missing cwd — four sessions in the same slug with various invalid cwd values, asserts they all group together and fall back to the slug-derived path.

Validation

Related (not in scope)

Issue #217 also mentions Antigravity sessions surfacing as opaque ID-paths. That's a separate path-resolution concern in a different provider; this PR is scoped to Claude Code only and leaves Antigravity discovery untouched. Worth a follow-up issue.

What it does NOT touch

Token parsing, pricing, classification, date filtering, non-Claude providers, dashboard rendering. Only the project-rollup grouping logic in scanProjectDirs.

ozymandiashh and others added 2 commits May 5, 2026 13:47
Without this consolidation step, a Claude project containing both
cwd-bearing and no-cwd session files ended up with two ProjectSummary
entries sharing the same dirName: one keyed on the canonical cwd, one
keyed on the slug. They later merged in parseAllSessions by p.project,
and the projectPath of whichever entry was created first won. So a
project with one alphabetically-early no-cwd session would silently
keep the lossy slug-derived projectPath even though a clean canonical
cwd was available on later sessions.

Fold slug-keyed entries into the cwd-keyed entry sharing the same
dirName during scanProjectDirs so canonical cwd always wins.

Tests added:
- mixed cwd / no-cwd in same slug -> canonical projectPath preserved
- null / empty / whitespace / missing cwd -> slug-derived fallback
@iamtoruk
iamtoruk merged commit 6151cf6 into main May 6, 2026
3 checks passed
@iamtoruk
iamtoruk deleted the fix/windows-canonical-cwd branch May 6, 2026 06:53
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.

Windows: same project shown under 3+ paths (case + slash variants), splitting cost/session counts

2 participants