OpenCode Cost Tracking: See What a Session Cost After It Ends
That is one real opencode session on the proxy path: Gemini 3.5 Flash, 16 turns, 32 tool calls, 16 cents. Of the tokens, 98% were the loop re-reading its own context. opencode’s per-call cost figure doesn’t show you that.
Short answer. Local metering needs no account and starts recording once the plugin is installed:
curl -sf https://agenticcontrolplane.com/install.sh | bash
npx acp-opencode report # spend by model, cache hit rate, per-task cost
For priced spend on the team dashboard, start opencode with opencode-acp. The installer sets it up. See below.
Full opencode install guide → · Turn on Cost X-Ray → · free up to 5 agents
opencode prices every model call. It reads the token counts off the response and multiplies by the rates in its models.dev data, with no setup. It doesn’t keep the result. Close the terminal and the session’s spend is gone. There’s no total across sessions, no per-task breakdown, and no team view. Two things fix that: a local SQLite database that needs no account, and a proxy that prices spend server-side and puts it on a dashboard.
What opencode computes, and what it drops
Every LLM request emits a step-finish part. It carries the call’s token counts (input, output, cache read, cache write) and the cost opencode worked out from its pricing data. That’s a real per-call price, not an estimate spread from a total. But it only lives in the running session. Nothing writes it to a file or a database. To find out what last Tuesday’s session cost, or which task in a long session was the expensive one, native opencode has nothing to show you.
Path one: local SQLite metering, no credentials
The acp-opencode plugin listens to opencode’s event bus and writes every model call and tool call to SQLite at ~/.acp/opencode-local.db. Set ACP_LOCAL_DB to move it. This works with or without a workspace credential. Metering needs no account and no network.
Two tables hold the record:
model_calls: one row per LLM request. It has the model, provider, mode, input/output/reasoning tokens, cache read/write tokens, cost, and session, task and turn ids.tool_calls: one row per tool run. It has the tool name, status (okorerror), duration, and result size.
Read it back with the bundled CLI:
npx acp-opencode report # spend by model, cache hit rate, tool errors, per-task cost
npx acp-opencode report --json # machine-readable, so an agent can read its own costs
npx acp-opencode report --days 30 # widen the window (default 7)
To put the command on your PATH, run npm install -g acp-opencode.
Prices come from opencode only. The plugin keeps no price table. Every dollar figure is what opencode computed. When opencode reports zero (an unknown model, or auth that includes usage with no per-call price), the row is stored with cost_usd left NULL and the report says “N calls have no price.” Token counts stay exact either way. To turn local metering off, set export ACP_LOCAL_METERING=off (0, false and disabled also work). It also turns itself off for the session, with one warning, if storage fails, so it never interrupts the agent.
What this path can’t do. opencode 1.18.4 only exposes the outgoing message array through an unstable experimental.chat.messages.transform hook, so context composition (how much of a prompt was system, user, earlier assistant turns, or tool output) isn’t filled in. Per-request API duration isn’t exposed per step either. Only message-level fallback rows carry timing, and step rows record zero. The proxy path covers both for traffic routed through it.
Path two: the ACP proxy, priced server-side
Local metering stays on your machine. It’s per developer, with no dashboard. The cost X-ray puts priced spend, cache hit rate, and the loop-versus-leaf split on the team console, metered server-side instead of read from a local file. Start opencode with the launcher the installer put next to claude-acp and codex-acp:
opencode-acp
The installer adds the ACP proxy to ~/.config/opencode/opencode.json as a provider named acp and leaves your default model alone, so plain opencode goes where it always did. opencode-acp reads the workspace key from ~/.acp/credentials, exports it as ACP_BEARER_TOKEN (the variable the plugin reads), and picks acp/gemini-3.5-flash for that one launch. Set ACP_OPENCODE_MODEL=<id> to pick another model. If the gateway is unreachable, the launcher starts plain opencode with a one-line note. An unpriced session beats no session.
Unlike claude-acp and codex-acp, which pass your own login through, opencode-acp sends the session’s model calls through ACP’s proxy. Check the install guide for how the model is billed on your plan before you rely on it.
This is the provider block the installer writes. It has no top-level "model", because picking the model is the launcher’s job:
// ~/.config/opencode/opencode.json
{
"provider": {
"acp": {
"npm": "@ai-sdk/openai-compatible",
"name": "Agentic Control Plane",
"options": {
"baseURL": "https://api.agenticcontrolplane.com/v1",
"apiKey": "{env:ACP_BEARER_TOKEN}"
},
"models": { "gemini-3.5-flash": {} }
}
}
}
The plugin’s chat.headers hook adds an X-GS-Session header to every model request. That header ties proxy-priced spend to the tool-call audit rows for the same session, so the dashboard shows what ran and what it cost in one place.
Which one to use
Start with local metering. It needs no account or network, it works as soon as the plugin is installed, and it’s the only path that records a call to a provider opencode has no price for (it saves the tokens and leaves the price empty). Move to the proxy when you want the spend on a team dashboard, joined to the audit trail for the same session, with real per-request duration for routed traffic. Those are the two gaps local metering can’t close until opencode ships a stable hook for them.
Related links
- /integrations/opencode: the install guide, both metering paths, and troubleshooting
- /controls/opencode: opencode’s control model
- opencode permissions reference: every key in the
permissionblock, defaults, and auto-approve - OpenCode permissions and hooks reference: the policy-side hooks,
permission.askand the backstop - Claude Code cost tracking reference: the transcript-priced equivalent for Claude Code
- Codex cost tracking: the same question for Codex CLI
- Turn on Cost X-Ray: the proxy path across harnesses
Frequently asked questions
Does opencode track cost natively?
It works out a cost per API call in-process, from its own models.dev pricing data, and shows it in the terminal UI for the session in progress. It isn’t saved to a database, added up across sessions, or split by task. Once the session ends, the total is gone unless something else recorded it.
What does acp-opencode report show that opencode doesn't?
A saved, queryable local record: spend by model, prompt-cache hit rate, tool error rates, and per-task cost. It’s read back from a SQLite database on your machine that the plugin has been writing to since install. It needs no credentials, and nothing leaves the machine.
Why route opencode through the ACP proxy if local metering already works?
Local metering is per machine and has no dashboard. It’s a report you run yourself. The proxy prices the same spend server-side, joins it to the tool-call audit for the same session, and shows both on the team console. Cost and the tool calls behind it are one view instead of two.
What happens when opencode doesn't know a model's price?
The call is stored with cost left NULL and exact token counts. The plugin keeps no price table and never guesses a dollar figure. The report shows it as “N calls have no price.” Routing that model through the proxy gets it priced server-side.
Running opencode? One command adds a plugin. Each tool call it sees is recorded, and a force-push, destructive SQL or curl | sh is blocked until you approve it on the console or from the email.
curl -fsSL https://agenticcontrolplane.com/install.sh | bash
irm https://agenticcontrolplane.com/install.ps1 | iex
What the installer writes · opencode guide · free up to 5 agents