Guide
Claude Code token usage: where it lives and how to cut it
Updated 2026-11-14
Claude Code already writes down the token count of every request it makes. The numbers sit in plain log files on your machine. This guide covers where those files are, what each usage field means, how to turn them into a token usage report, and which habits move the numbers most.
Where Claude Code records token usage
Every session writes a JSONL log under ~/.claude/projects/,
one folder per project. Each assistant turn in that log carries a
usage block with four counters:
| Field | What it counts | Price at API rates |
|---|---|---|
input_tokens | New input sent without the cache | Full input price |
cache_creation_input_tokens | Input written to the prompt cache | 1.25x input (five-minute cache), 2x (one-hour cache) |
cache_read_input_tokens | Input served from the cache | 0.1x input on most models |
output_tokens | What the model wrote back | Output price |
Two details trip up home-made totals. Streaming writes the same request more than once, so rows need deduplicating by request id before you add them up. And subagents and workflows write their own sub-logs beside the parent session, so a report that skips them undercounts delegated work.
Getting a token usage report
Run this in any terminal on the machine where you use Claude Code:
npx costclaw audit
It reads those logs locally, deduplicates them, and prints the totals at
dated API list prices, your cache hit rate, the model mix, your top
projects, a by-day spend rhythm, and a ranked list of changes with the
evidence behind each one. It also writes an HTML version of the report and
opens it. On a Pro or Max subscription, add --plan max20x (or
pro, max5x) and the report frames the same
numbers as a share of your usage instead of dollars.
If you only want daily or monthly token tables, the open-source ccusage reads the same logs and does that well. CostClaw adds the setup score and the ranked list of what to change.
How to reduce Claude Code token usage
These are the five levers the audit measures from your own logs.
- Keep the cache warm. The prompt cache lives five minutes by default. A turn after a longer pause writes the whole prefix again at the write price. See the cache guide for the numbers.
- Keep CLAUDE.md small and stable. It is sent with every
session in the project, so every line is paid for on every turn. Dated
status notes and long histories belong in
docs/. See CLAUDE.md best practices. - Send small jobs to a cheaper model. A short session on the most expensive model is the easiest saving to spot. The audit flags trivial sessions that ran on Opus or Fable and prices them against Sonnet.
- Clear or compact long sessions. In marathon sessions the context keeps growing and the cache hit rate tends to sag late in the session. Starting fresh with a short summary is often cheaper than carrying everything.
- Stop tool loops early. The same tool hitting the same file or command ten or more times in one session usually means the agent is stuck. A stop condition in CLAUDE.md, or a quicker interrupt, ends the loop sooner.