Skip to content

Cost modes: reconcile displayed cost with the source's own reported cost (auto/calculate/display) #890

Closed

Description

@iamtoruk

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.ts never 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)

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.

  1. Add reportedCostUsd?: number to the parsed-call type, distinct from the computed costUSD. 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-message costUSD.
  2. Carry both computed and reported cost through the daily rollup (day-aggregator), which is a DAILY_CACHE_VERSION bump (16 -> 17) riding the existing carry-forward so old days are preserved, not dropped. Same discipline as the recent structural-discovery bump.
  3. 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.
  4. Provenance: mark reported vs computed in the output (extend the existing estimated-cost signal), and in --json emit the selected costUSD plus computedCostUsd, reportedCostUsd, and costMode so downstream tools can reconcile.
  5. --cost-mode <auto|calculate|display> on the reporting commands, plus a persisted default in config.

Scope and phasing

  • Phase 1 (first PR): the reportedCostUsd field 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-mode on the core CLI and --json with auto (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

  1. ozymandiashh commented on Aug 4, 2026

    @ozymandiashh
    Collaborator

    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 costUSD is a client-side convenience estimate (computed from our tables is at least as good, and consistent across the fleet). A blanket report mode would silently downgrade accuracy for providers whose reported number is the weaker one. Suggest a per-provider trust default (reported-authoritative vs computed-authoritative, seeded from today's allowlist) with --cost-mode calculate|report|auto overriding the tie-break, auto being 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 | mixed per 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 audit growing 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. providerCallToCachedCall persists costUSD only for allowlisted providers; everyone else's cached calls carry no reported cost at all. So --cost-mode report cannot 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-time PROVIDER_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 under report mode 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 costUSD reading (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.

  2. therickfactr commented on Aug 4, 2026

    @therickfactr
    Contributor

    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. providerCallToCachedCall keeps costUSD only for a hardcoded list of provider names and drops it to undefined for everyone else, after which cachedCallToApiCall recomputes. That means a provider whose some calls are metered and some are not cannot express the distinction — it is all or nothing per provider. For cline-cli I 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-mode lands on, having the parsed call carry provenance (costIsEstimated already exists and is persisted through the cache) is strictly more expressive than keying on the provider name.

    A metered $0 is a real value and truthiness checks eat it. Free or fully-cached calls legitimately report cost: 0. Gating on cost > 0 silently 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 auto mode 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 cline VS Code provider reads a reported cost from api_req_started but 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-mode with an explicit auto default would fix it as a side effect rather than as a surprise.

  3. added
    enhancement
    area: cli
    provider: claude
    on Sep 14, 2026
  4. iamtoruk commented on Nov 5, 2026

    @iamtoruk
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: clienhancementprovider: claude

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions