Skip to content

Instantly share code, notes, and snippets.

@naoki-sawada
Created March 6, 2026 14:00
Show Gist options
  • Select an option

  • Save naoki-sawada/da6f4656a339d6ff91a473982fb57b44 to your computer and use it in GitHub Desktop.

Select an option

Save naoki-sawada/da6f4656a339d6ff91a473982fb57b44 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Read JSON data that Claude Code sends to stdin
input=$(cat)
# Extract fields using jq
MODEL=$(echo "$input" | jq -r '.model.display_name // "Unknown"')
DIR=$(echo "$input" | jq -r '.workspace.current_dir // .cwd // "."')
PCT=$(echo "$input" | jq -r '.context_window.used_percentage // 0' | cut -d. -f1)
# Get token counts from context_window
TOTAL_TOKENS=$(echo "$input" | jq -r '
.context_window.current_usage
| if . then
(.input_tokens // 0) + (.output_tokens // 0)
+ (.cache_creation_input_tokens // 0) + (.cache_read_input_tokens // 0)
else 0 end
')
# Get current git branch
BRANCH=""
if command -v git &>/dev/null; then
BRANCH=$(git -C "$DIR" rev-parse --abbrev-ref HEAD 2>/dev/null)
fi
# Format token display
if [ "$TOTAL_TOKENS" -ge 1000000 ]; then
TOKEN_DISPLAY="$(awk "BEGIN {printf \"%.1f\", $TOTAL_TOKENS/1000000}")M"
elif [ "$TOTAL_TOKENS" -ge 1000 ]; then
TOKEN_DISPLAY="$(awk "BEGIN {printf \"%.1f\", $TOTAL_TOKENS/1000}")K"
else
TOKEN_DISPLAY="$TOTAL_TOKENS"
fi
# Colors
GREEN='\033[32m'; YELLOW='\033[33m'; RED='\033[31m'; RESET='\033[0m'
# Color coding for percentage
if [ "$PCT" -ge 90 ]; then
COLOR="$RED"
elif [ "$PCT" -ge 70 ]; then
COLOR="$YELLOW"
else
COLOR="$GREEN"
fi
# Build status line
BRANCH_PART=""
[ -n "$BRANCH" ] && BRANCH_PART=" | 🌿 $BRANCH"
printf "[%s] 📁 %s%s | 🪙 %s | ${COLOR}%s%%${RESET}\n" \
"$MODEL" "${DIR##*/}" "$BRANCH_PART" "$TOKEN_DISPLAY" "$PCT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment