Show Token Usage and Estimated Cost in Claude Code
When you use Claude Code for a while, you start wondering: "How many tokens have I used? What's the cost so far?" You can surface exactly that at the bottom of the screen using a feature called the statusline.
How the statusline works
The mechanism is simple:
- On every turn, Claude Code pipes a JSON object with session info to your script via stdin.
- Whatever your script prints is shown at the bottom of the screen.
So displaying cost and tokens just means parsing that JSON. The key fields are:
| Field | Meaning |
|---|---|
model.display_name | Model name (e.g. Opus) |
cost.total_cost_usd | Estimated session cost (USD) |
cost.total_duration_ms | Total session duration |
cost.total_lines_added / total_lines_removed | Lines of code added/removed |
context_window.used_percentage | Context usage (0β100) |
Option 1. Use ccusage (easiest, recommended)
The community tool ccusage calculates cost, tokens, and burn rate and prints them on one line. Just add this to ~/.claude/settings.json:
{
"statusLine": {
"type": "command",
"command": "npx -y ccusage statusline",
"padding": 0
}
}
Example output:
π€ Opus 4.8 | π° $0.23 session / $1.23 today | π₯ $0.12/hr | π§ 25,000 (12%)
- session: cost spent in this conversation
- today: cumulative cost today
- /hr: spending rate per hour (burn rate)
- π§ : tokens currently in context and the usage percentage
As long as Node.js is installed, npx runs it instantly (Windows included).
Option 2. Build your own with /statusline
Tell Claude Code what you want in plain language and it generates the script for you:
/statusline show model name, estimated cost ($), and context usage as a progress bar
If you'd rather write the script yourself, just parse the JSON from stdin. For example, in bash:
#!/bin/bash
input=$(cat)
MODEL=$(echo "$input" | jq -r '.model.display_name')
COST=$(echo "$input" | jq -r '.cost.total_cost_usd // 0')
PCT=$(echo "$input" | jq -r '.context_window.used_percentage // 0' | cut -d. -f1)
echo "[$MODEL] π° $(printf '$%.2f' "$COST") | π§ ${PCT}%"
Save it as ~/.claude/statusline.sh and point to it in settings.json:
{
"statusLine": {
"type": "command",
"command": "~/.claude/statusline.sh"
}
}
Option 3. Just check it occasionally
You don't have to keep the statusline on all the time. You can check on demand with a command:
/usage(or/cost,/stats) β shows session cost, duration, token usage, and lines changed all at once.
Summary
| What you want | Recommended option |
|---|---|
| Always see cost/tokens at the bottom | ccusage (Option 1) |
| Fully customize it | /statusline or your own script (Option 2) |
| Only check occasionally | /usage (Option 3) |
If you're just getting started, go with ccusage. One line in settings.json makes cost tracking far easier.