OpenCode

OpenCode stats command: what it shows and what it misses

Use the OpenCode stats command for a quick usage snapshot, and learn which questions still require the database or a tracker.

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 stats

If the command is not listed, your version predates it. Query the database directly instead; the database location guide lists the paths.

What it covers

QuestionStats commandDatabase query
Total tokensYesYes
Total costWhere reportedYes
Per modelSometimesYes
Per projectNoYes, with a join
90-day trendNoYes
Provider balanceNoNo

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.

Browse by topic