Skip to content

Instantly share code, notes, and snippets.

@vildanbina
Last active February 28, 2026 19:46
Show Gist options
  • Select an option

  • Save vildanbina/af6b1186fa529093bdd5d61bdf6d7b33 to your computer and use it in GitHub Desktop.

Select an option

Save vildanbina/af6b1186fa529093bdd5d61bdf6d7b33 to your computer and use it in GitHub Desktop.
Show 5h/7d API usage in your terminal statusline

CC Usage Statusline

Shows your 5-hour and 7-day API usage limits in your terminal statusline.

5h: 42% | 7d: 23%

No more guessing how much capacity you have left.

Install

curl -o ~/.local/bin/cc-usage-statusline.sh \
  https://gist.githubusercontent.com/vildanbina/af6b1186fa529093bdd5d61bdf6d7b33/raw/cc-usage-statusline.sh
chmod +x ~/.local/bin/cc-usage-statusline.sh

Requires jq and curl.

Usage

Add to your statusline (tmux, starship, polybar, waybar, etc.):

~/.local/bin/cc-usage-statusline.sh

Caches results for 1 minute.

#!/bin/bash
#
# Show 5h + 7d API usage limits in your statusline
#
set -euo pipefail
CACHE="$HOME/.cache/cc-usage.txt"
LOCK="$HOME/.cache/cc-usage.lock"
CREDS="${CC_CREDENTIALS:-$HOME/.claude/.credentials.json}"
TTL="${CC_CACHE_TTL:-60}"
# Return cached if fresh
if [[ -f "$CACHE" ]]; then
age=$(($(date +%s) - $(stat -c '%Y' "$CACHE" 2>/dev/null || echo 0)))
[[ $age -lt $TTL ]] && cat "$CACHE" && exit 0
fi
# Rate limit API calls
if [[ -f "$LOCK" ]]; then
age=$(($(date +%s) - $(stat -c '%Y' "$LOCK" 2>/dev/null || echo 0)))
[[ $age -lt 30 ]] && { [[ -f "$CACHE" ]] && cat "$CACHE"; exit 0; }
fi
touch "$LOCK"
# Get token
[[ ! -f "$CREDS" ]] && echo "[No creds]" && exit 1
token=$(jq -r '.claudeAiOauth.accessToken // empty' "$CREDS" 2>/dev/null)
[[ -z "$token" ]] && echo "[Bad token]" && exit 1
# Fetch usage
resp=$(curl -s --max-time 5 \
"https://api.anthropic.com/api/oauth/usage" \
-H "Authorization: Bearer $token" \
-H "anthropic-beta: oauth-2025-04-20" 2>/dev/null) || true
[[ -z "$resp" ]] && { [[ -f "$CACHE" ]] && cat "$CACHE"; echo "[Timeout]"; exit 1; }
session=$(echo "$resp" | jq -r '.five_hour.utilization // empty' 2>/dev/null)
weekly=$(echo "$resp" | jq -r '.seven_day.utilization // empty' 2>/dev/null)
[[ -z "$session" || -z "$weekly" ]] && { [[ -f "$CACHE" ]] && cat "$CACHE"; echo "[Error]"; exit 1; }
echo "5h: ${session}% | 7d: ${weekly}%" | tee "$CACHE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment