Repository navigation
Description
Motivation
CodeBurn derives every cost from tokens times model pricing. But several sources write their own cost into the log, and where they do, we currently ignore it, so our headline can disagree with what the user sees in the tool itself.
- Claude Code writes a per-message
costUSD;claude.tsnever reads it and computes instead. - crush, codewhale, openclaw, the sqlite-based sources, cline and session-message already read a reported cost, but only as a zero-fallback (used only when our computed value is 0).
There is no way for a user to say "trust the source's own number" or "always recompute", and no provenance in the output distinguishing a computed cost from a reported one. This adds an explicit cost mode, so the displayed number can match the source of truth when one exists.
Semantics
A --cost-mode selector, mirrored in config and JSON:
calculate- always compute from tokens times pricing (today's behaviour).display- prefer the source's own reported cost where the log carries one; a source with no reported cost is shown as a computed estimate, never a silent 0.auto(default) - use the reported cost when it is present AND the source is on the known-reliable list, otherwise compute. Conservative: numbers only move where we have a trustworthy reported cost.
Non-goals (be honest)
- This does NOT fix the assumed-model divergence for sources that carry no cost field (Cursor computes against an assumed model and its data has no dollar figure to read). That is a separate discovery and pricing accuracy track.
- No new network calls. Reconciliation against a billing API is out of scope here (it overlaps Epic: quota intelligence (live remaining, burn-rate forecast, pre-flight awareness, invoice reconciliation) #725 Part 5).
Architecture
Cost is baked in at parse time and stored in the daily cache, so the mode has to be applied at read time, which means storing both numbers.
- Add
reportedCostUsd?: numberto the parsed-call type, distinct from the computedcostUSD. Populate it in the sources that read a reported cost (promote the existing zero-fallback reads to always capture it) and add Claude Code's per-messagecostUSD. - Carry both computed and reported cost through the daily rollup (
day-aggregator), which is aDAILY_CACHE_VERSIONbump (16 -> 17) riding the existing carry-forward so old days are preserved, not dropped. Same discipline as the recent structural-discovery bump. - One shared read-time selector applies the mode when a report is rendered, so the CLI, TUI, JSON and menubar can never disagree about which number they show.
- Provenance: mark reported vs computed in the output (extend the existing estimated-cost signal), and in
--jsonemit the selectedcostUSDpluscomputedCostUsd,reportedCostUsd, andcostModeso downstream tools can reconcile. --cost-mode <auto|calculate|display>on the reporting commands, plus a persisted default in config.
Scope and phasing
- Phase 1 (first PR): the
reportedCostUsdfield and its capture in the sources that carry a cost plus Claude Code; the daily-cache schema bump and carry-forward; the read-time selector;--cost-modeon the core CLI and--jsonwithauto(conservative) as the default; provenance in JSON and the TUI; tests and an adversarial pass on the money path. - Follow-ups: menubar and web toggle; per-source reliability tuning; billing reconciliation (with Epic: quota intelligence (live remaining, burn-rate forecast, pre-flight awareness, invoice reconciliation) #725 Part 5).
Evidence gate
Money path, so: conservation holds under every mode; a computed number is never rendered as reported nor the reverse; the cache bump is lossless (carry-forward pinned by a test); the mode selector is mutation-verified; adversarial review before merge.
Activity
ozymandiashh commentedon Aug 4, 2026
Design input from the two places I have touched this seam recently (the #891 review, where cline-cli joined the reported-cost allowlist, and kimicode, which lives on the computed side):
1. Make the mode select the tie-break, not a blanket override. The two cost kinds are not symmetric in trustworthiness per provider: cline-cli and the credit-metered tools write the number the user is actually billed (reported is truth), while Claude Code's
costUSDis a client-side convenience estimate (computed from our tables is at least as good, and consistent across the fleet). A blanketreportmode would silently downgrade accuracy for providers whose reported number is the weaker one. Suggest a per-provider trust default (reported-authoritativevscomputed-authoritative, seeded from today's allowlist) with--cost-mode calculate|report|autooverriding the tie-break,autobeing today's semantics made explicit.2. Provenance must ship in the same release, or the mode makes things less honest. Whatever the selector does, the output needs
costSource: reported | computed | mixedper row (JSON) and a subtle marker in the UI. Today's zero-fallback already produces invisibly mixed days; a mode selector without provenance turns "which number am I looking at" into a support thread. This is also what makes disagreement debuggable:codeburn auditgrowing a reported-vs-computed delta column per (provider, model) would let a user see exactly where and how much the two diverge before choosing a mode.3. The cache is the sharp edge.
providerCallToCachedCallpersistscostUSDonly for allowlisted providers; everyone else's cached calls carry no reported cost at all. So--cost-mode reportcannot be honored from existing caches for non-allowlisted providers - the data was dropped at parse time. That means: (a) the mode needs to be part of the cache config hash (or reported cost must ALWAYS be persisted alongside the computed one, mode applied at read time - my preference, it makes mode switches free after one re-parse), and (b) there is a one-timePROVIDER_PARSE_VERSIONS-style migration cost to start retaining it. Worth deciding before the selector lands, not after.4. Interaction with savings. The computed path is what feeds
savingsUSD/ localModelSavings / cache-efficiency math. A reported total has no token split, so underreportmode those columns either keep deriving from tokens (fine, but then "cost" and "savings" come from different accounting bases and the footer should say so) or go blank. Explicitly choosing option one with a footer sentence seems right; silent mixed-basis is the only wrong answer.5. Scope creep guard. Claude Code's
costUSDreading (your first bullet) can ship independently of the selector as "retain and expose", with zero behavior change, and would immediately populate the audit delta column with the fleet's biggest provider. That is the low-risk first PR of this epic.Happy to take implementation once the shape settles - the retain-both + read-time-mode variant of (3) plus the audit delta of (2) is a contained first slice I can start on your nod.
therickfactr commentedon Aug 4, 2026
A data point from #874, since the Cline CLI provider ran straight into this and the numbers are concrete.
The CLI meters cost per assistant message, so the source's own figure exists and is authoritative. Reporting it as computed instead of reported was not a rounding difference — on 12 real local sessions the same corpus came out $1.11 reported vs $3.92 recomputed, a 3.5x gap, because the routed model ids price very differently from what the CLI actually billed. That is the failure mode this issue describes, at a magnitude that would make the headline useless.
Two things that surfaced while wiring it up, both relevant to the design here:
The current mechanism is a provider-name allowlist in
parser.ts, and it is per-provider, not per-call.providerCallToCachedCallkeepscostUSDonly for a hardcoded list of provider names and drops it toundefinedfor everyone else, after whichcachedCallToApiCallrecomputes. That means a provider whose some calls are metered and some are not cannot express the distinction — it is all or nothing per provider. Forcline-cliI ended up wanting exactly that split, because a session can carry per-message metered costs while an interrupted one has only a rolled-up total. Whatever--cost-modelands on, having the parsed call carry provenance (costIsEstimatedalready exists and is persisted through the cache) is strictly more expressive than keying on the provider name.A metered
$0is a real value and truthiness checks eat it. Free or fully-cached calls legitimately reportcost: 0. Gating oncost > 0silently reclassifies those as unpriced and re-estimates them, which inflates the total. It needs to be a presence check — is the field there and non-negative — not a truthy one. Same trap on the rollup path. Both are cheap to get wrong and invisible once wrong, so it may be worth stating in the semantics of this issue rather than leaving each provider to rediscover it.For what it is worth, the
automode as you have described it is what I would want as the default: prefer the source's number where one exists, recompute where it does not, and make the distinction visible in the output rather than silently blending the two.One adjacent case you may want in scope: the
clineVS Code provider reads a reported cost fromapi_req_startedbut is not on the allowlist, so that number is currently discarded and recomputed. I deliberately left it alone in #891 rather than move existing users' dollar amounts without being asked — but it is the same defect, and a--cost-modewith an explicitautodefault would fix it as a side effect rather than as a surprise.feat(copilot): read per-request input/cache from session-store.db
feat(copilot): read per-request input/cache from session-store.db
feat(copilot): read per-request input/cache from session-store.db
feat(copilot): read per-request input/cache from session-store.db
feat(copilot): read per-request input/cache from session-store.db
feat(copilot): read per-request input/cache from session-store.db
feat(copilot): read per-request input/cache from session-store.db
feat(copilot): read per-request input/cache from session-store.db
feat(copilot): read per-request input/cache from session-store.db
feat(copilot): read per-request input/cache from session-store.db
feat(copilot): read per-request input/cache from session-store.db
iamtoruk commentedon Nov 5, 2026
Covered: sources that record their own cost are read as recorded (Copilot credits, Warp, Hermes, Cursor and others), and every call now carries a costBasis of recorded, calculated, estimated, included or unpriced in the JSON outputs. The explicit mode switch is not worth building on top. Closing.