Skip to content

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

Closed
ozymandiashh wants to merge 1 commit into
getagentseal:mainfrom
ozymandiashh:fix/windows-canonical-cwd
Closed

ozymandiashh wants to merge 1 commit into
getagentseal:mainfrom
ozymandiashh:fix/windows-canonical-cwd

Conversation

@ozymandiashh

@ozymandiashh ozymandiashh commented May 5, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Claude Code stores project sessions under sanitized directory slugs. On Windows that slug is lossy: a real path like C:\AI_LAB\OPENCLAW can appear as a directory such as c--AI-LAB-OPENCLAW. CodeBurn was trying to reconstruct the project path from that slug by replacing every - with /, which turns the example into c//AI/LAB/OPENCLAW and can split one real project into multiple rows when casing or slash style differs.

This PR makes the Claude parser use the canonical cwd already present inside the JSONL session data. That preserves the real Windows path, keeps underscores and drive letters intact, and groups case/slash variants of the same cwd into one project rollup.

What changed

  • Extract the first valid cwd from each Claude JSONL session and carry it alongside the parsed session summary.
  • Use that cwd as projectPath for Claude project rollups instead of reconstructing paths from directory slugs.
  • Group Claude sessions by a normalized path key so C:\AI_LAB\OPENCLAW, c:\AI_LAB\OPENCLAW, and c:/AI_LAB/OPENCLAW/ collapse into one project.
  • Preserve the existing slug-derived fallback for old or malformed sessions that do not contain cwd.
  • Add regression coverage for the Windows path bug and for grouped case/slash variants.
  • Add an Unreleased changelog note.

Closes #217.

Why this is safe

The change is limited to Claude project rollup grouping. It does not change token parsing, pricing, date filtering, classification, or non-Claude providers. Existing sessions without cwd keep the old behavior.

Validation

  • npx tsc --noEmit
  • npx vitest run tests/parser-claude-cwd.test.ts tests/security/prototype-pollution.test.ts tests/parser-filter.test.ts tests/date-range-filter.test.ts
  • npx vitest run
  • npm run build

@iamtoruk

iamtoruk commented May 6, 2026

Copy link
Copy Markdown
Member

Superseded by #245, which carries your original commit forward and adds a review fix on top:

Bug found: when a slug contained both cwd-bearing and no-cwd sessions, your scanProjectDirs created two ProjectSummary entries sharing the same dirName (one cwd-keyed, one slug-keyed). They later merged in parseAllSessions by p.project, and whichever was created first set projectPath. An alphabetically-early no-cwd session would silently win, leaving the lossy slug-derived path even though a clean canonical cwd was available on later sessions in the same directory.

Fix: added a consolidation step at the end of scanProjectDirs that folds slug-keyed entries into the cwd-keyed entry sharing the same dirName.

Tests added:

  • mixed cwd / no-cwd in same slug → canonical projectPath wins regardless of iteration order
  • null / empty / whitespace / missing cwd → slug-derived fallback still works

Closing in favor of #245. Thanks for the patch — the cwd-from-JSONL approach was the right call.

@iamtoruk iamtoruk closed this May 6, 2026
iamtoruk added a commit that referenced this pull request May 6, 2026
Reads the canonical cwd already stored inside Claude session JSONL files and uses it as the project path, then groups sessions by a normalized path key (case + slash insensitive) so Windows projects no longer split into 3+ rows on case/slash variants. Falls back to the legacy slug-derived path when cwd is missing. Closes #217. Supersedes #228 with a fix that preserves the canonical cwd even when mixed with slug-only sessions in the same directory. Original implementation by @ozymandiashh.
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