|
#!/bin/bash |
|
# Claude Code Status Line - similar to screenrc footer |
|
# Shows: [Model] Context% | tokens | +lines -lines | duration | branch | path | $cost |
|
|
|
input=$(cat) |
|
|
|
# Parse JSON input |
|
MODEL=$(echo "$input" | jq -r '.model.display_name // "Claude"') |
|
PERCENT=$(echo "$input" | jq -r '.context_window.used_percentage // 0' | xargs printf "%.0f") |
|
DIR=$(echo "$input" | jq -r '.workspace.current_dir // ""') |
|
COST=$(echo "$input" | jq -r '.cost.total_cost_usd // 0') |
|
INPUT_TOKENS=$(echo "$input" | jq -r '.context_window.total_input_tokens // 0') |
|
OUTPUT_TOKENS=$(echo "$input" | jq -r '.context_window.total_output_tokens // 0') |
|
CTX_SIZE=$(echo "$input" | jq -r '.context_window.context_window_size // 200000') |
|
LINES_ADDED=$(echo "$input" | jq -r '.cost.total_lines_added // 0') |
|
LINES_REMOVED=$(echo "$input" | jq -r '.cost.total_lines_removed // 0') |
|
DURATION_MS=$(echo "$input" | jq -r '.cost.total_duration_ms // 0') |
|
|
|
# Format token counts (K for thousands) |
|
format_tokens() { |
|
local num=$1 |
|
if [ "$num" -ge 1000 ]; then |
|
printf "%.1fK" "$(echo "scale=1; $num/1000" | bc)" |
|
else |
|
echo "$num" |
|
fi |
|
} |
|
|
|
# Format duration (ms to human readable) |
|
format_duration() { |
|
local ms=$1 |
|
local secs=$((ms / 1000)) |
|
local mins=$((secs / 60)) |
|
local hours=$((mins / 60)) |
|
mins=$((mins % 60)) |
|
secs=$((secs % 60)) |
|
|
|
if [ "$hours" -gt 0 ]; then |
|
printf "%dh%02dm" "$hours" "$mins" |
|
elif [ "$mins" -gt 0 ]; then |
|
printf "%dm%02ds" "$mins" "$secs" |
|
else |
|
printf "%ds" "$secs" |
|
fi |
|
} |
|
|
|
IN_FMT=$(format_tokens "$INPUT_TOKENS") |
|
OUT_FMT=$(format_tokens "$OUTPUT_TOKENS") |
|
CTX_FMT=$(format_tokens "$CTX_SIZE") |
|
DUR_FMT=$(format_duration "$DURATION_MS") |
|
|
|
# Get git branch if in a repo |
|
BRANCH="" |
|
if [ -n "$DIR" ] && [ -d "$DIR" ]; then |
|
BRANCH=$(git -C "$DIR" branch --show-current 2>/dev/null) |
|
fi |
|
|
|
# Shorten path for display (last 2 components) |
|
SHORT_PATH="" |
|
if [ -n "$DIR" ]; then |
|
SHORT_PATH=$(echo "$DIR" | rev | cut -d'/' -f1-2 | rev) |
|
fi |
|
|
|
# Format cost (only show if > $0.001) |
|
COST_STR="" |
|
if (( $(echo "$COST > 0.001" | bc -l) )); then |
|
COST_STR=$(printf "\$%.2f" "$COST") |
|
fi |
|
|
|
# ANSI colors |
|
CYAN='\033[0;36m' |
|
GREEN='\033[0;32m' |
|
YELLOW='\033[0;33m' |
|
MAGENTA='\033[0;35m' |
|
RED='\033[0;31m' |
|
BLUE='\033[0;34m' |
|
DIM='\033[2m' |
|
RESET='\033[0m' |
|
|
|
# Color context percentage based on usage |
|
if [ "$PERCENT" -lt 50 ]; then |
|
PCT_COLOR=$GREEN |
|
elif [ "$PERCENT" -lt 80 ]; then |
|
PCT_COLOR=$YELLOW |
|
else |
|
PCT_COLOR=$RED |
|
fi |
|
|
|
# Build output |
|
OUTPUT="${CYAN}[${MODEL}]${RESET}" |
|
OUTPUT="$OUTPUT ${PCT_COLOR}${PERCENT}%${RESET}" |
|
OUTPUT="$OUTPUT ${DIM}|${RESET} ${MAGENTA}↓${IN_FMT} ↑${OUT_FMT}${RESET}${DIM}/${CTX_FMT}${RESET}" |
|
OUTPUT="$OUTPUT ${DIM}|${RESET} ${GREEN}+${LINES_ADDED}${RESET} ${RED}-${LINES_REMOVED}${RESET}" |
|
OUTPUT="$OUTPUT ${DIM}|${RESET} ${DIM}${DUR_FMT}${RESET}" |
|
[ -n "$BRANCH" ] && OUTPUT="$OUTPUT ${DIM}|${RESET} ${GREEN}${BRANCH}${RESET}" |
|
[ -n "$SHORT_PATH" ] && OUTPUT="$OUTPUT ${DIM}|${RESET} ${BLUE}${SHORT_PATH}${RESET}" |
|
[ -n "$COST_STR" ] && OUTPUT="$OUTPUT ${DIM}|${RESET} ${YELLOW}${COST_STR}${RESET}" |
|
|
|
echo -e "$OUTPUT" |