A personal setup that shows token usage in Claude Code without spending any model tokens. Both pieces are local shell scripts that read the session transcript.
statusline.shis an always-visible status line:Sonnet 5.5 | ctx 146.5k | out 7.3k | calls 15 | $1.01token-report.shis a Stop hook that prints a one-line breakdown after each response:tokens this request: in 6 | out 1742 | cache-read 190957 | cache-write 88736 | api-calls 2 | context now ~140871
mkdir -p ~/.claude/hooks
cp statusline.sh token-report.sh ~/.claude/hooks/
chmod +x ~/.claude/hooks/*.shMerge this into ~/.claude/settings.json (keep your existing keys; do not replace the file):
{
"statusLine": {
"type": "command",
"command": "~/.claude/hooks/statusline.sh"
},
"hooks": {
"Stop": [
{
"hooks": [
{ "type": "command", "command": "~/.claude/hooks/token-report.sh", "timeout": 10 }
]
}
]
}
}If nothing appears, open /hooks once or restart Claude Code.
You only see usage if you remember to run /context or /cost, and in the middle of work you won't. This puts the numbers on screen all the time, so you can:
- clear the context before answers get worse
- notice which prompts are expensive
- never be surprised by usage or cost
The status line is always on. The Stop hook adds one extra line after each reply. If that's too much, remove the hook and keep the status line.
| Field | Meaning |
|---|---|
ctx |
Size of the most recent prompt, including cached content. Drops after /clear or compaction. |
out |
Cumulative output tokens for the session. |
calls |
Model calls in the session. |
$ |
Session cost reported by Claude Code. An estimate, not an invoice. Omitted if not supplied. |
cache-read / cache-write |
Prompt cache traffic. Usually the largest numbers. |
jq and awk. If jq is missing, both scripts print a short "jq not installed" message and exit cleanly. Tested on macOS only.
- It reads the session transcript (JSONL), which is not a documented stable API. A Claude Code update could change the field names and break the numbers.
- The status line re-parses the whole transcript on every refresh, so it can get slower in very long sessions.
- Per-request totals may not include subagent calls.
Remove the statusLine and hooks blocks from ~/.claude/settings.json, and delete the scripts.