opencode-costs-tui
v2.1.2
Published
Sidebar cost panel for OpenCode: per-agent cost and tokens for the current session and its subagents
Maintainers
Readme
opencode-costs
English · Español
Sidebar cost panel for OpenCode 2.x: cost and tokens per agent for the active session and every subagent below it.

Tokens instead of dollars. OpenCode 1.x stored a dollar cost per session, so the old CLI showed the spend of the parent session and its subagents in USD. OpenCode 2.x reports
cost: 0for subscription or free models — for example the wholeopencode-gocatalog — even though the model has a list price. The panel therefore shows dollars when the host reports them, and falls back to tokens for the family total, the per-session value and the percentage. It never invents a price. If you want the billed spend of a Go plan, use the quota panel.
What it shows
- Header: total cost of the session family (the session plus all its descendants), with a
▾/▸toggle. - One row per session: cost (or tokens, when the model has no price), share of the family total and an indent that mirrors the subagent depth. Finished subagents stay listed.
- Footer: number of sessions in the family and aggregate input / output / reasoning tokens.
- Live: it re-renders on every session event OpenCode pushes, plus a 30-second safety sync.
Click the header to collapse the panel; the choice is stored in the plugin's durable state.
Why 2.0 is a rewrite
The 1.x version was a Python CLI (costs) that read OpenCode's SQLite database. That broke with OpenCode 2.x for two separate reasons:
- The database moved. OpenCode 1.x wrote sessions to
session; 2.x writes new sessions tosession_v2(messages tosession_message). The legacy tables stop receiving rows, so the CLI kept reporting an old session and its subagents disappeared. - TUI plugins changed. In OpenCode 2.x a sidebar plugin is an npm package that uses the
@opencode/plugin/tuiAPI; local files and the oldtui.jsonentries are not loaded. A menu command cannot live next to it either.
So 2.0 drops the CLI and the Python engine entirely. The panel now reads the session store of the running OpenCode: no SQLite, no external process, no second runtime. That also means it only supports OpenCode 2.x; 1.x is no longer supported.
Install
TUI plugins are listed in ~/.config/opencode/cli.json, not in opencode.jsonc. (opencode plugin add registers server plugins, which is not what this package is.)
// ~/.config/opencode/cli.json
{
"plugins": ["opencode-costs-tui"]
}Or run the installer, which patches that file for you:
curl -fsSL https://raw.githubusercontent.com/caertos/opencode-costs/main/install.sh | shRestart OpenCode (or run /reload). The panel appears at the top of the session sidebar.
Uninstall: remove opencode-costs-tui from ~/.config/opencode/cli.json → plugins.
What the numbers mean
- Cost comes from OpenCode's own session accounting. If the provider or model has no price configured (some free tiers, local models), the cost is
$0.00while tokens are still reported. - Family = the session you are looking at, plus every session whose
parentIDchain starts there. Subagents created by task/delegation tools are included. - Rows are individual sessions, so you can see which subagent spent what. When the whole family reports
$0.00(unpriced or free model), the value and percentage columns switch to tokens instead of showing a column of zeros.
Requirements
- OpenCode 2.x with the TUI plugin API (verified on 2.4.0).
- No Python, no database access, no API key: the plugin only formats data the host already has.
Development
npm test # pure-logic tests (node --test)
npm run build # src/tui.tsx -> dist/tui.js (esbuild via npx)dist/ is built and committed, because OpenCode only activates packages whose TUI entrypoint is a JavaScript file.
License
MIT
