Skip to content

Instantly share code, notes, and snippets.

@zepgram
Last active January 31, 2026 22:55
Show Gist options
  • Select an option

  • Save zepgram/9d5d136301fa949a5d0a11879d403f29 to your computer and use it in GitHub Desktop.

Select an option

Save zepgram/9d5d136301fa949a5d0a11879d403f29 to your computer and use it in GitHub Desktop.
Claude Code Command Center - Custom Status Line (works in any terminal)
#!/bin/bash
# Command Center - Claude Status Line
input=$(cat)
MODEL=$(echo "$input" | jq -r '.model.display_name // "CLAUDE"' | tr '[:lower:]' '[:upper:]')
# Context calculation based on 90% usable space (auto-compact threshold)
USED_PERCENT=$(echo "$input" | jq -r '.context_window.used_percentage // 0')
USED_INT=${USED_PERCENT%.*}
# Real percentage: how much of the usable 90% is consumed
# At 82% used -> 82/90 = 91% of usable space consumed
# At 90% used -> 90/90 = 100% (auto-compact triggers)
REAL_PERCENT=$((USED_INT * 100 / 90))
[ "$REAL_PERCENT" -gt 100 ] && REAL_PERCENT=100
# Remaining until auto-compact (what matters operationally)
REMAINING=$((90 - USED_INT))
[ "$REMAINING" -lt 0 ] && REMAINING=0
IN_TOKENS=$(echo "$input" | jq -r '.context_window.total_input_tokens // 0')
OUT_TOKENS=$(echo "$input" | jq -r '.context_window.total_output_tokens // 0')
COST=$(echo "$input" | jq -r '.cost.total_cost_usd // 0')
DURATION_MS=$(echo "$input" | jq -r '.cost.total_duration_ms // 0')
API_DURATION_MS=$(echo "$input" | jq -r '.cost.total_api_duration_ms // 0')
PROJECT_DIR=$(echo "$input" | jq -r '.workspace.project_dir // .cwd // ""')
SESSION_ID=$(echo "$input" | jq -r '.session_id // "default"')
# Track previous API duration to calculate last request latency
STATE_FILE="/tmp/claude-statusline-${SESSION_ID}"
PREV_API_MS=0
LAST_LATENCY=0
if [ -f "$STATE_FILE" ]; then
PREV_API_MS=$(sed -n '1p' "$STATE_FILE" 2>/dev/null || echo "0")
LAST_LATENCY=$(sed -n '2p' "$STATE_FILE" 2>/dev/null || echo "0")
fi
# Calculate delta (last request latency)
if [ "$API_DURATION_MS" -gt "$PREV_API_MS" ]; then
LAST_LATENCY=$((API_DURATION_MS - PREV_API_MS))
fi
# Save current state
echo -e "${API_DURATION_MS}\n${LAST_LATENCY}" > "$STATE_FILE"
STATUS="◆"
# Format tokens
format_tokens() {
local n=$1
if [ "$n" -ge 1000000 ]; then
echo "$((n / 1000000))M"
elif [ "$n" -ge 1000 ]; then
echo "$((n / 1000))K"
else
echo "$n"
fi
}
# Format duration (ms to human readable)
format_duration() {
local ms=$1
local secs=$((ms / 1000))
if [ "$secs" -ge 3600 ]; then
echo "$((secs / 3600))h$((secs % 3600 / 60))m"
elif [ "$secs" -ge 60 ]; then
echo "$((secs / 60))m"
else
echo "${secs}s"
fi
}
# Format API latency
format_latency() {
local ms=$1
if [ "$ms" -ge 1000 ]; then
printf "%.1fs" "$(echo "scale=1; $ms / 1000" | bc)"
else
echo "${ms}ms"
fi
}
IN_FMT=$(format_tokens "$IN_TOKENS")
OUT_FMT=$(format_tokens "$OUT_TOKENS")
COST_FMT=$(printf "%.2f" "$COST")
DURATION_FMT=$(format_duration "$DURATION_MS")
LATENCY_FMT=$(format_latency "$LAST_LATENCY")
# Shorten project dir to last folder name
PROJECT_NAME=$(basename "$PROJECT_DIR")
# Context bar (visual representation based on real usable space)
BAR_LEN=10
FILLED=$((REAL_PERCENT * BAR_LEN / 100))
EMPTY=$((BAR_LEN - FILLED))
BAR=""
for ((i=0; i<FILLED; i++)); do BAR+="▰"; done
for ((i=0; i<EMPTY; i++)); do BAR+="▱"; done
echo "${STATUS} ${MODEL} 📁 ${PROJECT_NAME} │ ${BAR} ${REAL_PERCENT}% ↓${IN_FMT} ↑${OUT_FMT} │ ⏱ ${DURATION_FMT} ⚡${LATENCY_FMT} │ \$${COST_FMT}"
@zepgram
Copy link
Author

zepgram commented Jan 31, 2026

Capture d’écran 2026-01-31 à 19 20 42

@zepgram
Copy link
Author

zepgram commented Jan 31, 2026

  1. Download the script to ~/.claude/statusline.sh
  2. Make it executable: chmod +x ~/.claude/statusline.sh
  3. Add to ~/.claude/settings.json:
  "statusLine": {
    "type": "command",
    "command": "~/.claude/statusline.sh"
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment