|
#!/bin/bash |
|
# Claude Code status line: folder, git branch, model, context usage |
|
|
|
input=$(cat) |
|
|
|
cwd=$(printf '%s' "$input" | jq -r '.workspace.current_dir // .cwd // empty') |
|
[ -n "$cwd" ] || cwd=$PWD |
|
folder=$(basename "$cwd") |
|
|
|
branch=$(git -C "$cwd" --no-optional-locks branch --show-current 2>/dev/null) |
|
|
|
model=$(printf '%s' "$input" | jq -r '.model.display_name // empty') |
|
|
|
effort=$(printf '%s' "$input" | jq -r '.effort.level // empty') |
|
|
|
# "3% (32.3k)" — omitted entirely if the payload carries no context info. |
|
# NB: current_usage is an object of token subtotals; total_input_tokens is the scalar. |
|
ctx=$(printf '%s' "$input" | jq -r ' |
|
.context_window // {} |
|
| select(.used_percentage != null or .total_input_tokens != null) |
|
| [ (if .used_percentage != null then "\(.used_percentage | round)%" else empty end), |
|
(if .total_input_tokens != null then |
|
"(\(if .total_input_tokens >= 1000 then "\(.total_input_tokens / 100 | round / 10)k" |
|
else "\(.total_input_tokens)" end))" |
|
else empty end) ] |
|
| join(" ") |
|
') |
|
|
|
# folder (dim cyan) |
|
printf '\033[2;36m%s\033[0m' "$folder" |
|
|
|
# git branch (dim yellow), only if present |
|
if [ -n "$branch" ]; then |
|
printf ' \033[2;33m(%s)\033[0m' "$branch" |
|
fi |
|
|
|
# separator + model (dim magenta), with effort level in parens when present |
|
if [ -n "$model" ]; then |
|
if [ -n "$effort" ]; then |
|
printf ' \033[2m|\033[0m \033[2;35m%s\033[0m \033[2;35m(%s)\033[0m' "$model" "$effort" |
|
else |
|
printf ' \033[2m|\033[0m \033[2;35m%s\033[0m' "$model" |
|
fi |
|
fi |
|
|
|
# separator + context usage (dim white) |
|
if [ -n "$ctx" ]; then |
|
printf ' \033[2m|\033[0m \033[2mctx %s\033[0m' "$ctx" |
|
fi |
|
|
|
# rate limits: "[42%|68%]" (no prefix) — percentages colored green→yellow→red by usage |
|
pct_color() { awk '{if ($1 <= 50) print 32; else if ($1 <= 80) print 33; else print 31}' <<< "$1"; } |
|
|
|
f_pct=$(printf '%s' "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty') |
|
s_pct=$(printf '%s' "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty') |
|
|
|
if [ -n "$f_pct" ] || [ -n "$s_pct" ]; then |
|
f_color=$(pct_color "$f_pct") |
|
s_color=$(pct_color "$s_pct") |
|
printf ' \033[2m|\033[0m \033[2m[\033[0m' |
|
[ -n "$f_pct" ] && printf '\033[2;%dm%.0f%%\033[0m' "$f_color" "$f_pct" || printf '--%' |
|
printf '\033[2m|\033[0m' |
|
[ -n "$s_pct" ] && printf '\033[2;%dm%.0f%%\033[0m' "$s_color" "$s_pct" || printf '--%' |
|
printf '\033[2m]\033[0m' |
|
fi |
|
|
|
printf '\n' |