CostClaw Get started

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:

FieldWhat it countsPrice at API rates
input_tokensNew input sent without the cacheFull input price
cache_creation_input_tokensInput written to the prompt cache1.25x input (five-minute cache), 2x (one-hour cache)
cache_read_input_tokensInput served from the cache0.1x input on most models
output_tokensWhat the model wrote backOutput 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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.

Run it on your own logs.

The audit reads what is already on your disk and prints the report. If it finds nothing, you have lost a minute. If it finds signals, you have a local estimate to investigate.

npx costclaw audit

Reads local logs. Sends nothing. No account.