Skip to content

Instantly share code, notes, and snippets.

@dannguyen
Last active April 24, 2026 21:07
Show Gist options
  • Select an option

  • Save dannguyen/8b422aeba238025c18013b7311d6c809 to your computer and use it in GitHub Desktop.

Select an option

Save dannguyen/8b422aeba238025c18013b7311d6c809 to your computer and use it in GitHub Desktop.
Claude statusline.sh to dynamically show Claude usage stats, including % remaining and next refresh window

Adding Usage/Quota status bar to Claude Code CLI

image

To add a dynamic usage status bar to Claude Code CLI:

Create ~/.claude/statusline-command.sh

Make it executable:

chmod +x ~/.claude/statusline-command.sh                                    

In settings.json, add:

  "statusLine": {
    "type": "command",
    "command": "sh /Users/yourname/.claude/statusline-command.sh"
  }
#!/bin/sh
input=$(cat)
cwd=$(echo "$input" | jq -r '.cwd')
# Compute last 2 path components (mimics zsh %2d)
last2=$(echo "$cwd" | awk -F'/' '{
n=NF
if (n >= 2) print $(n-1) "/" $n
else print $n
}')
# Pro/Max plan usage — only present after first API response in session
five_hour=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
five_hour_reset=$(echo "$input" | jq -r '.rate_limits.five_hour.resets_at // empty')
seven_day=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty')
seven_day_reset=$(echo "$input" | jq -r '.rate_limits.seven_day.resets_at // empty')
# ANSI colors
BLUE='\033[34m'
YELLOW='\033[33m'
WHITE='\033[37m'
DIM='\033[2m'
GREEN='\033[32m'
RED='\033[31m'
RESET='\033[0m'
PURPLE='\033[35m'
BOLDLABEL='\e[1;35m'
BOLDWHITE='\e[1;37m'
# Pick a color based on usage percentage
usage_color() {
pct=$1
# strip decimals for integer comparison
int_pct=${pct%.*}
if [ "$int_pct" -ge 80 ] 2>/dev/null; then
printf "$RED"
elif [ "$int_pct" -ge 50 ] 2>/dev/null; then
printf "$YELLOW"
else
printf "$GREEN"
fi
}
usage_segment=""
if [ -n "$five_hour" ] || [ -n "$seven_day" ]; then
usage_segment=" ${DIM}${RESET}"
if [ -n "$five_hour" ]; then
c=$(usage_color "$five_hour")
usage_segment="${usage_segment} ${PURPLE}5HR${RESET} [${c}$(printf '%.0f' "$five_hour")%%${RESET}]"
if [ -n "$five_hour_reset" ]; then
reset_time=$(date -r "$five_hour_reset" "+%H:%M %Z" 2>/dev/null || date -d "@$five_hour_reset" "+%H:%M %Z" 2>/dev/null)
usage_segment="${usage_segment} ${GREEN}${WHITE}${reset_time}${RESET}"
fi
fi
if [ -n "$seven_day" ]; then
c=$(usage_color "$seven_day")
usage_segment="${usage_segment} | ${PURPLE}7DAY${RESET} [${c}$(printf '%.0f' "$seven_day")%%${RESET}]"
if [ -n "$seven_day_reset" ]; then
reset_datetime=$(date -r "$seven_day_reset" "+%a %H:%M %Z" 2>/dev/null || date -d "@$seven_day_reset" "+%a %H:%M %Z" 2>/dev/null)
usage_segment="${usage_segment} ${GREEN}${WHITE}${reset_datetime}${RESET}"
fi
fi
fi
printf "${BLUE}pwd: ${YELLOW}${last2}${RESET}${usage_segment}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment