Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(usage): aggregate transcripts from every provider instance #6603

Closedeffektsvk(GitHub profile, opens in a new tab)wants to merge 5 commits intomain fromrefs/pull/6603/headopened View on GitHub

What Changed

The Usage page now aggregates transcript history from every configured Claude Code and Codex provider instance.

  • Resolve each instance's explicit homePath or merged CLAUDE_CONFIG_DIR/CODEX_HOME, while retaining built-in defaults for legacy settings.
  • Resolve relative CLAUDE_CONFIG_DIR values against every known active or archived project and worktree cwd, matching Claude's runtime behavior.
  • Deduplicate identical transcript roots before scanning and share record-level deduplication across every source in one scan.
  • Associate usage buckets with their exact transcript source via sourceIndex, so cross-environment merging removes only overlapping roots.
  • Bump the usage contract to v5 while decoding older buckets with sourceIndex: 0, and document multi-instance collection.
  • Add focused coverage for source resolution, cross-source aggregation, contract compatibility, and usage merging.

Tests: 4 files passed, 35 tests passed.

Why

Previously, usage collection only scanned the default Claude Code and Codex homes, omitting activity from additional provider instances and workspace-relative Claude config directories. Cross-environment ownership also operated at the provider level, which could discard valid usage when two environments shared one transcript root but had other distinct roots.

Resolving the same provider instances and workspace-relative paths used at runtime, sharing record deduplication across roots, and tracking each bucket's exact source makes collection complete without double-counting copied records or dropping unrelated instance usage.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes (not applicable)
  • I included a video for animation/interaction changes (not applicable)

Authored with gpt-5.6-sol through the Codex harness in T3 Code.


Note

Medium Risk Changes usage collection, aggregation, and the v5 contract; wrong path resolution or merge logic could misreport totals, though behavior is covered by new tests and backward-compatible decoding.

Overview The Usage page now scans every configured Claude and Codex provider instance instead of only the default homes, using a new resolveUsageTranscriptSources path that honors explicit homePath, per-instance CLAUDE_CONFIG_DIR / CODEX_HOME, and legacy default slots.

Relative CLAUDE_CONFIG_DIR values resolve against all project and worktree cwds gathered via resolveUsageWorkspaceCwds (from active and archived shell projections, with server cwd fallback). Identical transcript roots are deduped before scanning, and record dedupe runs once across all sources in a scan via a shared seenDedupeKeys set.

Each UsageBucket carries sourceIndex (contract v5; older payloads decode as 0), and cross-environment mergeUsage keeps buckets by owned source index rather than by provider alone, so overlapping roots drop without discarding other instances on the same machine.

serverGetUsageSummary passes workspace cwds into readSummary; aggregation uses one aggregator per transcript source and merges sorted buckets.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e1dbf038b32862b2f1286fdf1f697f219ee9884b. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Aggregate usage transcripts from every configured provider instance

  • Introduces usageTranscriptSources.ts to resolve transcript directories for all Claude and Codex provider instances, honoring explicit config, CLAUDE_CONFIG_DIR/CODEX_HOME env vars, and workspace-relative paths.
  • Adds usageWorkspaceCwds.ts to collect workspace root paths from active projections, passed to readSummary at request time to resolve relative provider paths.
  • UsageAggregator now accepts a shared seenDedupeKeys set so duplicate records across multiple transcript sources are dropped in a single scan; emitted UsageBucket entries carry a sourceIndex.
  • Ownership filtering in usageMerge.ts now tracks owned source indexes instead of provider names, preserving buckets from unowned sources of the same provider.
  • Behavioral Change: USAGE_CONTRACT_VERSION bumped from 4 to 5; older summaries decode with sourceIndex defaulting to 0.
Macroscope summarized e1dbf03.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: aecb3271-c57b-4984-b8ea-2e455df8a351

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      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.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. @@ -0,0 +84,21 @@
      84+ // not receive shell-style tilde expansion.
      85+ return path.resolve(environmentHome);
      86+ }
      87+
      88+ return path.resolve(NodeOS.homedir());
      89+ },
      90+);
      91+
      92+/**
      93+ * Claude's config dir is the home itself when overridden, but older/default
      94+ * layouts nest transcripts under `<home>/.claude/projects`. Probe both.
      95+ */
      96+const resolveClaudeTranscriptDir = Effect.fn("UsageTranscriptSources.resolveClaudeTranscriptDir")(
      97+ function* (homePath: string) {
      98+ const fileSystem = yield* FileSystem.FileSystem;
      99+ const path = yield* Path.Path;
      100+ const nested = path.join(homePath, ".claude", "projects");
      101+ const nestedExists = yield* fileSystem
      102+ .exists(nested)
      103+ .pipe(Effect.catchCause(() => Effect.succeed(false)));
      104+ return nestedExists ? nested : path.join(homePath, "projects");
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟡 Medium usage/usageTranscriptSources.ts:104

      When <home>/.claude/projects exists, resolveClaudeTranscriptDir returns only that root, so transcripts under the legacy <home>/projects directory are silently excluded. Return both existing roots and let the existing source deduplication handle overlaps.

      🤖 Copy this AI Prompt to have your agent fix this:
      In file @apps/server/src/usage/usageTranscriptSources.ts around line 104:
      
      When `<home>/.claude/projects` exists, `resolveClaudeTranscriptDir` returns only that root, so transcripts under the legacy `<home>/projects` directory are silently excluded. Return both existing roots and let the existing source deduplication handle overlaps.
    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      1 blocking correctness issue found. This PR changes runtime behavior by expanding transcript source discovery from fixed defaults to all configured provider instances. The changes affect what directories get scanned for usage data, introduce new resolution logic for workspace cwds and environment variables, and bump the contract version. Given the behavioral scope and cross-cutting nature of the changes, human review is recommended.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot). Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 4546e55a7dbd64c370c60f388faf3efdb85c2147. Configure [here](https://www.cursor.com/dashboard/bugbot).
    6. Note

      🤖 GPT-5.6 Sol responding on behalf of Theo

      We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together.

      We are keeping OPEN #5806 as the review path for usage across provider instances. This branch's multi-home transcript handling remains useful reference.

      If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed.

Sign in to join this conversation.