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:

  1. On every turn, Claude Code pipes a JSON object with session info to your script via stdin.
  2. 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:

FieldMeaning
model.display_nameModel name (e.g. Opus)
cost.total_cost_usdEstimated session cost (USD)
cost.total_duration_msTotal session duration
cost.total_lines_added / total_lines_removedLines of code added/removed
context_window.used_percentageContext usage (0–100)

The community tool ccusage calculates cost, tokens, and burn rate and prints them on one line. Just add this to ~/.claude/settings.json:

JSON
{
  "statusLine": {
    "type": "command",
    "command": "npx -y ccusage statusline",
    "padding": 0
  }
}

Example output:

TEXT
πŸ€– 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:

TEXT
/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:

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:

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 wantRecommended option
Always see cost/tokens at the bottomccusage (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.