Subagent Usage
opencode TUI sidebar widget showing the rolled-up cost and token usage of subagent (child) sessions.
1
330
14 in 7 days
37.3
Multi-signal model
17 days ago
2026-09-17
Install and configure
opencode.jsonWrites to this project's opencode.json — applies to this repository only.
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-subagent-usage@0.1.1"]
}Writes to ~/.config/opencode/opencode.json — applies to every project.
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-subagent-usage@0.1.1"]
}If you want to modify the plugin locally, install it into the project and reference the local path.
shell
pnpm add -D opencode-subagent-usageOpenCode loads npm dependencies through its embedded runtime on startup and caches them locally — no manual global install needed.
A TUI sidebar widget for opencode that shows the rolled-up cost and token usage of the subagent (child) sessions a session spawned.
opencode's built-in Context block only reports the session it is attached to. Anything a subagent spends never appears there, so on subagent-heavy work the number you see can be a small fraction of what was actually billed.
Subagents <- this plugin
42 sessions · 3 running
$3.80 spent
188,204,551 tokens
Context <- built-in
96,410 tokens
48% used
$0.90 spent
In that example the session's real total was about $4.70. The built-in sidebar showed $0.90 on its own. Real numbers vary with how much a workflow fans out; the point is that the difference is invisible without this.
Install
opencode plugin opencode-subagent-usage --global
That installs the package and registers it in ~/.config/opencode/tui.json.
Without --global it installs into the current directory's .opencode/tui.json
instead. Restart the TUI afterwards.
Prefer to do it by hand? Add the package to the plugin array in
~/.config/opencode/tui.json:
{
"$schema": "https://opencode.ai/tui.json",
"plugin": ["opencode-subagent-usage"]
}
TUI plugins belong in
tui.json. Putting this inopencode.jsonmakes the server-side loader look for aserver()export that does not exist, and it will warn and skip the package.
What it shows
- sessions - number of child sessions, counted recursively (subagents and
any subagents they spawned). The line reads
N runningwhen one or more children are currently busy. - spent - summed
costacross all of those child sessions. - tokens - summed input, output, reasoning, and cache read/write tokens.
The block hides itself when a session has no subagents.
The figures are additive with Context, not inclusive. Context is the session you are viewing; Subagents is everything it spawned. Add them for the true session total.
Token counts follow the same definition the built-in Context widget uses, which includes cache reads. On long sessions cache reads usually dominate, so the token number can look much larger than the raw conversation size.
How it works
For the session currently displayed in the sidebar, it calls
client.session.children({ sessionID }), sums each child's cost and tokens,
then recurses into each child. Data refreshes every 2 seconds and on
session.status / session.updated events. A seen set guards against cycles.
No network calls are made beyond opencode's own local API client. Nothing is written to disk, nothing is sent anywhere, and no session data leaves your machine.
Why the source is plain JS
src/subagent-usage.js is hand-written, not compiled from JSX, and that is
deliberate. opencode loads published plugins from inside node_modules, and its
bundled Bun runtime does not apply the JSX transform to files there, so a
shipped .tsx is never executed - it fails silently and the plugin simply never
appears. Building the JSX ahead of time does not solve it either: the common
compilers either emit the dev JSX runtime, or flatten JSX props eagerly and
drop Solid's reactivity. So the file is written directly in the shape a
Solid-aware compiler would produce: jsx/jsxs from the production runtime,
with getters on every prop that reads reactive state.
The practical consequence is that this package has no build step and no
runtime dependencies other than the solid-js and @opentui/solid the host
already provides.
Requirements
- opencode
>= 1.18.31(the version verified to expose the TUI plugin slot API) - A model provider that reports cost, for the
spentfigure to be meaningful
Tuning
Two constants at the top of src/subagent-usage.js:
POLL_MS- refresh interval, default2000orderin theslots.registercall - default90, which places the block directly above the built-in Context block (100)
Notes
- Costs come from opencode's own session records. A sum computed against the raw database can differ slightly (well under a percent) because the two are read at different moments.
- If you want the upstream fix rather than a plugin, see anomalyco/opencode#45417 (session cost excludes subagent cost) and #47822 / #48548.
Not affiliated
This project is not built by the opencode team and is not affiliated with it in any way. "opencode" is used only to describe what it plugs into.
License
MIT
Similar plugins
Total Session Cost
opencode-total-session-cost
Real-time cumulative cost tracker for Opencode sessions, aggregating costs from parent sessions, archived messages, and all child sub-agent tasks.
Context Usage
opencode-context-usage
OpenCode TUI plugin: a /context command with the exact token breakdown behind the built-in Context panel (last request) plus session-wide usage, subagent totals, cache hit rate and cost.
Usage Panel
opencode-usage-panel
Sidebar token-usage and cost panel for the opencode TUI. Breaks a session down by model with per-model cost, context usage, and configurable peak/off-peak pricing.