Skip to content

Coding Engine spend is invisible in the usage ledger — the largest real cost isn't recorded #267

Description

@serge-ivo

The gap

ai_usage is written at exactly one choke point — runUserWorkersAi in lib/user-ai.ts (plus recordVoiceUsage for the key-proxy and recordPlatformUsage for Workers-AI). The coding Engine never passes through any of them. Claude Code / Codex / Grok run on the user's own machine, spending on their own subscription or key, and the platform records nothing.

Measured on the live ledger (30d, operator account):

kind cost calls
chat $18.95 814
voice $8.51 840
overseer $7.45 326
copilot $4.85 244
coding $0.70 67

That coding row is only the cloud-side Pilot deciding what to do next. The Engine's own consumption — almost certainly the single largest item for anyone using Coder in earnest — is absent. So the Usage page reads $40.92 when real spend is materially higher, and there is no signal that anything is missing.

Why this matters beyond curiosity

The implementation path is already open

packages/browser-runner/src/coding/headless.ts parses Claude Code's stream-json and already handles the result event (line ~497) — it reads is_error/result/subtype and discards the usage and total_cost_usd fields on the same object. The data is flowing through today and being thrown away.

  1. In the result case, capture usage (input/output/cache tokens) + total_cost_usd when present.
  2. Report it with the existing session event channel (/coding/event) — no new transport, no relay change.
  3. Cloud side: ledger it as kind:"engine", provider:"anthropic", with the CLI-reported cost — this is the one number that is not an estimate, since Claude Code computes it itself.
  4. Raw (non-Claude) engines emit no such event → record nothing rather than guess. Codex/Grok stay invisible until each exposes an equivalent; say so in the UI rather than implying zero.

Acceptance

  • A Coder session on the claude engine produces ai_usage rows with kind:"engine".
  • The Usage page distinguishes engine spend from platform-mediated spend, and states which engines report (Claude) and which cannot (raw).
  • Cost from the CLI is stored as reported and marked authoritative, not re-estimated through ai-pricing.ts.
  • A session on a raw engine records nothing and does not fabricate a zero.

Found while answering "what is $40.92 and is it real". Related: #45 (platform actuals), #56, #57, #68.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions