ccusage aggregates token deltas from all session files without accounting for fork relationships, leading to 3-4x token overcounting when users frequently fork sessions. Both Codex and Claude Code are affected, though in different ways.
I analyzed a real 4-level Codex fork chain on my machine (ccusage v20.0.1, Codex CLI v0.131.0):
019e648e (root, before 5/27)
└─ 019e67b4 (fork 1, 5/27)
├─ 019e68e3 (fork 2, 5/27)
└─ 019e6a50 (fork 3, 5/28)
└─ 019e6acf (fork 4, 5/28)
### Steps to reproduce
1. Have a Codex session with accumulated token usage (e.g., 178M tokens)
2. Fork that session (e.g., `codex fork <session_id>`)
3. The forked session's JSONL file will show `forked_from_id` in `session_meta`
4. Run `ccusage codex daily --json`
5. Both parent and forked session deltas are summed independently
6. Result: total tokens = parent_delta + fork_delta, even though fork re-sent the same context
Concrete data from my machine (ccusage v20.0.1, Codex v0.131.0-alpha.9):
019e648e (root)
└─ 019e67b4 (fork 1, 5/27) — delta: 178M tokens
├─ 019e68e3 (fork 2, 5/27) — delta: 149M tokens
└─ 019e6a50 (fork 3, 5/28) — delta: 190M tokens
└─ 019e6acf (fork 4, 5/28) — delta: 195M tokens
Each fork child's `total_token_usage` resets to ~22,812 (system prompt baseline) rather than inheriting parent's accumulator. ccusage sums all four deltas = 712M tokens, but the actual new context processed is closer to 195M (last fork's cumulative).
### Expected behavior
When `forked_from_id` is present in `session_meta`, ccusage should recognize the session as a fork and avoid double-counting the inherited historical context. Options:
- Option A (preferred): Build fork trees and only count tokens from divergence points (after `thread_rolled_back` events)
- Option B: Expose `forkedFrom` in JSON output so users can dedup themselves
- Option C: Add a `--dedup-forks` flag
Without dedup, heavy fork users see 3-4x inflated token counts in daily/monthly reports.
### Version
_No response_
What happened?
Summary
ccusage aggregates token deltas from all session files without accounting for fork relationships, leading to 3-4x token overcounting when users frequently fork sessions. Both Codex and Claude Code are affected, though in different ways.
Evidence
Codex: fork chain token duplication (confirmed with real data)
I analyzed a real 4-level Codex fork chain on my machine (ccusage v20.0.1, Codex CLI v0.131.0):