OpenCode token usage: where the numbers are stored OpenCode stores per-message token counts — input, output, reasoning, cache read, cache write and a cost estimate — in a local SQLite database, usually opencode.db in the data directory, rather than keeping a single running session counter, so session totals must be computed by summing assistant-message records. The guide advises running `opencode debug paths db` to print the exact file path, since OPENCODE_DB and XDG_DATA_HOME can override it and some builds use a storage folder of JSON files instead. It warns that input already includes cached tokens and that reasoning is typically billed inside output, so adding those fields together double counts. Quick answer OpenCode stores token counts per assistant message in its local SQLite database, usually opencode.db inside the data directory. Each message keeps input, output, reasoning, and cache read and write counts plus a cost value. Run opencode debug paths db to print the exact file on your machine before you query it. Tokens are attached to messages, not sessions OpenCode does not keep one running counter that says what a session cost. It writes a record for every assistant response, and the usage numbers travel inside that record. A session total is something you compute by adding those records together. That is why the same session can show one figure in the interface and a different figure in a spreadsheet. | Field | What it counts | Common mistake | |---|---|---| | input | Everything sent to the model, cached prefix included | Adding it to cache.read double counts | | output | Tokens generated, reasoning included on most providers | Adding reasoning again inflates the total | | reasoning | Thinking tokens, reported separately but billed as output | Summing it with output for a bill estimate | | cache.read | Input served from the provider's prompt cache | Treating it as free when it is billed at a lower rate | | cache.write | Tokens written into the cache for later turns | Ignoring it on providers that charge for writes | | cost | A per-message estimate from the provider or model rates | Assuming it matches your invoice exactly | Read the columns in the right order. input already includes the cached tokens the provider served, so fresh input is input minus cache read. If your provider bills cached input at a discount, keep the two apart rather than collapsing them into one number. Reasoning is the second trap. Providers that bill internal thinking as output usually report it inside output and also expose it as reasoning . Adding both inflates the estimate. Check a single message against the provider's invoice before you trust any total built from these fields. Find the file before you write a query Guessing the path wastes more time than the query. OpenCode ships a command that resolves the location for the current install after environment variables and the release channel are applied. opencode debug paths db opencode debug paths data opencode debug paths - Linux: ~/.local/share/opencode/opencode.db , unless XDG DATA HOME is set - macOS: often ~/.local/share/opencode , though some builds use ~/Library/Application Support/opencode - Windows: %APPDATA%\opencode , which expands to C:\Users\