fix(server): count every provider instance on the Usage page - #7419
fix(server): count every provider instance on the Usage page#7419MatthewFoxAF wants to merge 1 commit into
Conversation
The usage scan only read the default Claude and Codex homes from the legacy `providers.<kind>` settings, so transcripts written by additional provider instances (a second Claude install with its own CLAUDE_CONFIG_DIR, a second Codex home) never showed up. Resolve transcript directories from the same merged instance map the provider registry hydrates from, one entry per distinct home, deduped so instances that share a home are not counted twice. Made with Claude Fable 5 in Claude Code.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This PR changes runtime behavior by expanding usage tracking to scan ALL configured provider instances rather than just the default ones. This affects the user-visible Usage page metrics and warrants review to confirm the intended scope of the change. You can add or adjust custom eligibility rules. Learn more. |
What Changed
The usage scan now resolves one transcript directory per configured Claude and Codex provider instance instead of only the legacy default
providers.<kind>homes. It walks the same merged instance map the provider registry hydrates from (deriveProviderInstanceConfigMap), so explicitproviderInstancesentries and the legacy mirrors are both covered, and dedupes by resolved directory so instances that share a home are not counted twice.The resolution moved out of
UsageServiceintousageTranscriptDirs.tsso it has focused tests (usageTranscriptDirs.test.ts): legacy-only, extra instances, nested.claude/projectsprobe, shared-home dedupe, and skipping non-transcript drivers / undecodable configs. One sentence added todocs/user/usage.md.Why
A second Claude instance pointed at its own
CLAUDE_CONFIG_DIR(or a second Codex home) writes transcripts there, not under~/.claude/projects, so the Usage page silently under-reported that instance's spend as zero. Reported on a machine with aclaude-secondinstall: the page showed only the default account.Checklist
Before
After
Note
Medium Risk
Changes which directories are scanned for billing-style usage totals; wrong paths could still under- or over-report, but behavior is aligned with the provider registry and covered by new unit tests.
Overview
Fixes under-reported Usage when multiple Claude or Codex installs use separate home directories. The scan no longer walks only the legacy default
providers.<kind>homes.Transcript directory resolution moves to
usageTranscriptDirs.ts, which uses the same merged instance map as the provider registry (deriveProviderInstanceConfigMap). Each Claude/Codex instance gets its own transcript path (with the existing nested.claude/projectsprobe), deduped when two instances share a home, and skipped for non-transcript drivers or invalid configs.UsageServicedelegates to that helper and suppliesFileSystemalongsidePathfor the existence probe.usageTranscriptDirs.test.tscovers legacy-only, extra instances, nesting, dedupe, and skip behavior; user docs note that every configured instance counts.Reviewed by Cursor Bugbot for commit 893cdf9. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix Usage page to count every configured provider instance
usageTranscriptDirs.tswithresolveUsageTranscriptDirs, which derives transcript directories from all configured Claude and Codex provider instances (including legacy defaults), deduplicating by provider+directory.resolveTranscriptDirslogic inUsageService.ts, which only scanned legacy/default homes, with a call to the new helper..claude/projectsdirectory under the configured home path before falling back tohome/projects.Macroscope summarized 893cdf9.