Last active
July 1, 2026 14:42
-
-
Save grundmanise/e3417808630e97d4972b75b6c7cefcb7 to your computer and use it in GitHub Desktop.
Claude Code custom statusline: model [effort] + cwd (git branch) + context bar with token usage and color thresholds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| input=$(cat) | |
| model_raw=$(echo "$input" | jq -r '.model.display_name // .model.id // "claude"') | |
| cwd=$(echo "$input" | jq -r '.workspace.current_dir // .cwd // ""') | |
| effort=$(echo "$input" | jq -r '.effort_level // .effortLevel // empty') | |
| output_style=$(echo "$input" | jq -r '.output_style.name // ""') | |
| # Fall back to settings.json — Claude Code doesn't pass effortLevel via stdin | |
| if [ -z "$effort" ]; then | |
| effort=$(jq -r '.effortLevel // empty' "$HOME/.claude/settings.json" 2>/dev/null) | |
| fi | |
| total_tokens=$(echo "$input" | jq -r '(.context_window.total_input_tokens // 0) + (.context_window.total_output_tokens // 0)') | |
| context_size=$(echo "$input" | jq -r '.context_window.context_window_size // 0') | |
| used_pct=$(echo "$input" | jq -r '.context_window.used_percentage // empty') | |
| # Strip "(1M context)" — redundant with progress bar | |
| model=$(echo "$model_raw" | sed -E 's/ *\([^)]*\)//g') | |
| dir_base=$(basename "$cwd" 2>/dev/null) | |
| branch="" | |
| if [ -n "$cwd" ] && [ -d "$cwd" ]; then | |
| branch=$(git -C "$cwd" rev-parse --abbrev-ref HEAD 2>/dev/null) | |
| fi | |
| format_tokens() { | |
| local n=$1 | |
| if [ "$n" -ge 1000000 ]; then | |
| printf "%s" "$(echo "scale=1; $n/1000000" | bc -l | sed 's/\.0$//')M" | |
| elif [ "$n" -ge 1000 ]; then | |
| printf "%dK" $((n / 1000)) | |
| else | |
| printf "%d" "$n" | |
| fi | |
| } | |
| RED=$'\033[1;31m' | |
| YELLOW=$'\033[1;33m' | |
| RESET=$'\033[0m' | |
| # Build segments | |
| left="$model" | |
| [ -n "$effort" ] && [ "$effort" != "null" ] && left="$left [$effort]" | |
| [ -n "$output_style" ] && [ "$output_style" != "null" ] && [ "$output_style" != "default" ] && left="$left {$output_style}" | |
| [ -n "$dir_base" ] && left="$left · $dir_base" | |
| [ -n "$branch" ] && left="$left ($branch)" | |
| if [ -n "$used_pct" ] && [ "$used_pct" != "null" ]; then | |
| bw=10 | |
| f=$(printf "%.0f" "$(echo "$used_pct * $bw / 100" | bc -l)") | |
| [ "$f" -lt 0 ] && f=0 | |
| [ "$f" -gt "$bw" ] && f=$bw | |
| e=$((bw - f)) | |
| bar="" | |
| for ((i=0; i<f; i++)); do bar="${bar}█"; done | |
| for ((i=0; i<e; i++)); do bar="${bar}░"; done | |
| tokens_fmt=$(format_tokens "$total_tokens") | |
| context_fmt=$(format_tokens "$context_size") | |
| ctx="$bar $(printf "%.0f" "$used_pct")% ($tokens_fmt/$context_fmt)" | |
| color="" | |
| [ "$total_tokens" -ge 150000 ] && color="$YELLOW" | |
| [ "$total_tokens" -ge 300000 ] && color="$RED" | |
| if [ -n "$color" ]; then | |
| left="$left · ${color}${ctx}${RESET}" | |
| else | |
| left="$left · $ctx" | |
| fi | |
| fi | |
| printf "%s\n" "$left" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to reuse
Install on a new machine:
Wire it up in
~/.claude/settings.json:{ "statusLine": { "type": "command", "command": "~/.claude/statusline-command.sh" } }Requires
jqandbconPATH(preinstalled on macOS;brew install jq bcif missing).Update the gist after local edits:
gh gist edit e3417808630e97d4972b75b6c7cefcb7 ~/.claude/statusline-command.shPull latest changes down to another machine:
curl -fsSL https://gist.githubusercontent.com/grundmanise/e3417808630e97d4972b75b6c7cefcb7/raw/statusline-command.sh -o ~/.claude/statusline-command.sh