Skip to content

Instantly share code, notes, and snippets.

@pmatos
Created February 11, 2026 09:23
Show Gist options
  • Select an option

  • Save pmatos/70f18d396f8e21804f8a437184de1292 to your computer and use it in GitHub Desktop.

Select an option

Save pmatos/70f18d396f8e21804f8a437184de1292 to your computer and use it in GitHub Desktop.
Waybar custom module: Claude Code session and weekly API usage
#!/bin/bash
TOKEN=$(jq -r '.claudeAiOauth.accessToken' ~/.claude/.credentials.json 2>/dev/null)
if [ -z "$TOKEN" ] || [ "$TOKEN" = "null" ]; then
echo '{"text": "CC: --", "tooltip": "Claude Code: no credentials", "class": "claude-error"}'
exit 0
fi
USAGE=$(curl -sf \
-H "Accept: application/json" \
-H "Authorization: Bearer $TOKEN" \
-H "anthropic-beta: oauth-2025-04-20" \
"https://api.anthropic.com/api/oauth/usage" 2>/dev/null)
if [ -z "$USAGE" ]; then
echo '{"text": "CC: --", "tooltip": "Claude Code: API error", "class": "claude-error"}'
exit 0
fi
SESSION=$(echo "$USAGE" | jq -r '.five_hour.utilization // "?"')
WEEKLY=$(echo "$USAGE" | jq -r '.seven_day.utilization // "?"')
SESSION_RESET=$(echo "$USAGE" | jq -r '.five_hour.resets_at // ""' | xargs -I{} date -d {} '+%H:%M' 2>/dev/null)
WEEKLY_RESET=$(echo "$USAGE" | jq -r '.seven_day.resets_at // ""' | xargs -I{} date -d {} '+%b %d, %H:%M' 2>/dev/null)
CLASS="claude"
SESSION_INT=${SESSION%.*}
if [ "$SESSION_INT" -ge 80 ] 2>/dev/null; then
CLASS="claude-high"
elif [ "$SESSION_INT" -ge 50 ] 2>/dev/null; then
CLASS="claude-mid"
fi
TOOLTIP="Session: ${SESSION}% (resets ${SESSION_RESET})\nWeek: ${WEEKLY}% (resets ${WEEKLY_RESET})"
echo "{\"text\": \"Session: ${SESSION}% | Week: ${WEEKLY}%\", \"tooltip\": \"${TOOLTIP}\", \"class\": \"${CLASS}\"}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment