Skip to content

Instantly share code, notes, and snippets.

@dguerizec
Created February 19, 2026 23:17
Show Gist options
  • Select an option

  • Save dguerizec/7f34f5c7895cafb08699870c45f30485 to your computer and use it in GitHub Desktop.

Select an option

Save dguerizec/7f34f5c7895cafb08699870c45f30485 to your computer and use it in GitHub Desktop.
claude-usage
#!/usr/bin/env bash
set -euo pipefail
CREDENTIALS_FILE="${HOME}/.claude/.credentials.json"
if [[ ! -f "$CREDENTIALS_FILE" ]]; then
echo "Error: credentials file not found: $CREDENTIALS_FILE" >&2
exit 1
fi
ACCESS_TOKEN=$(jq -r '.claudeAiOauth.accessToken // empty' "$CREDENTIALS_FILE")
if [[ -z "$ACCESS_TOKEN" ]]; then
echo "Error: no OAuth access token found in $CREDENTIALS_FILE" >&2
exit 1
fi
curl -sf \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${ACCESS_TOKEN}" \
-H "anthropic-beta: oauth-2025-04-20" \
-H "User-Agent: claude-code/2.1.34" \
"https://api.anthropic.com/api/oauth/usage" | jq .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment