Skip to content

Instantly share code, notes, and snippets.

@tdwesten
Created March 25, 2026 08:52
Show Gist options
  • Select an option

  • Save tdwesten/dd88edf7735b7d1aa7e26218b7b2ed6a to your computer and use it in GitHub Desktop.

Select an option

Save tdwesten/dd88edf7735b7d1aa7e26218b7b2ed6a to your computer and use it in GitHub Desktop.
Claude statusline.sh
#!/bin/bash
# Read JSON input once
input=$(cat)
# Extract current directory
cwd=$(echo "$input" | jq -r '.workspace.current_dir')
# Extract context percentage
ctx_pct=$(echo "$input" | jq -r '.context_window.used_percentage // 0' | cut -d. -f1)
# Extract model label (opus/sonnet/haiku)
model_id=$(echo "$input" | jq -r '.model.id // ""')
if echo "$model_id" | grep -qi 'opus'; then
model_label='opus'
elif echo "$model_id" | grep -qi 'haiku'; then
model_label='haiku'
elif echo "$model_id" | grep -qi 'sonnet'; then
model_label='sonnet'
else
model_label=$(echo "$input" | jq -r '.model.display_name // ""' | tr '[:upper:]' '[:lower:]')
fi
# Git information
if git -C "$cwd" rev-parse --git-dir > /dev/null 2>&1; then
# Get repo name (just the directory name)
repo_name=$(basename "$cwd")
# Get current branch (or short commit hash if detached HEAD)
branch=$(git -C "$cwd" symbolic-ref --short HEAD 2>/dev/null || git -C "$cwd" rev-parse --short HEAD 2>/dev/null)
# Dirty indicator — staged or unstaged changes, no network calls
if ! git -C "$cwd" diff --quiet 2>/dev/null || ! git -C "$cwd" diff --cached --quiet 2>/dev/null; then
dirty='*'
else
dirty=''
fi
# Ahead/behind relative to upstream — local only, no fetch
ahead_behind=''
upstream=$(git -C "$cwd" rev-parse --abbrev-ref '@{upstream}' 2>/dev/null)
if [ -n "$upstream" ]; then
counts=$(git -C "$cwd" rev-list --left-right --count HEAD..."$upstream" 2>/dev/null)
ahead=$(echo "$counts" | awk '{print $1}')
behind=$(echo "$counts" | awk '{print $2}')
[ "${ahead:-0}" -gt 0 ] && ahead_behind="${ahead_behind}${ahead}"
[ "${behind:-0}" -gt 0 ] && ahead_behind="${ahead_behind}${behind}"
[ -n "$ahead_behind" ] && ahead_behind=" ${ahead_behind}"
fi
# Color the context percentage based on usage
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
printf '\033[01;36m%s\033[00m 🌿\033[01;35m(%s%s%s)\033[00m | 📊 %b%s%%\033[00m | 🧠 \033[00;37m%s\033[00m' \
"$repo_name" "$branch" "$dirty" "$ahead_behind" "$ctx_color" "$ctx_pct" "$model_label"
else
printf '\033[01;36m%s\033[00m | 📊 %s%% | 🧠 \033[00;37m%s\033[00m' "$cwd" "$ctx_pct" "$model_label"
fi

Comments are disabled for this gist.