fix(terra): surface Claude usage errors and retry sooner

The CLD panel went blank with no reason when Claude Code's saved OAuth
token had expired and the widget's own renewal was refused.

- Collapsed panel shows EXPIRED/ERR instead of dashes; failures are
  logged to `qs log`.
- Retry every minute after a failure instead of every 5.
- claude-usage identifies as claude-cli, the suspected cause of the
  refresh 429s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-30 21:21:20 +02:00
co-authored by Claude Opus 5.5
parent c33d184228
commit bee9b49ce1
4 changed files with 47 additions and 6 deletions
+6 -2
View File
@@ -7,6 +7,10 @@ fail() {
[ -r "$creds" ] || fail "not logged in"
# Identify as Claude Code: the suspected cause of refreshes failing with 429.
version="$(claude --version 2>/dev/null | cut -d" " -f1)" || true
ua="claude-cli/${version:-2.1.0} (external, cli)"
# The refresh token rotates, so the new one must be written back or the CLI's
# next refresh fails and forces a re-login.
refresh() {
@@ -20,7 +24,7 @@ refresh() {
client_id: "9d1c250a-e61b-44d9-88ed-5944d1962f5e", scope: $s}' \
| curl -s -m 20 -o "$body" -w '%{http_code}' \
https://platform.claude.com/v1/oauth/token \
-H 'Content-Type: application/json' --data-binary @-)" || code=000
-H 'Content-Type: application/json' -A "$ua" --data-binary @-)" || code=000
if [ "$code" != 200 ]; then
rm -f "$body"
fail "token refresh HTTP $code"
@@ -51,7 +55,7 @@ token="$(jq -r '.claudeAiOauth.accessToken // empty' "$creds")"
body="$(curl -s -m 20 -w '\n%{http_code}' https://api.anthropic.com/api/oauth/usage \
-H "Authorization: Bearer $token" \
-H 'anthropic-beta: oauth-2025-04-20')" || fail "usage request failed"
-H 'anthropic-beta: oauth-2025-04-20' -A "$ua")" || fail "usage request failed"
code="${body##*$'\n'}"
[ "$code" = 200 ] || fail "usage HTTP $code"
printf '%s' "${body%$'\n'*}" | jq -c . || fail "bad usage response"