mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-06-10 18:23:12 +08:00
The transcript-sum estimate diverges from the harness's API-billed cost on
long sessions and after --resume:
- the hard-coded rate table cannot represent Opus 4.7's >200K-token 2x tier
or the 1h-cache 2x tier (under-counts);
- summing the full transcript double-counts work across --resume boundaries
while cost.total_cost_usd is per-process.
Both made the bridge file overshoot real cost by 4-5x, which tripped
ecc-context-monitor's $50 "critical" threshold and made agents halt
prematurely (observed: $73.99 hook value at $15.61 real harness cost).
This change adds an opt-in contract: if a statusline writes
{ts, cost_usd} to <tmpdir>/harness-cost-<session_id>.json on each render,
cost-tracker prefers that authoritative value when fresh (<=300s).
Behaviour is strictly additive — absent a writer, the transcript-sum path
is unchanged.
Tests cover both the prefer-fresh-cache and ignore-stale-cache paths.