Skip to content

Codex Session history costs not recalculated, total cost severely understated

Quick fix

Usage costs are computed once at import, causing understated or duplicated costs: upgrade cc-switch to v3.18.0+ (first launch auto-rebuilds Codex history) and…

Error output
修改模型定价后,已导入的 Codex Session 历史成本没有重新计算,导致统计金额严重偏低
English translation

After modifying model pricing, the already-imported Codex Session history costs are not recalculated, causing the total cost figure to be severely understated

cc-switch incrementally imports session JSONL files under ~/.claude/projects and ~/.codex/sessions into the local database proxy_request_logs, computing fields such as input_cost_usd, output_cost_usd, and total_cost_usd against the pricing table at the moment of import and writing them permanently. If the model had no pricing when the record was imported, the cost is written as 0; even if you later add or change prices, older versions never recompute historical records. This produces a severe mismatch where token counts are huge but total cost is only a few tenths of a dollar (fixed in v3.15.0).

The same import logic has several related variants with different fix status: when Codex Desktop forks a task, the copied parent session history was mistakenly treated by the old importer as the child session's usage, producing two identical duplicated rows for parent and child (fixed in v3.18.0 by using forked_from_id / parent_thread_id plus token signature alignment to strip the replayed history); every token_count event is inserted as a separate row, inflating log rows by about 33x and total tokens by about 38x (#3190, still open; PR #3189 proposes per-turn aggregation); incremental sync uses INSERT OR IGNORE, so once the preliminary message_start snapshot is stored, the terminal event containing the real cache_read and output data is permanently ignored, lowering cache hit rate and cost accuracy (#6994, still unfixed in 3.20.1).

  1. Upgrade cc-switch to v3.18.0 or later: the historical cost recalculation issue was fixed in v3.15.0, and the Codex Desktop fork duplicate counting was fixed in v3.18.0. On first launch after upgrading to v3.18.0, the database is automatically backed up and Codex usage history is rebuilt, so an empty fork correctly imports 0 usage entries.

  2. Open "Settings → Usage Statistics → Cost Pricing" and fill in prices (input / output / cache read / cache write) for every model appearing in your statistics. The default config may not yet include prices for new models (e.g. gpt-5.5); add them manually or costs will show as 0.

  3. After upgrading, return to the "Model Statistics" page and verify token counts match total cost. If Codex-side usage is still abnormally high (the one-row-per-token_count-event inflation issue #3190 has no merged fix yet), you can turn off the "auto-scan session records" toggle added in v3.20.1 on the usage page and instead click "Sync Now" manually, while watching #3190 / PR #3189 for progress.

  4. If Claude Code sessions still show low cache hit rates and costs (the terminal event's cache_read / output not being stored), that variant (#6994) is still unfixed in 3.20.1 and on the main branch. There is no official workaround; watch that issue for updates.

Toolcc-switch
Version3.14.1 - 3.20.1 均报告过受影响;成本不重算在 v3.15.0 修复,fork 重复计数在 v3.18.0 修复,#3190 与 #6994 两个变体在 3.20.1 仍未修复
PlatformsmacOSWindows
Why are historical record costs still 0 or severely understated after I add or change model pricing?
Older versions compute the cost once when the session record is imported and write it into proxy_request_logs; later price changes are not applied retroactively, so token counts accumulate normally while total cost stays at the old value or 0. This was fixed in v3.15.0; please upgrade.
Why does the cost calculation show 0 in usage statistics?
Usually the default pricing table does not yet include the latest prices for the model you use (e.g. gpt-5.5). Add that model's input / output / cache prices manually in "Settings → Usage Statistics → Cost Pricing". In older versions, historical records still will not be recomputed automatically after adding prices; upgrade to v3.15.0+.
I forked a task in Codex Desktop but sent no messages—why was usage double-counted?
The old importer mistakenly treated the copied parent session history (bounded by thread_settings_applied) as the child session's usage. This was fixed in v3.18.0 by using forked_from_id / parent_thread_id plus token signature prefix alignment to strip the replayed history; an empty fork correctly imports 0 usage entries.
Will I lose historical usage data after upgrading to v3.18.0?
No. On first launch after upgrading to v3.18.0, the app automatically backs up the database and then rebuilds Codex usage history, removing the previously duplicated fork usage.

This is an unofficial community wiki with no affiliation to the cc-switch authors or the project itself. Its content is compiled from the project's public GitHub issues. This site distributes no software.