Skip to content

Fold Claude Code worktree sessions into their parent project#154

Open
poppinpixels wants to merge 1 commit into
phuryn:DEVfrom
poppinpixels:fold-worktree-projects
Open

Fold Claude Code worktree sessions into their parent project#154
poppinpixels wants to merge 1 commit into
phuryn:DEVfrom
poppinpixels:fold-worktree-projects

Conversation

@poppinpixels

Copy link
Copy Markdown

Claude Code creates per-session git worktrees under <project>/.claude/worktrees/<generated-name>/ (on by default in the desktop app). Because project_name_from_cwd takes the last two path components, every worktree session becomes its own "project" — my dashboard had 15+ rows like worktrees/elastic-cori-f29409 splitting the real projects' costs.

Changes

  • project_name_from_cwd folds any .claude/worktrees path back to the parent project (POSIX + Windows paths).
  • One-time backfill renames existing worktree sessions from the cwd already stored on turns — no transcript re-read, turns untouched, so token totals cannot drift. Gated by schema_meta worktree_fold_done, mirroring the topic backfill in Add session topic to Recent Sessions table #147.
  • 5 new naming tests + 3 backfill tests; full suite passes (152 tests, stdlib only, no new deps).

Not included

A CHANGELOG entry, since the version-parity test ties the top heading to scanner.VERSION. Suggested bullet for the next TBD section, under Scanner:

Sessions run in a Claude Code worktree (<project>/.claude/worktrees/<name>/) are now attributed to their parent project instead of appearing as one ephemeral worktrees/<name> project each. On upgrade, a one-time migration renames existing worktree sessions using the cwd already stored on their turns — no rescan needed.

Happy to add an opt-out flag if you'd rather keep per-worktree visibility available.

🤖 Generated with Claude Code

Claude Code's per-session worktrees live at
<project>/.claude/worktrees/<generated-name>/, so each worktree session
showed up as its own project (e.g. "worktrees/zen-joliot-603975") in
cost-by-project views, splitting a project's real usage across many
ephemeral rows.

- project_name_from_cwd now folds any .claude/worktrees path back to the
  parent project before taking the last two components (POSIX + Windows).
- One-time backfill renames existing worktree sessions using the cwd
  already stored on their turns — no transcript re-read, turns untouched,
  token totals cannot drift. Gated by schema_meta 'worktree_fold_done',
  mirroring the topic backfill.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant