Skip to content

Instantly share code, notes, and snippets.

@ray-amjad
Last active May 5, 2026 01:52
Show Gist options
  • Select an option

  • Save ray-amjad/8ae314578769ff2fb38cdd7bd283b2e9 to your computer and use it in GitHub Desktop.

Select an option

Save ray-amjad/8ae314578769ff2fb38cdd7bd283b2e9 to your computer and use it in GitHub Desktop.
Ray Amjad's Claude Code Statusline
#!/bin/sh
input=$(cat)
# Model name
model=$(echo "$input" | jq -r '.model.display_name // .model.id // "Unknown"')
# Context window usage - battery indicator
used_pct=$(echo "$input" | jq -r '.context_window.used_percentage // empty')
if [ -n "$used_pct" ]; then
used_int=$(printf "%.0f" "$used_pct")
# Battery is 10 blocks wide
filled=$(( used_int / 10 ))
empty=$(( 10 - filled ))
bar=""
i=0
while [ $i -lt $filled ]; do
bar="${bar}█"
i=$(( i + 1 ))
done
i=0
while [ $i -lt $empty ]; do
bar="${bar}░"
i=$(( i + 1 ))
done
context_display="[${bar}] ${used_int}%"
else
context_display="[░░░░░░░░░░] --%"
fi
# Git branch and unstaged changes
cwd=$(echo "$input" | jq -r '.cwd // .workspace.current_dir // ""')
git_info=""
if [ -n "$cwd" ]; then
branch=$(git -C "$cwd" --no-optional-locks rev-parse --abbrev-ref HEAD 2>/dev/null)
if [ -n "$branch" ]; then
unstaged=$(git -C "$cwd" --no-optional-locks diff --name-only 2>/dev/null | wc -l | tr -d ' ')
untracked=$(git -C "$cwd" --no-optional-locks ls-files --others --exclude-standard 2>/dev/null | wc -l | tr -d ' ')
git_info="${branch}"
[ "$unstaged" -gt 0 ] 2>/dev/null && git_info="${git_info} ~${unstaged}"
[ "$untracked" -gt 0 ] 2>/dev/null && git_info="${git_info} +${untracked}"
fi
fi
# Rate limits (Claude.ai subscription) — clock-style with "in Xh" countdown
# Try several field-name conventions in case Claude Code uses snake_case or camelCase
five_pct=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // .rate_limits.fiveHour.used_percentage // empty')
five_at=$(echo "$input" | jq -r '.rate_limits.five_hour.resets_at // .rate_limits.five_hour.resetsAt // .rate_limits.fiveHour.resets_at // .rate_limits.fiveHour.resetsAt // empty')
week_pct=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // .rate_limits.sevenDay.used_percentage // empty')
week_at=$(echo "$input" | jq -r '.rate_limits.seven_day.resets_at // .rate_limits.seven_day.resetsAt // .rate_limits.sevenDay.resets_at // .rate_limits.sevenDay.resetsAt // empty')
# Debug: drop the rate_limits subtree to /tmp so we can inspect the raw shape
echo "$input" | jq '.rate_limits // null' > /tmp/statusline-rate-debug.json 2>/dev/null
# Convert reset timestamp to a short countdown like "3h" / "45m" / "5d".
# Accepts ISO 8601 (with/without fractional seconds, with Z or +HH:MM offset)
# OR a Unix epoch in seconds OR milliseconds.
fmt_until() {
ts="$1"
scale="$2" # "hours" (sub-day) or "days" (sub-week)
[ -z "$ts" ] || [ "$ts" = "null" ] && return
reset_epoch=""
# Numeric? assume epoch (seconds or ms)
case "$ts" in
''|*[!0-9]*) ;;
*)
if [ ${#ts} -ge 13 ]; then
reset_epoch=$(( ts / 1000 ))
else
reset_epoch="$ts"
fi
;;
esac
if [ -z "$reset_epoch" ]; then
# ISO 8601: strip fractional seconds and timezone suffix (treat as UTC)
clean=$(printf "%s" "$ts" | sed -E 's/\.[0-9]+//' | sed -E 's/(Z|[+-][0-9:]+)$//')
reset_epoch=$(date -j -u -f "%Y-%m-%dT%H:%M:%S" "$clean" "+%s" 2>/dev/null)
fi
[ -z "$reset_epoch" ] && return
now_epoch=$(date -u "+%s")
diff=$(( reset_epoch - now_epoch ))
[ $diff -lt 0 ] && diff=0
if [ "$scale" = "days" ]; then
# Round to nearest day; below 1d, fall through to nearest hour
days=$(( (diff + 43200) / 86400 ))
if [ $days -ge 1 ]; then
printf "%dd" "$days"
else
hours=$(( (diff + 1800) / 3600 ))
[ $hours -lt 1 ] && hours=1
printf "%dh" "$hours"
fi
else
# Round to nearest hour; below 1h, fall through to nearest minute
hours=$(( (diff + 1800) / 3600 ))
if [ $hours -ge 1 ]; then
printf "%dh" "$hours"
else
mins=$(( (diff + 30) / 60 ))
[ $mins -lt 1 ] && mins=1
printf "%dm" "$mins"
fi
fi
}
rate_display=""
if [ -n "$five_pct" ]; then
five_int=$(printf "%.0f" "$five_pct")
five_until=$(fmt_until "$five_at" "hours")
if [ -n "$five_until" ]; then
rate_display="⏱ ${five_int}% (in ${five_until})"
else
rate_display="⏱ ${five_int}%"
fi
fi
if [ -n "$week_pct" ]; then
week_int=$(printf "%.0f" "$week_pct")
week_until=$(fmt_until "$week_at" "days")
if [ -n "$week_until" ]; then
week_seg="${week_int}% (in ${week_until})"
else
week_seg="${week_int}%"
fi
if [ -n "$rate_display" ]; then
rate_display="${rate_display} · ${week_seg}"
else
rate_display="⏱ ${week_seg}"
fi
fi
# Assemble status line
parts="${model} | ${context_display}"
[ -n "$git_info" ] && parts="${parts} | ${git_info}"
[ -n "$rate_display" ] && parts="${parts} | ${rate_display}"
printf "%s" "$parts"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment