Quick answer
OpenCode records token counts on each assistant message in its local data directory, usually `~/.local/share/opencode` on macOS and Linux and `%APPDATA%\opencode` on Windows. Recent versions use a SQLite database; older ones use JSON files under `storage/`. UsageAtlas reads that data and shows tokens by session, model, and day.
What OpenCode records
| Field | Meaning | Use |
|---|---|---|
| Input tokens | Context sent with the message | Measures context size |
| Output tokens | Tokens generated | Measures answer length |
| Cache read | Prompt cache reused | Shows discount potential |
| Cache write | Context written to cache | First-turn cost |
| Cost | Provider-reported or computed cost | Per-message spend |
| Model | Provider and model ID | Per-model split |
Because OpenCode talks to many providers, the fields available depend on what the provider returns. A missing cost field means the provider did not report one, not that the request was free.
Three views that answer different questions
- Per session: which run was expensive, and why.
- Per model: whether a cheap model is actually cheaper per completed task.
- Per day: whether usage is trending up before a bill arrives.
UsageAtlas provides all three from the same local database. It keeps 7, 30, or 90-day windows and needs no account for local tracking.
What local usage cannot tell you
OpenCode is a client. It knows what it sent and what the provider reported. It does not know your remaining balance with a provider, your plan window, or a rate limit that applies account-wide.
For provider limits, connect the provider where UsageAtlas supports it, or check that provider's dashboard. The OpenCode limit reset guide explains which limits are local and which are not.
Where OpenCode keeps the numbers
OpenCode records every session in a local database: messages, model IDs, token counts, and timestamps. There is no vendor dashboard behind it, so that file is the record. Anything you cannot see in the TUI is still in the database.
| View | Shows | Lifetime |
|---|---|---|
| TUI status | Current session and model | Until you exit |
| Database | Every session and token count | Until you delete it |
| UsageAtlas | Totals by day, model, project | 7, 30, or 90 days |
| Provider console | Only provider-billed usage | Varies |
The database location guide has the platform paths, and session history explains what each record contains.
Questions, answered
Does OpenCode track token usage automatically?
Yes. Token counts are written with each assistant message as part of the session record. You do not need to enable anything.
Where does OpenCode store usage data?
In its local data directory, typically ~/.local/share/opencode on macOS and Linux and %APPDATA%\opencode on Windows. The exact file depends on the version.
Can I see OpenCode usage without a third-party app?
Yes, with the CLI stats command where available, or by querying the local database. A tracker is only a convenience layer.