Repository navigation
Description
Description
ccusage-codex appears to double-count token usage when processing conversations branched/forked from Codex Desktop.
This looks similar to the previously fixed Claude Code issue:
- [Bug] Branched conversations are fully counted #19
- fix: implement chronological deduplication for branched conversations #58
However, I am still seeing inflated totals with Codex Desktop / @ccusage/codex.
The symptom is that rerunning the same command shortly after a Codex Desktop branch/fork session causes the current day's token totals and cost to jump significantly, while earlier days stay unchanged. This suggests duplicated historical usage from the branched conversation may be counted again as new usage.
Environment
- Tool:
ccusage-codex - Package:
@ccusage/codex - Version: 18.0.11
- Install method: npm
- Codex Desktop version: 26.506.31421 (2620)
- OS: macOS
- Timezone: Asia/Shanghai
- Date observed: 2026-05-12
Reproduction
-
Use Codex Desktop with an existing conversation.
-
Branch/fork from an earlier point in that conversation.
-
Run:
ccusage-codex -s 2026-05-10
-
Wait briefly / continue using the branched Codex Desktop conversation.
-
Run the same command again:
ccusage-codex -s 2026-05-10
Actual behavior
The current day's totals increased dramatically between two runs of the same command.
First run at 2026-05-12 14:18:29 CST:
May 12, 2026
Input: 6,681,079
Output: 913,911
Reasoning: 163,313
Cache Read: 88,417,152
Total: 96,012,142
Cost: $91.17
Second run at 2026-05-12 14:20:15 CST:
May 12, 2026
Input: 25,954,265
Output: 2,404,174
Reasoning: 582,132
Cache Read: 447,427,200
Total: 475,785,639
Cost: $411.35
Delta within about two minutes:
Input: +19,273,186
Output: +1,490,263
Reasoning: +418,819
Cache Read:+359,010,048
Total: +379,773,497
Cost: +$320.18
The earlier days in the report did not change, which makes this look like duplicated branch-session usage being attributed to the current day.
Full output:
$ date; ccusage-codex -s 2026-05-10
2026年 5月12日 星期二 14时18分29秒 CST
WARN Fetching latest model pricing from LiteLLM... @ccusage/codex 14:18:35
ℹ Loaded pricing for 2706 models @ccusage/codex 14:18:36
WARN Pricing not found for model codex-auto-review; defaulting to zero-cost pricing. @ccusage/codex 14:18:36
╭──────────────────────────────────────────────────────────────╮
│ │
│ Codex Token Usage Report - Daily (Timezone: Asia/Shanghai) │
│ │
╰──────────────────────────────────────────────────────────────╯
┌──────────────┬──────────────────────────────┬─────────────┬────────────┬────────────┬──────────────┬───────────────┬─────────────┐
│ Date │ Models │ Input │ Output │ Reasoning │ Cache Read │ Total Tokens │ Cost (USD) │
├──────────────┼──────────────────────────────┼─────────────┼────────────┼────────────┼──────────────┼───────────────┼─────────────┤
│ May 10, 2026 │ - codex-auto-review │ 12,586,076 │ 897,667 │ 362,018 │ 176,975,232 │ 190,458,975 │ $168.33 │
│ │ - gpt-5.5 │ │ │ │ │ │ │
├──────────────┼──────────────────────────────┼─────────────┼────────────┼────────────┼──────────────┼───────────────┼─────────────┤
│ May 11, 2026 │ - codex-auto-review │ 37,064,333 │ 2,875,270 │ 836,947 │ 547,033,216 │ 586,972,819 │ $522.84 │
│ │ - gpt-5.5 │ │ │ │ │ │ │
├──────────────┼──────────────────────────────┼─────────────┼────────────┼────────────┼──────────────┼───────────────┼─────────────┤
│ May 12, 2026 │ - codex-auto-review │ 6,681,079 │ 913,911 │ 163,313 │ 88,417,152 │ 96,012,142 │ $91.17 │
│ │ - gpt-5.5 │ │ │ │ │ │ │
├──────────────┼──────────────────────────────┼─────────────┼────────────┼────────────┼──────────────┼───────────────┼─────────────┤
│ Total │ │ 56,331,488 │ 4,686,848 │ 1,362,278 │ 812,425,600 │ 873,443,936 │ $782.35 │
└──────────────┴──────────────────────────────┴─────────────┴────────────┴────────────┴──────────────┴───────────────┴─────────────┘
$ date; ccusage-codex -s 2026-05-10
2026年 5月12日 星期二 14时20分15秒 CST
WARN Fetching latest model pricing from LiteLLM... @ccusage/codex 14:20:23
ℹ Loaded pricing for 2706 models @ccusage/codex 14:20:24
WARN Pricing not found for model codex-auto-review; defaulting to zero-cost pricing. @ccusage/codex 14:20:24
╭──────────────────────────────────────────────────────────────╮
│ │
│ Codex Token Usage Report - Daily (Timezone: Asia/Shanghai) │
│ │
╰──────────────────────────────────────────────────────────────╯
┌──────────────┬──────────────────────────────┬─────────────┬────────────┬────────────┬────────────────┬────────────────┬─────────────┐
│ Date │ Models │ Input │ Output │ Reasoning │ Cache Read │ Total Tokens │ Cost (USD) │
├──────────────┼──────────────────────────────┼─────────────┼────────────┼────────────┼────────────────┼────────────────┼─────────────┤
│ May 10, 2026 │ - codex-auto-review │ 12,586,076 │ 897,667 │ 362,018 │ 176,975,232 │ 190,458,975 │ $168.33 │
│ │ - gpt-5.5 │ │ │ │ │ │ │
├──────────────┼──────────────────────────────┼─────────────┼────────────┼────────────┼────────────────┼────────────────┼─────────────┤
│ May 11, 2026 │ - codex-auto-review │ 37,064,333 │ 2,875,270 │ 836,947 │ 547,033,216 │ 586,972,819 │ $522.84 │
│ │ - gpt-5.5 │ │ │ │ │ │ │
├──────────────┼──────────────────────────────┼─────────────┼────────────┼────────────┼────────────────┼────────────────┼─────────────┤
│ May 12, 2026 │ - codex-auto-review │ 25,954,265 │ 2,404,174 │ 582,132 │ 447,427,200 │ 475,785,639 │ $411.35 │
│ │ - gpt-5.5 │ │ │ │ │ │ │
├──────────────┼──────────────────────────────┼─────────────┼────────────┼────────────┼────────────────┼────────────────┼─────────────┤
│ Total │ │ 75,604,674 │ 6,177,111 │ 1,781,097 │ 1,171,435,648 │ 1,253,217,433 │ $1102.53 │
└──────────────┴──────────────────────────────┴─────────────┴────────────┴────────────┴────────────────┴────────────────┴─────────────┘
Expected behavior
Branched/forked Codex Desktop conversations should not cause previous API calls / token usage to be counted again.
Only genuinely new usage after the branch point should be added to the report.
This should probably follow the same semantic behavior as the Claude Code fix in #58: duplicate usage records across branched conversations should be globally deduplicated, and usage should remain attributed to the original request/date.
Notes
The previous fix in #58 deduplicates Claude Code branched conversations using message.id + requestId and chronological processing.
It may be that Codex Desktop stores branched sessions with different identifiers or a different schema, so the same dedupe logic is not being applied to @ccusage/codex.
Activity
han-cheng6 commentedon May 18, 2026
Thanks again for the quick fix and release.
I upgraded and re-tested the same Codex Desktop branch-session case. The result looks improved, but I think the duplicated-usage issue may not be fully fixed yet.
Before upgrading:
After upgrading:
I understand that the new
Inputvalue may now include cache-read tokens, so I am not treating that field change itself as the issue.The remaining concern is that the reduction still seems much smaller than the duplicated increase I originally observed. In the original report, the suspicious jump was about
379,773,497tokens within a short interval. After the new release, the reported usage is lower, but it still seems far above the earlier baseline for the same day.So I suspect there may still be some duplicated historical usage from Codex Desktop branched sessions being counted.
Could we reopen this issue to track the remaining Codex Desktop branch-session duplication case?
@ryoppippi
Happy to help debug this further. I can provide redacted local fixture details if useful, including timestamps, model names, usage fields, request IDs, message/session IDs, and branch/fork metadata, while removing private prompt/response content.
Full output:
ryoppippi commentedon May 18, 2026
thanks. i'll take a look
han-cheng6 commentedon May 19, 2026
Thanks for reopening this.
Happy to help debug further. I can provide redacted local fixture details or run any specific branch / command against my Codex Desktop data if that would be useful.
fix(codex): dedupe copied branch history (#1156)
fix(codex): dedupe replayed usage (#1435)