A custom status line that shows session info: model, context usage, and cost.
opus-4-6 | 12% | $0.04
- Model (blue) — shortened model name
- Context (yellow) — percentage of context window used
- Cost (green) — session cost in USD
- jq installed (
brew install jqon macOS)
Create ~/.claude/statusline-command.sh:
#!/bin/bash
input=$(cat)
model=$(echo "$input" | jq -r '.model.display_name | sub("^anthropic\\.claude-";"") | sub("-v[0-9]+$";"")')
ctx=$(echo "$input" | jq -r '.context_window.used_percentage // 0')
cost=$(echo "$input" | jq -r '.cost.total_cost_usd')
cost_fmt=$(printf "%.2f" "$cost")
printf "\033[34m%s\033[0m \033[2m|\033[0m \033[33m%s%%\033[0m \033[2m|\033[0m \033[32m\$%s\033[0m" "$model" "$ctx" "$cost_fmt"Make it executable:
chmod +x ~/.claude/statusline-command.shAdd the statusLine entry to ~/.claude/settings.json:
{
"statusLine": {
"type": "command",
"command": "bash ~/.claude/statusline-command.sh"
}
}That's it. The status line appears at the bottom of the Claude Code terminal.
Claude Code pipes a JSON object to the status line command's stdin on each refresh. The script extracts three fields:
| Field | JSON path | Description |
|---|---|---|
| Model | .model.display_name |
Active model, trimmed to short name (e.g. opus-4-6) |
| Context | .context_window.used_percentage |
Percentage of context window consumed |
| Cost | .cost.total_cost_usd |
Cumulative session cost in USD |
The ANSI escape codes in the printf control colors. Change them to suit your terminal theme:
| Code | Color |
|---|---|
\033[31m |
Red |
\033[32m |
Green |
\033[33m |
Yellow |
\033[34m |
Blue |
\033[35m |
Magenta |
\033[36m |
Cyan |
\033[1m |
Bold |
\033[2m |
Dim |
The full JSON input includes:
{
"session_id": "...",
"cwd": "/path/to/project",
"model": { "id": "...", "display_name": "..." },
"version": "2.1.39",
"cost": {
"total_cost_usd": 3.10,
"total_duration_ms": 80201764,
"total_api_duration_ms": 545739,
"total_lines_added": 106,
"total_lines_removed": 38
},
"context_window": {
"used_percentage": 19,
"remaining_percentage": 81,
"context_window_size": 200000
}
}