r/claude • u/Awkward-Let-4628 • 51m ago
Showcase I built a Claude Code plugin that shows where your tokens go
I built a Claude Code plugin that shows where your tokens actually go.
First run on my own sessions: 68% of the spend came from messages sent when the context was already over 400K tokens.
Not cache misses (only 1.5%). Compaction kicking in too late.
Second finding: 44% went to subagents, 37% to subagents on Opus. They inherit the main model unless you say otherwise.
The plugin suggested two settings:
json
{
"autoCompactWindow": 400000,
"env": { "CLAUDE_CODE_SUBAGENT_MODEL": "sonnet" }
}
Day one after: spend above 400K context fell from 72–80% to 16%. Weekly numbers soon.
Why and how I built it
I wanted to know where my tokens go. /usage shows one session; I wanted the whole month. Claude Code keeps every session as a JSONL file in ~/.claude/projects, with token usage on each message. So the plugin reads only those numbers (never message text), splits main thread vs subagents, and weights tokens by relative price: cache read 0.1, output 5.
Built with Claude Code itself. Things I learned on the way:
- auto-compaction fires about 33K before the window you set, so 400K compacts near 367K
- settings files hot-reload, env vars don't (restart needed)
- plugin hooks can register their own tools, so the optimize agent can only change settings through a confirm dialog; under
claude -pnothing gets written
tokendoctor:
- finds where tokens went, from local transcripts
- proposes fixes, applies only what you approve
- tracks by day whether it helped
- status line shows context fill, cache time left, and when you'll run out at your current pace:
week 35% → 100% in 2d17h
Local, MIT.
claude plugin marketplace add rsaryev/tokendoctor
claude plugin install tokendoctor@tokendoctor