-
-
Notifications
You must be signed in to change notification settings - Fork 319
Description
Summary
While building a custom cost tracking solution, I noticed a significant discrepancy between token counts from direct JSONL parsing vs ccusage output. After investigation, this appears related to #313.
Environment
- ccusage version: 17.0.3 (via bunx)
- Claude Code: 2.1.7
- macOS
Observed Behavior
For the same project directory, comparing token counts:
| Source | Total Tokens | Cost |
|---|---|---|
| Direct JSONL parsing | 1.18B | ~$886 |
| ccusage session | 527M | ~$372 |
That's a 2.25x difference in token count for the same project.
Investigation
- Subagent files exist in
~/.claude/projects/<project>/subagents/directory - Direct JSONL parsing includes these files
- ccusage appears to not fully capture tokens from these subagent conversations
Example structure:
~/.claude/projects/-Users-me-myproject/
├── abc123.jsonl # Main conversation
└── subagents/
├── agent-a1b2c3.jsonl # Sub-task 1
├── agent-d4e5f6.jsonl # Sub-task 2
└── ...
Verification
Calculated costs excluding subagents:
- Main files only: 1.17B tokens (~$877)
- Subagent files: ~$126
Even excluding subagents, there's still a ~2x discrepancy, suggesting the issue may be broader than just subagent directories.
Pricing Verification
Confirmed ccusage uses LiteLLM pricing which has correct Opus 4.5 rates ($5/$25 per MTok). The discrepancy is in token counting, not pricing.
Related
This may be related to #313 (sub-task token tracking). Happy to provide more debug info if helpful.
Using Claude Code Max subscription, so accurate tracking is important for usage benchmarking.