Created
February 11, 2026 09:23
-
-
Save pmatos/70f18d396f8e21804f8a437184de1292 to your computer and use it in GitHub Desktop.
Waybar custom module: Claude Code session and weekly API usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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