Skip to content

@ccusage/codex double-counts tokens for branched Codex Desktop conversations #988

Description

@han-cheng6

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:

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

  1. Use Codex Desktop with an existing conversation.

  2. Branch/fork from an earlier point in that conversation.

  3. Run:

    ccusage-codex -s 2026-05-10
  4. Wait briefly / continue using the branched Codex Desktop conversation.

  5. 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

  1. han-cheng6 commented on May 18, 2026

    @han-cheng6
    Author

    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.84
    

    After 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.47
    

    I understand that the new Input value 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,497 tokens 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:

    --- 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           │               │            │           │               │               │              │
    └────────────┴─────────────────────┴───────────────┴────────────┴───────────┴───────────────┴───────────────┴──────────────┘
    
    
  2. ryoppippi commented on May 18, 2026

    @ryoppippi
    Member

    thanks. i'll take a look

  3. han-cheng6 commented on May 19, 2026

    @han-cheng6
    Author

    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.

  4. added a commit that references this issue on May 25, 2026
    c95deda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions