Skip to content

Instantly share code, notes, and snippets.

@StuMason
Created February 25, 2026 13:33
Show Gist options
  • Select an option

  • Save StuMason/3e98ea184de32ecd74d65ede1fa0a7f2 to your computer and use it in GitHub Desktop.

Select an option

Save StuMason/3e98ea184de32ecd74d65ede1fa0a7f2 to your computer and use it in GitHub Desktop.
Custom statusline script for Claude Code CLI showing repo name, git branch (with dirty indicator), color-coded context usage, session cost, duration, lines changed, and active model name.
#!/bin/bash
# Read JSON input once
input=$(cat)
# Extract fields
cwd=$(echo "$input" | jq -r '.workspace.current_dir')
ctx_pct=$(echo "$input" | jq -r '.context_window.used_percentage // 0' | cut -d. -f1)
cost=$(echo "$input" | jq -r '.cost.total_cost_usd // 0')
cost_fmt=$(printf '$%.2f' "$cost")
dur_ms=$(echo "$input" | jq -r '.cost.total_duration_ms // 0')
mins=$((dur_ms / 60000))
added=$(echo "$input" | jq -r '.cost.total_lines_added // 0')
removed=$(echo "$input" | jq -r '.cost.total_lines_removed // 0')
model=$(echo "$input" | jq -r '.model.display_name // "unknown"')
# Context color
if [ "$ctx_pct" -ge 60 ]; then
ctx_color='\033[01;31m' # red
elif [ "$ctx_pct" -ge 40 ]; then
ctx_color='\033[01;33m' # yellow
else
ctx_color='\033[01;32m' # green
fi
# Cost color (red above $1)
cost_color='\033[00m'
cost_cents=$(echo "$cost" | awk '{printf "%d", $1 * 100}')
[ "$cost_cents" -ge 100 ] && cost_color='\033[01;31m'
# Git info
branch=""
dirty=""
repo=$(basename "$cwd")
if git -C "$cwd" rev-parse --git-dir > /dev/null 2>&1; then
branch=$(git -C "$cwd" symbolic-ref --short HEAD 2>/dev/null || echo "detached")
dirty_count=$(git -C "$cwd" status --porcelain 2>/dev/null | wc -l | tr -d ' ')
[ "$dirty_count" -gt 0 ] && dirty="*"
fi
printf '\033[01;36m%s\033[00m \033[02m%s%s\033[00m | ctx: %b%s%%\033[00m | %b%s\033[00m | %sm | \033[32m+%s\033[00m \033[31m-%s\033[00m | %s' \
"$repo" "$branch" "$dirty" \
"$ctx_color" "$ctx_pct" \
"$cost_color" "$cost_fmt" \
"$mins" \
"$added" "$removed" \
"$model"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment