Skip to content

Instantly share code, notes, and snippets.

@chanlito
Created May 9, 2026 08:36
Show Gist options
  • Select an option

  • Save chanlito/799d5cad33668f725be675717af56e08 to your computer and use it in GitHub Desktop.

Select an option

Save chanlito/799d5cad33668f725be675717af56e08 to your computer and use it in GitHub Desktop.
Claude Code statusline — Model | Ctx | Git | 5h | 7d
#!/usr/bin/env bash
input=$(cat)
model=$(echo "$input" | jq -r '.model.display_name // ""')
used_pct=$(echo "$input" | jq -r '.context_window.used_percentage // empty')
cwd=$(echo "$input" | jq -r '.workspace.current_dir // .cwd // ""')
five_hr_pct=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
seven_day_pct=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty')
perm_mode=$(echo "$input" | jq -r '.permission_mode // empty')
color_for_pct() {
local pct="$1"
[ -z "$pct" ] && echo "2" && return
local i=$(printf "%.0f" "$pct")
if [ "$i" -ge 80 ]; then echo "31"
elif [ "$i" -ge 50 ]; then echo "33"
else echo "2"
fi
}
SEP="\033[2m | \033[0m"
out=""
# Model — color by tier: Haiku=green, Sonnet=cyan, Opus=yellow
model_color="36"
case "$model" in
*[Hh]aiku*) model_color="32" ;;
*[Ss]onnet*) model_color="36" ;;
*[Oo]pus*) model_color="33" ;;
esac
effort=$(echo "$input" | jq -r '.effort.level // empty')
[ -n "$model" ] && out="Model: \033[${model_color}m${model}\033[0m"
[ -n "$effort" ] && out="${out} \033[2m(${effort})\033[0m"
# Git branch
branch=""
[ -n "$cwd" ] && branch=$(git -C "$cwd" -c core.hooksPath=/dev/null symbolic-ref --short HEAD 2>/dev/null)
[ -n "$branch" ] && out="${out}${SEP}⎇ \033[35m${branch}\033[0m"
# Git changes (+X,-Y)
if [ -n "$branch" ]; then
ins=0; del=0
for stat in \
"$(git -C "$cwd" -c core.hooksPath=/dev/null diff --shortstat 2>/dev/null)" \
"$(git -C "$cwd" -c core.hooksPath=/dev/null diff --cached --shortstat 2>/dev/null)"; do
i=$(echo "$stat" | grep -o '[0-9]* insertion' | grep -o '[0-9]*'); ins=$((ins + ${i:-0}))
d=$(echo "$stat" | grep -o '[0-9]* deletion' | grep -o '[0-9]*'); del=$((del + ${d:-0}))
done
if [ "$ins" -gt 0 ] || [ "$del" -gt 0 ]; then
out="${out}${SEP}(\033[32m+${ins}\033[0m,\033[31m-${del}\033[0m)"
else
out="${out}${SEP}\033[2m(+0,-0)\033[0m"
fi
fi
# Context (percentage)
if [ -n "$used_pct" ]; then
c=$(color_for_pct "$used_pct")
i=$(printf "%.1f" "$used_pct")
out="${out}${SEP}Ctx: \033[${c}m${i}%\033[0m"
fi
# 5h rate limit
if [ -n "$five_hr_pct" ]; then
i=$(printf "%.0f" "$five_hr_pct"); c=$(color_for_pct "$five_hr_pct")
out="${out}${SEP}5h: \033[${c}m${i}%\033[0m"
fi
# 7d rate limit
if [ -n "$seven_day_pct" ]; then
i=$(printf "%.0f" "$seven_day_pct"); c=$(color_for_pct "$seven_day_pct")
out="${out}${SEP}7d: \033[${c}m${i}%\033[0m"
fi
# Permission mode
if [ -n "$perm_mode" ] && [ "$perm_mode" != "default" ]; then
out="${out}${SEP}\033[33m►► ${perm_mode}\033[0m"
fi
printf "%b\n" "$out"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment