You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Stats & Usage under-reports OpenCode by roughly 70x, so OpenCode-heavy days render as empty cells on the "Daily intensity" heatmap and OpenCode barely registers in "Total tokens", even on days with hundreds of millions of tokens of OpenCode activity.
Cause: the OpenCode scanner reads opencode.db with the wrong token model. In OpenCode's schema tokens.input is uncached input only and tokens.total = input + output + reasoning + cache.read + cache.write (verified on 99,153 assistant messages: zero rows where total differs from that sum). Two places in src/main/opencode-usage/ assume the opposite:
selectSessionUsageRows (the fast path used whenever the DB has materialized session.tokens_* columns) synthesizes total: tokens_input + tokens_output + tokens_reasoning, dropping tokens_cache_read and tokens_cache_write entirely.
parseOpenCodeUsageRow sets cachedInputTokens = min(cache.read, input), which is ≈ input on real data (e.g. input: 638, cache.read: 642944), so "new input" collapses to ~0 and cache share is meaningless.
Because prompt caching means cache reads are ~97% of OpenCode traffic, the fast path discards almost everything.
Steps to reproduce
Use OpenCode for a while with a provider that reports cache reads (any recent OpenCode; session.tokens_* columns exist since the 20260510033149_session_usage migration).
Open Stats & Usage in Orca with OpenCode analytics enabled.
Compare the OpenCode total with SELECT SUM(tokens_input+tokens_output+tokens_reasoning+tokens_cache_read+tokens_cache_write) FROM session in ~/.local/share/opencode/opencode.db.
On my machine (Orca 1.4.197, macOS, 5.4 GB opencode.db):
OpenCode totals match OpenCode's own tokens.total, and the materialized-session fast path produces the same numbers as parsing the per-message rows it summarizes.
Environment
Orca 1.4.197 (macOS 26.3, Apple Silicon)
OpenCode with session.tokens_* columns (schema migration 20260510033149_session_usage)
Validated against OpenCode source: session totals expose tokens_input, tokens_output, tokens_reasoning, tokens_cache_read, and tokens_cache_write, and OpenCode sums all five. Orca was dropping both cache fields in its materialized-session path. PR #21886 fixes both fields, preserves compatibility with older databases, and covers write-only sessions.
Activity
nwparker commentedon Sep 21, 2026
Validated against OpenCode source: session totals expose tokens_input, tokens_output, tokens_reasoning, tokens_cache_read, and tokens_cache_write, and OpenCode sums all five. Orca was dropping both cache fields in its materialized-session path. PR #21886 fixes both fields, preserves compatibility with older databases, and covers write-only sessions.