Wire SQLite reader into getSummary() to fix usage accuracy drift (#23 root cause)
Context
PR #55 shipped session-level cost tracking on top of the extension's local estimate (buildSummaryFromTracked). That estimate is fine for per-session display. The subscription totals in the status bar tooltip (today / weekly / monthly) still use it, though, and the number can drift from what OpenCode actually bills. Two things the extension can't see: server-side cache affinity, and any usage from the CLI or TUI.
Issue #23 reported exactly this drift (weekly 9% to 15% too low, monthly 15% too low). It got closed as COMPLETED through PR #50, but PR #50 only added manual usage targets. The underlying estimate never changed.
Current state (verified on main post-PR #55)
goUsageTracker.ts already has most of the pieces. They just aren't wired in:
readOpenCodeHistory()(line 228) reads~/.local/share/opencode/opencode.db, returnsHistoryRow[]with{ createdMs, cost }. SQL matches the OpenUsage plugin.buildSummaryFromRows()(line 343) builds aUsageSummaryfrom those rows using the correct anchored-month formula.hasSQLiteData(line 424) is the only caller ofreadOpenCodeHistory, and itself has no callers.getSummary()(line 337) only callsbuildSummaryFromTracked(...). Never the SQLite path.
Proposal
- Make SQLite the primary source.
getSummary()callsreadOpenCodeHistory()first; if rows come back, usebuildSummaryFromRows(). Fall back to tracked only when the DB is missing (user never ran the CLI). - Merge tracked entries as enrichment, with dedup by timestamp window so the two sources don't double-count.
- Adopt
anchoredMonthBoundsfrom OpenUsage so the monthly window lines up with the dashboard. Current code uses calendar month, which accounts for part of the 15% drift on its own. - Drop
hasSQLiteDataunless it earns a real caller during the wire-up. Keep the code path if someone wants it as a feature flag, otherwise delete.
Why this matters
Users treat the status bar as the source of truth for spend. A 9% to 15% drift, especially near the subscription cap, quietly trains them to distrust it. Manual targets move that burden onto the user; the default should be correct on its own.
The reader, SQL, and buildSummaryFromRows already exist. What's left is the call site swap, dedup logic, and the anchored month formula.
References
- Issue #23 (closed COMPLETED via PR #50 workaround)
- PR #50 (manual targets, not a root fix)
- PR #55 (session tracking; unrelated to subscription totals, but it introduced the
(est)marker pattern worth reusing here) - OpenUsage plugin: https://github.com/robinebers/openusage/blob/main/docs/providers/opencode-go.md
- Repo memory note:
opencode-go-usage-accuracy.md(TODO #1-#4, Jun 2026)
OpenUsage just removed the support for Opencode because the lack of API: https://github.com/robinebers/openusage/issues/565
The only real fix here i think is use oAuth to get the most recent data, and failback to a local estimate that should run in parallel when the web scrap / private api breaks. Then we can keep fixing over time until breaks again. Or they publish a public API for that.