Skip to content

Instantly share code, notes, and snippets.

@abhinavguptas
Created April 14, 2026 07:08
Show Gist options
  • Select an option

  • Save abhinavguptas/d59d8b502a3be542fd2a6bf66e9ffdff to your computer and use it in GitHub Desktop.

Select an option

Save abhinavguptas/d59d8b502a3be542fd2a6bf66e9ffdff to your computer and use it in GitHub Desktop.
claude code status line script
#!/bin/bash
# Claude Code statusline
# Line 1: MODEL | $cost | ctx% - tokens/total | 5h% (reset?) | 7d% (reset?)
# Line 2: repo (branch) [dimmed]
INPUT=$(cat)
MODEL_ID=$(echo "$INPUT" | jq -r '.model.id // ""')
MODEL_NAME=$(echo "$INPUT" | jq -r '.model.display_name // .model.id // "claude"')
CWD=$(echo "$INPUT" | jq -r '.cwd // ""')
CTX_TOKENS=$(echo "$INPUT" | jq -r '.context_window.total_input_tokens // 0')
CTX_SIZE=$(echo "$INPUT" | jq -r '.context_window.context_window_size // 200000')
CTX_PCT=$(echo "$INPUT" | jq -r '.context_window.used_percentage // 0')
FIVE_PCT=$(echo "$INPUT" | jq -r '.rate_limits.five_hour.used_percentage // 0')
FIVE_RESET=$(echo "$INPUT" | jq -r '.rate_limits.five_hour.resets_at // 0')
SEVEN_PCT=$(echo "$INPUT" | jq -r '.rate_limits.seven_day.used_percentage // 0')
SEVEN_RESET=$(echo "$INPUT" | jq -r '.rate_limits.seven_day.resets_at // 0')
# --- ANSI colors ---
R=$'\033[0m'
DIM=$'\033[2m'
CYAN=$'\033[1;38;5;30m'
YELLOW=$'\033[1;38;5;136m'
GREEN=$'\033[1;38;5;28m'
RED=$'\033[1;38;5;160m'
MAGENTA=$'\033[1;38;5;125m'
SEP="${DIM}|${R} "
# --- Model badge ---
case "$MODEL_ID" in
*opus*) BG=$'\033[48;5;203m' ;;
*sonnet*) BG=$'\033[48;5;75m' ;;
*haiku*) BG=$'\033[48;5;108m' ;;
*) BG=$'\033[48;5;244m' ;;
esac
MODEL_LABEL=$(echo "$MODEL_NAME" | tr '[:lower:]' '[:upper:]')
FG=$'\033[97m'
BADGE="${BG}${FG} ${MODEL_LABEL} ${R}"
# --- Context: 13% ctx - 352/200.0K ---
fmt_k() { awk "BEGIN { n=$1; if (n>=1000) printf \"%.1fK\", n/1000; else printf \"%d\", n }"; }
if [ "$CTX_PCT" -ge 80 ]; then CC=$RED
elif [ "$CTX_PCT" -ge 50 ]; then CC=$YELLOW
else CC=$GREEN
fi
CTX_PART="${SEP}${CC}${CTX_PCT}% ctx${R} ${DIM}-${R} $(fmt_k "$CTX_TOKENS")/$(fmt_k "$CTX_SIZE")"
# --- Reset time helper: Xh Ym or Xd Yh ---
reset_str() {
local SECS=$(( $1 - $(date +%s) ))
[ "$SECS" -le 0 ] && return
local D=$(( SECS / 86400 ))
local H=$(( (SECS % 86400) / 3600 ))
local M=$(( (SECS % 3600) / 60 ))
if [ "$D" -gt 0 ]; then echo " (${D}d ${H}h)"
else echo " (${H}h ${M}m)"; fi
}
# --- 5-hour limit ---
if [ "$FIVE_PCT" -gt 40 ]; then
FIVE_PART="${SEP}${YELLOW}5h ${FIVE_PCT}%$(reset_str "$FIVE_RESET")${R}"
else
FIVE_PART="${SEP}${GREEN}5h ${FIVE_PCT}%${R}"
fi
# --- 7-day limit ---
if [ "$SEVEN_PCT" -gt 40 ]; then
SEVEN_PART="${SEP}${YELLOW}7d ${SEVEN_PCT}%$(reset_str "$SEVEN_RESET")${R}"
else
SEVEN_PART="${SEP}${GREEN}7d ${SEVEN_PCT}%${R}"
fi
# --- Line 1 ---
printf "%s%s%s%s\n" "$BADGE" "$CTX_PART" "$FIVE_PART" "$SEVEN_PART"
# --- Line 2: repo (branch) dimmed ---
REPO=$(basename "$CWD" 2>/dev/null || echo "~")
BRANCH=""
if git -C "$CWD" rev-parse --git-dir >/dev/null 2>&1; then
BRANCH=$(git -C "$CWD" branch --show-current 2>/dev/null)
fi
if [ -n "$BRANCH" ]; then
printf "${DIM}%s (%s)${R}" "$REPO" "$BRANCH"
else
printf "${DIM}%s${R}" "$REPO"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment