Adds token and cost breakdowns to opencode.ai workspace usage pages.
There are three ways to run it:
| Version | Best for | Output |
|---|---|---|
| Browser extension | Keeping stats on the usage page | Inline tables and charts |
| Userscript | Getting the same dashboard through a userscript manager | Inline tables and charts |
| Console script | One-off inspection from DevTools | console.table() reports and session totals |
The extension and userscript share the same dashboard code. The console script is separate: it prints a report, exposes raw data on window.__opencodeStats, and includes the session breakdown.
The dashboard adds two tables above the normal usage list.
| Table | What it shows |
|---|---|
| Estimated Pricing | Per-model input, output, and cache-read prices in dollars per 1M tokens. These are fitted from usage records that include cost data. |
| Per-Model Summary | Requests, input tokens, output tokens, reasoning tokens, cache reads, total cost, and effective dollars per 1M tokens for each model. |
The summary table also includes the fitted pricing columns when pricing can be estimated for the model.
The dashboard has range filters for All, Today, 7d, 30d, 90d, and 1y. The selected range updates the tables and the chart together.
Three of the chart modes are daily stacked bars, split by model:
| Chart | What it answers |
|---|---|
| Cost | How much each model cost per day. |
| Tokens | How many input, output, reasoning, and cache-read tokens each model used per day, summed into one token total. |
| Requests | How many requests each model handled per day. |
Two chart modes compare models across the selected range:
| Chart | What it answers |
|---|---|
| Efficiency | Which models were most expensive per 1M tokens. This is a horizontal bar chart sorted by effective dollars per 1M tokens. |
| Share | Which models accounted for the largest share of total cost. This is a horizontal bar chart with percent share and dollar cost in the tooltip. |
Example chart views:
| Cost | Tokens | Efficiency |
|---|---|---|
![]() |
![]() |
![]() |
dist/pull-stats.js is for quick checks without installing anything. Open an opencode.ai workspace usage page, paste the script into the browser console, and run it.
It prints:
| Section | What it contains |
|---|---|
| Estimated Pricing | The same fitted per-model prices used by the dashboard. |
| Per-Model Summary | Request, token, cost, and effective price totals by model. |
| Grand Total | Workspace-wide token and cost totals. |
| Top Sessions by Cost | The 20 most expensive model/session pairs. This is console-only. |
After it finishes, the parsed records and computed summaries are available as window.__opencodeStats.
Prerequisite: Build the extension/userscript first with
npm install && npm run build.
Load the dist/extension/ directory as an unpacked extension.
| Browser | Steps |
|---|---|
| Chrome | Open Extensions, enable Developer mode, choose Load unpacked, then select dist/extension/. |
| Firefox | Open about:debugging, choose This Firefox, choose Load Temporary Add-on, then select dist/extension/manifest.json. |
The extension runs on https://opencode.ai/workspace/*/usage.
Install dist/opencode-stats.user.js with Tampermonkey, Violentmonkey, or another userscript manager.
The userscript runs on the same usage pages as the extension and renders the same dashboard.
Open an opencode.ai workspace usage page, paste the contents of dist/pull-stats.js into DevTools, and run it.
npm install
npm run buildnpm run build produces:
| Output | Source entry | Purpose |
|---|---|---|
dist/extension/content.js |
src/entries/extension.ts |
Browser extension content script. |
dist/opencode-stats.user.js |
src/entries/extension.ts |
Userscript dashboard. |
dist/pull-stats.js |
src/entries/console.ts |
Console-only report. |
All output goes to dist/.
npm run releaseThis builds the extension and writes extension.zip.
npm run checkThe FN_ID constant (see src/packages/core/constants.ts) is the server function identifier used by opencode.ai's
internal API gateway to route usage-history requests. It is a public routing key, not a secret,
and is embedded in the opencode.ai web client. If the upstream API changes, this value must be
updated in src/packages/core/constants.ts.
- Reads the workspace ID from the current usage page URL.
- Fetches usage pages through opencode.ai's internal
/_serverendpoint. - Deduplicates records and merges them with records cached in
localStorage. - Computes per-model request, token, and cost totals.
- Estimates per-model token prices by solving a linear system from records with cost data.
- Renders the dashboard or prints the console report, depending on the script being used.
Pricing is estimated from your recorded usage, so a model may not show fitted prices until there is enough cost-bearing data for that model.




