Example: [Opus 4.6 (1M context)] Context: 0% (↑339 ↓7.9k) | $0.53
-
Place the above script in
~/.claude/statusline.sh -
Edit
~/.claude/settings.jsonto 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" |