Repository navigation
@ccusage/codex double-counts tokens for branched Codex Desktop conversations #988
Description
Activity
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:
2026-05-12 Input: 35,607,673 Output: 2,913,722 Reasoning: 713,857 Cache Read: 569,439,104 Total: 607,960,499 Cost: $508.84After upgrading:
2026-05-12 Input: 517,790,648 Output: 2,520,730 Reasoning: 602,957 Cache Read: 487,060,736 Total: 520,311,378 Cost: $431.47I 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?
@ryoppippiHappy 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:
--- before upgrading(remove unrelated): $ date; ccusage-codex 2026年 5月18日 星期一 16时16分12秒 CST WARN Fetching latest model pricing from LiteLLM... @ccusage/codex 16:16:23 ℹ Loaded pricing for 2716 models @ccusage/codex 16:16:24 WARN Pricing not found for model codex-auto-review; defaulting to zero-cost pricing. @ccusage/codex 16:16:24 ╭──────────────────────────────────────────────────────────────╮ │ │ │ Codex Token Usage Report - Daily (Timezone: Asia/Shanghai) │ │ │ ╰──────────────────────────────────────────────────────────────╯ ┌──────────────┬──────────────────────────────┬──────────────┬─────────────┬────────────┬────────────────┬────────────────┬─────────────┐ │ Date │ Models │ Input │ Output │ Reasoning │ Cache Read │ Total Tokens │ Cost (USD) │ ├──────────────┼──────────────────────────────┼──────────────┼─────────────┼────────────┼────────────────┼────────────────┼─────────────┤ │ May 12, 2026 │ - codex-auto-review │ 35,607,673 │ 2,913,722 │ 713,857 │ 569,439,104 │ 607,960,499 │ $508.84 │ │ │ - gpt-5.5 │ │ │ │ │ │ │ └──────────────┴──────────────────────────────┴──────────────┴─────────────┴────────────┴────────────────┴────────────────┴─────────────┘ --- after upgrading(remove unrelated, version 19.0.3): $ date; npx ccusage codex 2026年 5月18日 星期一 16时56分32秒 CST ╭────────────────────────────────────╮ │ │ │ Codex Token Usage Report - Daily │ │ │ ╰────────────────────────────────────╯ ┌────────────┬─────────────────────┬───────────────┬────────────┬───────────┬───────────────┬───────────────┬──────────────┐ │ Date │ Models │ Input │ Output │ Reasoning │ Cache Read │ Total Tokens │ Cost (USD) │ ├────────────┼─────────────────────┼───────────────┼────────────┼───────────┼───────────────┼───────────────┼──────────────┤ │ 2026-05-12 │ - codex-auto-review │ 517,790,648 │ 2,520,730 │ 602,957 │ 487,060,736 │ 520,311,378 │ $431.47 │ │ │ - gpt-5.5 │ │ │ │ │ │ │ └────────────┴─────────────────────┴───────────────┴────────────┴───────────┴───────────────┴───────────────┴──────────────┘thanks. i'll take a look
thanks. i'll take a look
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.
- added a commit that references this issue
on May 25, 2026 - added a commit that references this issue
on Jul 25, 2026
Description
ccusage-codexappears to double-count token usage when processing conversations branched/forked from Codex Desktop.This looks similar to the previously fixed Claude Code issue:
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
ccusage-codex@ccusage/codexReproduction
Use Codex Desktop with an existing conversation.
Branch/fork from an earlier point in that conversation.
Run:
Wait briefly / continue using the branched Codex Desktop conversation.
Run the same command again:
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:Second run at
2026-05-12 14:20:15 CST:Delta within about two minutes:
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:
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+requestIdand 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.