A custom status line for Claude Code that shows real-time context window usage with a visual progress bar.
[op] $0.31 | ████░░░░░░ 22.6% (45K/200K) | main*
[op]- Model indicator (op=opus, so=sonnet, ha=haiku)$0.31- Session cost████░░░░░░- Visual progress bar (color-coded: green/yellow/red)22.6% (45K/200K)- Context usage percentage and token countsmain*- Git branch (* indicates uncommitted changes)
- Real-time context tracking - See exactly how much of the 200K context window you've used
- Color-coded warnings:
- Green: < 50% (plenty of room)
- Yellow: 50-80% (getting full)
- Red: > 80% (danger zone, consider compacting)
- Cost tracking - Running total for the session
- Git integration - Current branch with dirty indicator
- Claude Code CLI
jqfor JSON parsing:# macOS brew install jq # Ubuntu/Debian sudo apt install jq
-
Create the hooks directory (if it doesn't exist):
mkdir -p ~/.claude/hooks -
Download the script:
curl -o ~/.claude/hooks/statusline.sh \ "https://gist.githubusercontent.com/RAW_URL_HERE/statusline.sh" chmod +x ~/.claude/hooks/statusline.sh
Or copy
statusline.shfrom this gist manually. -
Configure Claude Code - Add to
~/.claude/settings.json:{ "statusLine": { "type": "command", "command": "~/.claude/hooks/statusline.sh" } }If you already have a settings.json, just add the
statusLineblock. -
Restart Claude Code to apply changes.
Claude Code passes JSON data to the status line command via stdin, including:
{
"model": { "api_model_id": "claude-opus-4-..." },
"cost": { "total_cost_usd": 0.31 },
"context_window": {
"context_window_size": 200000,
"current_usage": {
"input_tokens": 30000,
"output_tokens": 10000,
"cache_creation_input_tokens": 5000,
"cache_read_input_tokens": 0
}
}
}The script parses this data and renders the progress bar with color coding.
Edit this line in the script:
bar=$(printf '%*s' "$filled" '' | tr ' ' '█')$(printf '%*s' "$empty" '' | tr ' ' '░')Alternative styles:
▓and░- Shaded blocks#and-- ASCII only⣿and⣀- Braille dots
if [ "$pct_int" -ge 80 ]; then # Red threshold
color="\033[31m"
elif [ "$pct_int" -ge 50 ]; then # Yellow threshold
color="\033[33m"
else
color="\033[32m" # Green (default)
fiRemove or comment out the git_info section (lines 85-95).
MIT - Feel free to modify and share!
Hello, the detection of the model was not working , you can add than this to retrieve it from settings
if [ -z "$model" ] || [ "$model" = "null" ]; then
settings_file="$HOME/.claude/settings.json"
if [ -f "$settings_file" ] && command -v jq &>/dev/null; then
model=$(jq -r '.model // empty' "$settings_file" 2>/dev/null)
fi
fi