Repository navigation
Description
Summary
CodeBurn v0.9.15 on Windows only reads the legacy file-based JSON sessions from OpenCode and completely ignores the current SQLite database (opencode.db), even when both exist side-by-side. This causes the dashboard to show only a tiny fraction of actual usage (in my case: $3.31 / 12 sessions instead of the real ~$2,617 / 71 models).
Environment
- OS: Windows 11
- Node: v24.13.0 (
node:sqliteavailable and working) - CodeBurn: v0.9.15 (installed globally via
npm install -g codeburn) - OpenCode: current (sessions stored in SQLite
opencode.db, 1.5 GB, modified today)
Data layout on disk
~\.local\share\opencode\
├── opencode.db ← 1.5 GB SQLite, current (modified today 20:41)
├── opencode - Copy.db ← backup
├── opencode - Copy (2).db ← backup
└── storage\
├── session\*.json ← 13 legacy JSON files (Jan 22 – Feb 13 2026, ~5 KB total)
└── message\*.json ← 797 legacy message files (same period)
Symptom
codeburn report --provider opencode -p all shows:
- $3.31 cost, 549 calls, 12 sessions
- Last data point: 2026-02-13
- Only the 13 legacy JSON sessions are visible
The 1.5 GB SQLite DB (containing all usage from Feb through today, ~$2,617 across 71 models including gpt-5.5 at ~$1,000) is completely ignored.
For comparison, tokscale reading the same machine shows the correct numbers from the SQLite DB:
- $2,616.89 across 71 models, last data point today (2026-07-05)
- Top model: gpt-5.5 at $1,000
Root cause (found in bundled dist/main.js)
In src/providers/opencode.ts, createOpenCodeProvider → discoverSessions():
async discoverSessions() {
const fileSessions = await discoverOpenCodeFileSessions(resolvedDataDir, "opencode");
if (fileSessions.length > 0) return fileSessions; // ← short-circuits, never falls back to SQLite
return discoverSqliteSessions(sqliteConfig);
}The comment above it says:
"OpenCode 1.1+ stores sessions as file-based JSON; older builds used a SQLite DB. Prefer file-based when present, otherwise fall back to the DB so pre-migration installs keep reporting."
This assumption is backwards for real-world OpenCode installs on Windows. OpenCode migrated from file-based JSON (legacy, storage/session/*.json) to SQLite (opencode.db) at some point. After the migration, the legacy JSON files are left behind on disk but are no longer written to. The current data lives exclusively in opencode.db.
Because the discovery short-circuits on fileSessions.length > 0, any install that still has the old storage/session/ directory (even with just a handful of stale files from January) will never read the SQLite DB. The SQLite fallback only fires when the legacy directory is completely empty/absent — which is not the case for users who upgraded OpenCode in place.
Expected behavior
CodeBurn should read both sources and merge them (dedup by session ID), the way tokscale does (opencode.db or/and storage/message/ legacy). At minimum, it should prefer the SQLite DB when it exists and is larger/newer than the legacy files, rather than short-circuiting on any legacy file presence.
Suggested fix
Either:
- Merge both sources (dedup by session ID), so legacy + SQLite are both counted; or
- Prefer SQLite when present and only fall back to legacy files when no
opencode*.dbexists; or - At minimum, compare mtime/size and prefer the source that is actively being written to.
Reproduction
- Install OpenCode on Windows, use it for a while (creates
storage/session/*.json) - Upgrade OpenCode in place (it migrates to
opencode.dbSQLite, leaves legacy files behind) - Continue using OpenCode (data now flows into
opencode.dbonly) npm install -g codeburnand runcodeburn report --provider opencode -p all- Observe: only the stale legacy JSON sessions are shown; current SQLite data is missing
Related
- No usage stats for OpenCode on windows #359 reported a similar "No usage stats for OpenCode on windows" issue for v0.9.9 (compound
:sessionIdpath bug, fixed in Fix OpenCode/Goose returning 0 sessions on fresh install #347). This is a different bug: the SQLite DB is not even attempted because the legacy file short-circuit fires first.
Activity
NihalJain commentedon Jul 5, 2026
do you plan to provide a fix for this? if not i can hit this up? although i can try a fix and test only on mac, i believe this issue exists for mac too.
morpheus9393 commentedon Jul 5, 2026
Opened PR #622 with the fix. Verified on Windows 11 against a real 1.5 GB opencode.db + 13 stale legacy JSON files: before patch .31/12 sessions, after patch ,182.91/470 sessions (matches tokscale's independent SQLite reading). The bug is not Windows-specific — any in-place OpenCode upgrade that leaves legacy storage/session/ files behind will hit the same short-circuit on Mac too.