Skip to content

Instantly share code, notes, and snippets.

@andynu
Created January 10, 2026 19:39
Show Gist options
  • Select an option

  • Save andynu/50e4ad20ced7a9e5ac93052ff1911048 to your computer and use it in GitHub Desktop.

Select an option

Save andynu/50e4ad20ced7a9e5ac93052ff1911048 to your computer and use it in GitHub Desktop.
Claude Code custom statusline script - shows model, folder, git branch, and token usage with progress bar
#!/bin/bash
input=$(cat)
MODEL=$(echo "$input" | jq -r '.model.display_name // "Claude"')
DIR=$(echo "$input" | jq -r '.workspace.current_dir // "~"')
FOLDER="${DIR##*/}"
# Git branch
BRANCH=""
if git -C "$DIR" rev-parse --git-dir > /dev/null 2>&1; then
BRANCH=$(git -C "$DIR" branch --show-current 2>/dev/null)
[ -z "$BRANCH" ] && BRANCH=$(git -C "$DIR" rev-parse --short HEAD 2>/dev/null)
fi
# Token usage - use current_usage for actual context window consumption
USAGE=$(echo "$input" | jq '.context_window.current_usage')
TOKENS_MAX=$(echo "$input" | jq -r '.context_window.context_window_size // 200000')
if [ "$USAGE" != "null" ]; then
# Sum input tokens + cache tokens for total context consumption
TOKENS_USED=$(echo "$USAGE" | jq -r '(.input_tokens // 0) + (.cache_creation_input_tokens // 0) + (.cache_read_input_tokens // 0)')
else
TOKENS_USED=0
fi
# Calculate percentage remaining until autocompact (matches Claude's built-in calculation)
# Autocompact threshold = context_window - max_output_reserved (~32k) - autocompact_buffer (13k)
if [ "$TOKENS_MAX" -gt 0 ] 2>/dev/null; then
AUTOCOMPACT_THRESHOLD=$((TOKENS_MAX - 32000 - 13000))
if [ "$AUTOCOMPACT_THRESHOLD" -gt 0 ]; then
PCT_REMAINING=$(( (AUTOCOMPACT_THRESHOLD - TOKENS_USED) * 100 / AUTOCOMPACT_THRESHOLD ))
[ "$PCT_REMAINING" -lt 0 ] && PCT_REMAINING=0
PCT=$((100 - PCT_REMAINING)) # Convert "remaining" to "used"
else
PCT=0
fi
else
PCT=0
fi
# Format token count (e.g., 45.2k)
if [ "$TOKENS_USED" -ge 1000 ]; then
TOKENS_FMT=$(awk "BEGIN {printf \"%.1fk\", $TOKENS_USED/1000}")
else
TOKENS_FMT="$TOKENS_USED"
fi
# Progress bar (10 chars wide)
BAR_WIDTH=10
FILLED=$((PCT * BAR_WIDTH / 100))
EMPTY=$((BAR_WIDTH - FILLED))
BAR=$(printf '%*s' "$FILLED" '' | tr ' ' '█')$(printf '%*s' "$EMPTY" '' | tr ' ' '░')
# Build output
if [ -n "$BRANCH" ]; then
echo "[$MODEL] $FOLDER ($BRANCH) | ${TOKENS_FMT} [$BAR] ${PCT}%"
else
echo "[$MODEL] $FOLDER | ${TOKENS_FMT} [$BAR] ${PCT}%"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment