Skip to content
Source
Sign inSign up
pingdotgg/t3code

feat(usage): add OpenCode usage reporting #6040

Closedgmmeyer(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/6040/headopened View on GitHub

What Changed

Add Opencode usage to t3 usage page

Why

I use opencode as well as claude and codex so I can use open or alternative models. This will add opencode usage to the page as well. Opencode stores the data in a different way than claude or codex (sqlite), which forces us to slightly change the calculation mechanism. But it's basically the same.

UI Changes

This is what it looks like now: image

This is what it will look like: image

Checklist

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

Note

Medium Risk New local SQLite reads and a contract version bump affect usage aggregation across clients; reads are scoped to usage scalars only, limiting exposure of prompt content.

Overview Adds OpenCode as a third usage provider alongside Claude Code and Codex, reading local SQLite assistant-message data instead of JSONL transcripts.

The server introduces usageOpenCode for read-only SQLite access (Bun and Node), maps legacy message and current session_message rows into shared UsageRecords without selecting conversation content, and discovers databases under OpenCode’s data dir with support for OPENCODE_DB, channel DBs, and OPENCODE_DISABLE_CHANNEL_DB. UsageService branches on source kind (jsonl vs opencodeSqlite) and reports OpenCode-specific missing/partial/failed source status.

The shared contract adds opencode to UsageProviderKind and bumps USAGE_CONTRACT_VERSION to 5. Web and mobile charts/tables register OpenCode label, color, and icon; the web usage table’s empty-state colSpan now follows PROVIDER_ORDER length. User docs describe OpenCode sourcing and privacy boundaries.

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

Note

Add OpenCode usage reporting to usage summary and UI

  • Adds readOpenCodeUsage and resolveOpenCodeDatabasePaths in usageOpenCode.ts to read assistant usage from OpenCode SQLite databases, supporting both current and legacy schemas with deduplication by message ID.
  • Integrates OpenCode as a new source in UsageService, discovering channel databases via directory scan and reporting partial/failed states per database.
  • Registers opencode in provider ordering, labels, colors, and icons across web and mobile UI, and adds an OpenCodeIcon mark to the chart legend.
  • Increments USAGE_CONTRACT_VERSION from 4 to 5 and adds opencode to the UsageProviderKind schema in packages/contracts/src/usage.ts.
  • Risk: version bump to contract v5 may cause version-mismatch warnings or partial-state handling in clients that validate the contract version.
Macroscope summarized 3bd1517.
    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: 44678b53-e708-4389-b6aa-3a97bdafbf47

      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. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      Adds a new third-party tool integration (OpenCode) with SQLite database reading, new UI display, and contract changes. While well-tested and following existing patterns, the scope of new capability (~850 lines, new database access, schema handling) warrants human review.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Two follow-ups from running this on a fork of t3code (I cherry-picked this branch locally):

      1. The opencode.db path is hardcoded, OPENCODE_DB and channel installs are ignored

      UsageService.ts resolves the database as {XDG data dir}/opencode/opencode.db, but opencode's own resolution (packages/core/src/database/database.ts in v1.18.16) is:

      • OPENCODE_DB wins when set: absolute paths are used verbatim, relative paths resolve against the data dir (:memory: aside);
      • non-stable channels write opencode-<channel>.db instead of opencode.db.

      Any install with OPENCODE_DB set (or a channel build) would silently report zero OpenCode usage. I suggest mirroring opencode's resolution, e.g. a small resolveOpenCodeDatabasePath(dataDir) helper that honors OPENCODE_DB, and either handles the channel suffix or documents it as out of scope.

      2. Zero-token placeholder rows are counted as malformed → the source reports partial

      parseOpenCodeUsageRow returns null for the placeholder assistant rows opencode writes for aborted/empty attempts (valid identity + model, zero tokens, cost: 0), and readOpenCodeUsage counts every null as malformedRecords. The source then reports status: "partial" with "Some OpenCode usage records could not be parsed" on perfectly healthy installs (75 such rows in my db). I suggest distinguishing placeholders from malformed rows, e.g. an isOpenCodePlaceholderRow check before incrementing the malformed count. So that partial stays reserved for actually malformed rows.

    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).

      Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ffbd13f7365502fec8a1bb8e151b36c4390dd2d9. Configure [here](https://www.cursor.com/dashboard/bugbot).
    6. @AskPlays I fixed these issues thank you!

    7. Note

      🤖 GPT-5.6 Sol responding on behalf of Theo

      Closing this PR after an automated pass over open pull requests. Duplicates another usage-reporting proposal while adding a broad client, contract, or provider integration.

Sign in to join this conversation.