#!/bin/bash # Context percentage progress bar for ccstatusline custom-command widget # Receives Claude Code JSON via stdin input=$(cat) if ! command -v jq >/dev/null 2>&1; then echo "Ctx: ?" exit 0 fi # Extract context window info CTX_SIZE=$(echo "$input" | jq -r '.context_window.context_window_size // 200000') USAGE=$(echo "$input" | jq '.context_window.current_usage // null') if [ "$USAGE" = "null" ] || [ -z "$USAGE" ]; then echo "Ctx: --" exit 0 fi CURRENT=$(echo "$USAGE" | jq '(.input_tokens // 0) + (.cache_creation_input_tokens // 0) + (.cache_read_input_tokens // 0)') # Usable = 80% of max (auto-compact threshold) USABLE=$(( CTX_SIZE * 80 / 100 )) USED_PCT=$(( CURRENT * 100 / USABLE )) [ "$USED_PCT" -lt 0 ] && USED_PCT=0 [ "$USED_PCT" -gt 100 ] && USED_PCT=100 # Build progress bar (width=12) - fills up as usage increases W=12 FILLED=$(( USED_PCT * W / 100 )) EMPTY=$(( W - FILLED )) BAR=$(printf '%*s' "$FILLED" '' | tr ' ' '█')$(printf '%*s' "$EMPTY" '' | tr ' ' '░') printf '%s %s%%' "[$BAR]" "$USED_PCT"