Skip to content

Oauth usage endpoint#39

Open
BrianPugh wants to merge 3 commits into
HermannBjorgvin:mainfrom
BrianPugh:oauth-usage-endpoint
Open

Oauth usage endpoint#39
BrianPugh wants to merge 3 commits into
HermannBjorgvin:mainfrom
BrianPugh:oauth-usage-endpoint

Conversation

@BrianPugh

Copy link
Copy Markdown
Contributor

Revamp of #37. Changes from #37:

  1. Add exponential backoff up to 5min period. This solves the previous "retry every 5 seconds" bug/bad-behavior.
  2. Add a new optional err field to the BLE payload. If supplied, the string will be displayed instead of anim_messages.

So here are my findings on the rate-limiting behavior:

  1. After not using ClaudeCode for serveral hours, your authentication credentials expire and you begin getting 401 Auth errors.
  2. After several authentication errors (even with 5min period), you will get 429 rate-limit-errors.
  3. After you send a ClaudeCode message, ClaudeCode will renew your credentials, and the 401/429 Errors go away and everything works expected.

So ultimately, in real workflows, the rate-limiting-errors aren't really an issue. It would be nice to somehow detect when we send our first message in a while to instantly update usage (instead of up to 5min of stale data for the initial successful usage poll).

BrianPugh added 3 commits May 24, 2026 16:14


Main had reverted PR HermannBjorgvin#29 (commit 1218454) so this branch could be
re-investigated. Branch now contains the original /api/oauth/usage
change plus follow-ups a5b5708 (exponential backoff) and 1cbc747
(daemon→device error passing). Conflict resolution keeps HEAD's
oauth version for daemon/claude-usage-daemon.sh,
daemon/claude_usage_daemon.py, and install.sh, restoring the
reverted change. README updates from main are picked up as-is.
@HermannBjorgvin

Copy link
Copy Markdown
Owner

Me and @tobby168 had some similar discussions in #32

I think maybe it is a related topic, since credentials expiring was also a concern there.

There is one quirk about using Claude Code to refresh the credentials and that is that it starts a new 5 hour session for the user which they might not want since a lot of people including me and my coworker have specific times when it works best for us to start a new 5 hour window.

Not sure what the best solution is here to be honest. Is the 5 minute window too broad or is it fine?

Should we leverage hooks maybe to see a session start event and start fetching usage data at that point for x number of hours?

@BrianPugh

Copy link
Copy Markdown
Contributor Author

Not sure what the best solution is here to be honest. Is the 5 minute window too broad or is it fine?

For me, the initial up-to-5-minute-delay is totally fine. I'm not really concerned about my usage within the first 5 minutes of my session 😛 . That said, it would be nicer to have a more reactive solution.

Should we leverage hooks maybe to see a session start event and start fetching usage data at that point for x number of hours?

I think this would be great. Maybe use watchfiles or something? I imagine ClaudeCode updates some file in the ~/.claude directory whenever actually running.

@HermannBjorgvin

Copy link
Copy Markdown
Owner

Yeah wondering what the best non-invasive way to do this is.

Perhaps changing the polling to ~5 minute intervals is best, right now it's polling every minute and storing the usage stats for the past 5 polls and using that to calculate the rate and displaying different splash screens based on that.

I like this way better indeed, can you tell me how does the splash animations work now did you update the rate calculations to account for the new time intervals?

@BrianPugh

Copy link
Copy Markdown
Contributor Author

Perhaps changing the polling to ~5 minute intervals is best

I worry this would be too sluggish, especially for Pro ($20) users. I think the 1min interval is fine, no actual limiting happens during real sessions.

did you update the rate calculations to account for the new time intervals?

I didn't touch any of that calculation since the normal operating rate is still the default 60s

@niradler

Copy link
Copy Markdown

@HermannBjorgvin

Copy link
Copy Markdown
Owner

what about this https://github.com/anthropics/claude-desktop-buddy/blob/main/REFERENCE.md ?

Would work for Claude desktop users, doesn't give the 5h/7d window in the data that's sent over from what I can tell... maybe they could add it for us?

alasdaircs added a commit to alasdaircs/clawdmeter-wifi that referenced this pull request Jun 8, 2026
…Bjorgvin#39 resilience)

Port the endpoint-independent resilience work from upstream PR HermannBjorgvin#39 onto our
existing /v1/messages poll path. The PR's headline change — switching to the
zero-token GET /api/oauth/usage endpoint — was evaluated and rejected: that
endpoint needs an OAuth token with broader scope than the 1-year
`claude setup token` the device is provisioned with, so it returns HTTP 403.
Confirmed empirically (setup token -> 403, full-scope claudeAiOauth token ->
200, garbage -> 401, proving 403 is a scope issue not expiry). A scope-limited
long-lived token and a usage-scoped short-lived token are mutually exclusive
for an always-on device, so we stay on /v1/messages.

Kept from HermannBjorgvin#39 (all endpoint-independent):
- Exponential backoff on consecutive poll failures (60s -> 5min cap) on a
  counter separate from the Wi-Fi-connect counter, so a rate-limited API can't
  trip the captive-portal fallback. Cuts TLS-handshake heap churn during
  outages (SRAM is tight with NimBLE + HTTPS).
- Error categorisation: 429 -> WIFI_POLL_RATE_LIMITED ("Rate limited"),
  5xx -> WIFI_POLL_API_DOWN ("Anthropic API down").
- 401 now retries 3x with backoff before stopping, to ride out Anthropic
  auth-server wobbles rather than stopping on the first 401.

WIFI_FORK.md documents the scope finding ("Why not /api/oauth/usage?") and the
new error states. Verified on device: HTTP 200, s/w/status/reset parsed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants