Skip to content

Instantly share code, notes, and snippets.

@joncardasis
Last active March 4, 2026 13:57
Show Gist options
  • Select an option

  • Save joncardasis/0fa2f2037e58016f4c92f11e6faa7401 to your computer and use it in GitHub Desktop.

Select an option

Save joncardasis/0fa2f2037e58016f4c92f11e6faa7401 to your computer and use it in GitHub Desktop.
Claude Code Statusline - Show tok and cost info

Claude Code Status Line

Example: [Opus 4.6 (1M context)] Context: 0% (↑339 ↓7.9k) | $0.53

  1. Place the above script in ~/.claude/statusline.sh

  2. Edit ~/.claude/settings.json to include a new key:

    "statusLine": {
      "type": "command",
      "command": "~/.claude/statusline.sh"
    }
    
#!/bin/bash
input=$(cat)
MODEL=$(echo "$input" | jq -r '.model.display_name')
INPUT_TOKENS=$(echo "$input" | jq -r '.context_window.total_input_tokens')
OUTPUT_TOKENS=$(echo "$input" | jq -r '.context_window.total_output_tokens')
CONTEXT_SIZE=$(echo "$input" | jq -r '.context_window.context_window_size')
COST=$(echo "$input" | jq -r '.cost.total_cost_usd')
TOTAL_TOKENS=$((INPUT_TOKENS + OUTPUT_TOKENS))
PERCENT_USED=$((TOTAL_TOKENS * 100 / CONTEXT_SIZE))
format_tokens() {
local n=$1
if [ "$n" -lt 1000 ]; then
printf "%d" "$n"
else
local tenths=$((n / 100))
printf "%d.%dk" "$((tenths / 10))" "$((tenths % 10))"
fi
}
IN_FMT=$(format_tokens "$INPUT_TOKENS")
OUT_FMT=$(format_tokens "$OUTPUT_TOKENS")
printf "[%s] Context: %d%% (↑%s ↓%s) | \$%.2f" "$MODEL" "$PERCENT_USED" "$IN_FMT" "$OUT_FMT" "$COST"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment