Skip to content

Instantly share code, notes, and snippets.

@kenji4569
Last active August 1, 2026 21:30
Show Gist options
  • Select an option

  • Save kenji4569/cc4fe8add6af41f82c1d9ec36d1f6454 to your computer and use it in GitHub Desktop.

Select an option

Save kenji4569/cc4fe8add6af41f82c1d9ec36d1f6454 to your computer and use it in GitHub Desktop.
A shell script that renders a colorized Claude Code status line showing the current directory, Git status, model, cost, execution time, context usage, and subscription rate limits.
#!/bin/sh
# Claude Code statusLine script
# Mirrors ~/.zshrc PROMPT configuration
input=$(cat)
cwd=$(echo "$input" | jq -r '.cwd')
MODEL_NAME=$(echo "$input" | jq -r '.model.display_name')
TOTAL_COST=$(echo "$input" | jq -r '.cost.total_cost_usd')
TOTAL_DURATION=$(echo "$input" | jq -r '.cost.total_duration_ms')
TOTAL_API_DURATION=$(echo "$input" | jq -r '.cost.total_api_duration_ms')
USED_PCT=$(echo "$input" | jq -r '.context_window.used_percentage')
# Subscription rate limits: .rate_limits is only present when logged in with a
# subscription account (absent for API-key auth), so "// empty" doubles as the gate.
RATE_LIMITS=$(echo "$input" | jq -r '[(.rate_limits.five_hour.used_percentage // ""), (.rate_limits.five_hour.resets_at // ""), (.rate_limits.seven_day.used_percentage // ""), (.rate_limits.seven_day.resets_at // "")] | @tsv')
LIMIT_5H=$(echo "$RATE_LIMITS" | cut -f1)
RESET_5H=$(echo "$RATE_LIMITS" | cut -f2)
LIMIT_7D=$(echo "$RATE_LIMITS" | cut -f3)
RESET_7D=$(echo "$RATE_LIMITS" | cut -f4)
# Color codes
RESET='\033[0m'
MAGENTA='\033[35m'
BLUE='\033[34m'
YELLOW='\033[33m'
RED='\033[31m'
CYAN='\033[36m'
GRAY='\033[90m'
SILVER='\033[38;2;205;214;244m'
SAGE='\033[38;2;122;158;122m'
# Branch colors: brighter (pastel) + bold so the branch stands out from the rest
BRANCH_CLEAN='\033[1;38;2;137;180;250m'
BRANCH_UNTRACKED='\033[1;38;2;249;226;175m'
BRANCH_MODIFIED='\033[1;38;2;243;139;168m'
BRANCH_ADDED='\033[1;38;2;148;226;213m'
# Display current directory
cwd_display=$(echo "$cwd" | sed "s|^$HOME|~|")
printf "${SILVER}%s${RESET}" "$cwd_display"
# Git branch status (mirrors branch-status-check / get-branch-status)
if ! echo "$cwd" | grep -qE '/\.git(/.*)?$'; then
branchname=$(git -C "$cwd" rev-parse --abbrev-ref HEAD 2>/dev/null)
if [ -n "$branchname" ]; then
output=$(git -C "$cwd" --no-optional-locks status --short 2>/dev/null)
if [ -z "$output" ]; then
color="$BRANCH_CLEAN"
res=":"
elif echo "$output" | grep -qE '^\?\? '; then
color="$BRANCH_UNTRACKED"
res="?:"
elif echo "$output" | grep -qE '^ M '; then
color="$BRANCH_MODIFIED"
res="M:"
else
color="$BRANCH_ADDED"
res="A:"
fi
printf " ${color}${res}${branchname}${RESET}"
fi
fi
printf "${RESET}\n"
# Format cost, durations, context usage and token counts compactly
fmt_duration() {
awk -v ms="$1" 'BEGIN{s=(ms+0)/1000; m=int(s/60); s=int(s)%60; if (m>0) printf "%dm%02ds", m, s; else printf "%ds", s}'
}
cost_fmt=$(awk -v c="$TOTAL_COST" 'BEGIN{printf "$%.2f", c+0}')
api_dur_fmt=$(fmt_duration "$TOTAL_API_DURATION")
dur_fmt=$(fmt_duration "$TOTAL_DURATION")
pct_fmt=$(awk -v p="$USED_PCT" 'BEGIN{printf "%.0f%%", p+0}')
printf " ${CYAN}%s${RESET} ${GRAY}|${RESET} ${YELLOW}%s${RESET} ${GRAY}|${RESET} ${MAGENTA}ctx %s${RESET} ${GRAY}|${RESET} %s / %s" \
"$MODEL_NAME" "$cost_fmt" "$pct_fmt" "$api_dur_fmt" "$dur_fmt"
# Subscription usage (only rendered when the account exposes rate limits)
limit_color() {
awk -v p="$1" 'BEGIN{p+=0; if (p>=90) printf "\033[31m"; else if (p>=70) printf "\033[33m"; else printf "\033[32m"}'
}
# resets_at is a Unix timestamp in seconds -> "43m" / "2h13m" / "3d5h"
fmt_reset() {
[ -n "$1" ] || return 0
awk -v t="$1" -v now="$(date +%s)" 'BEGIN{
d=t-now; if (d<0) d=0;
h=int(d/3600); m=int((d%3600)/60);
if (h>=24) printf " (%dd%dh)", int(h/24), h%24;
else if (h>0) printf " (%dh%02dm)", h, m;
else printf " (%dm)", m
}'
}
fmt_limit() {
printf "%s%s${RESET}${SAGE}%s${RESET}" \
"$(limit_color "$1")" "$(awk -v p="$1" 'BEGIN{printf "%.0f%%", p+0}')" "$(fmt_reset "$2")"
}
if [ -n "$LIMIT_5H" ] && [ -n "$LIMIT_7D" ]; then
printf " ${GRAY}|${RESET} %s ${GRAY}/${RESET} %s" \
"$(fmt_limit "$LIMIT_5H" "$RESET_5H")" "$(fmt_limit "$LIMIT_7D" "$RESET_7D")"
elif [ -n "$LIMIT_5H" ]; then
printf " ${GRAY}|${RESET} %s" "$(fmt_limit "$LIMIT_5H" "$RESET_5H")"
elif [ -n "$LIMIT_7D" ]; then
printf " ${GRAY}|${RESET} %s" "$(fmt_limit "$LIMIT_7D" "$RESET_7D")"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment