ccusagewhere your tokens went, by month
github.com/ccusage/ccusage · MIT · reads the logs Claude Code already keeps on your machine. Nothing is sent anywhere.
npx ccusage@latest monthly --no-cost # or: daily, session, blocks- My logs since 1 Oct: 7.77 billion tokens. 97.8% were cache reads (Claude re-reading context it already had), 1.8% cache writes, and Claude's own output was 0.46%.
- Cache reads are billed at a tenth of the normal input price, so most of the volume is cheap, but it's still where the tokens go: every turn re-sends the whole conversation, tool lists and files so far.
--no-costhides the dollar column. Without it you see what the same use would cost at API prices (useful if you're on a plan and wondering what you'd pay per token).
cost-xraywhat's inside each request
github.com/tigerless-labs/cost-xray · MIT · a local proxy that captures Claude Code's requests and breaks each one down: system prompt, tool lists, skills, your messages, its answers.
git clone https://github.com/tigerless-labs/cost-xray && cd cost-xray
./run.sh start # a local capture proxy, no background service (./install.sh sets one up instead)
export ANTHROPIC_BASE_URL=http://127.0.0.1:8788 # it prints the exact line; then run claude in this terminal
./run.sh tui # the live breakdown (the README's `cx`)
./run.sh stop # when you're done; captured data stays in ~/.cost-xray until you delete it- My test: one small bug-fix session in a throwaway repo. System tools were 25% of its bill and skills 16%: about 41% of the cost was the lists of tools and skills that ride along with every request.
- Safety, from reading its code: it captures traffic on your machine, redacts auth headers in what it saves, and only
calls Anthropic's own token-counting endpoint. The installer adds a background service and a block in your shell
profile (
cx uninstallremoves both); manualstart/stopdoesn't touch either.
TokenEconomizer (Microsoft + UC Berkeley)learns your repo, prunes tools
github.com/microsoft/TokenEconomizer · a Claude Code plugin (also Codex, Copilot CLI and others). It learns from your sessions in a repo: facts it can inject next time, tools you never use there, and loops to break.
git clone https://github.com/microsoft/TokenEconomizer
claude plugin marketplace add "$PWD/TokenEconomizer"
claude plugin install tokeneconomizer@tokeneconomizer # add --scope local to try it in one repo only
te status # what it learned and did in this repo- In a scratch repo it switched off 187 tools I never used there (written to
.claude/settings.local.json). - The twist: tokens per request didn't shrink. About 43.6k in four sessions before, 43.7k in four after (from its own ledger). Claude Code already loads most rarely used tools on demand instead of sending them every time, so there was little left to prune in my setup. Its paper reports 18-31% lower cost on SWE-Bench tasks, from all three of its mechanisms over many sessions; my eight short sessions are not a fair test of that.
- It needs Python 3.10 or newer for its hooks (set
TE_PYTHONif yourpython3is older).
The takeaway: it's not your code that costs, it's the context. Start new sessions for new tasks, keep CLAUDE.md and your skill list lean, and turn off MCP servers you don't use.
More free guides: pranavinnovates.com