Quick answer
Recent OpenCode versions include a `stats` command that prints a usage summary for the local data set. It is useful for a quick total and limited for anything else: it does not give a per-project split, a long trend, or provider balance. Run `opencode --help` to confirm the command exists in your build.
Run it
opencode --help
opencode statsIf the command is not listed, your version predates it. Query the database directly instead; the database location guide lists the paths.
What it covers
| Question | Stats command | Database query |
|---|---|---|
| Total tokens | Yes | Yes |
| Total cost | Where reported | Yes |
| Per model | Sometimes | Yes |
| Per project | No | Yes, with a join |
| 90-day trend | No | Yes |
| Provider balance | No | No |
When a snapshot is not enough
A single total cannot tell you whether last Tuesday was unusual. If you need the trend, keep a history. UsageAtlas records daily totals and keeps 7, 30, or 90-day views, which is the same data with a time axis.
The built-in stats view and its limits
OpenCode ships with a stats view that reports totals for the sessions it can see. It is the fastest check and the least flexible: you cannot change the window freely, join it with other tools, or keep a history after the database is reset.
- Good for a one-off total after a long session.
- Good for confirming the database is being written.
- Weak for month-over-month comparisons.
- Not a substitute for cost estimates across models.
For a persistent view, see the OpenCode usage dashboard and the token tracker CLI comparison.
Questions, answered
Does OpenCode have a stats command?
Recent versions do. Older builds may not, so check opencode --help before relying on it.
Can the stats command export CSV?
Usually not. Export requires reading the database or using a tracker that supports export.
Why does the total differ from my provider bill?
The stats command totals local messages at estimated rates. A bill includes plans, credits, rounding, and taxes.