Skip to content

Token count discrepancy - subagents/sub-tasks not fully captured #806

@rz1989s

Description

@rz1989s

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

  1. Subagent files exist in ~/.claude/projects/<project>/subagents/ directory
  2. Direct JSONL parsing includes these files
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions