Repository navigation
Anthropic Claude Pro/Max OAuth login fails with 429 on token exchange #18329
Description
Description
opencode auth login -p anthropic -m "Claude Pro/Max" consistently fails during the OAuth code exchange step with 429 Too Many Requests from https://console.anthropic.com/v1/oauth/token.
This is not just a generic Failed to authorize UI problem; with local debug logging enabled in the Anthropic auth plugin, the underlying failure is:
[opencode-anthropic-auth] OAuth exchange failed: status=429 statusText=Too Many Requests headers={...} body={
"error": {
"type": "rate_limit_error",
"message": "Rate limited. Please try again later."
}
}
I can reproduce this across multiple Anthropic accounts, which makes it look more like a flow-level / client-level / IP-level throttle than an account-specific Max-plan problem.
Environment
- OpenCode version:
1.2.20 - OS: macOS
- Provider:
anthropic - Login method:
Claude Pro/Max
Steps to reproduce
- Run:
opencode auth login -p anthropic -m "Claude Pro/Max" --print-logs --log-level DEBUG - Open the provided
claude.ai/oauth/authorizeURL in the browser. - Complete login successfully in Claude.
- Paste the returned authorization code back into OpenCode.
- Observe
Failed to authorize.
What is happening underneath
The browser authorization step succeeds and returns a code.
The failure happens on the follow-up token exchange to:
POST https://console.anthropic.com/v1/oauth/token
The plugin currently collapses that HTTP failure into a generic Failed to authorize message.
Related behavior
Earlier in the same session, Anthropic OAuth refresh was also failing for prompt traffic with:
Error: Token refresh failed: 429
So both fresh login and refresh appear to be failing on the Anthropic OAuth/token path.
Notes
- Anthropic status page was nominal at the time.
- We also tested changing the outgoing
User-Agentfor Anthropic requests locally, but the 429 still occurred. - The response did not include a
Retry-Afterheader or obvious Anthropic rate-limit reset metadata, only generic front-door headers.
Request
It would help a lot if OpenCode could:
- Surface the real OAuth exchange status/body instead of only
Failed to authorize. - Clarify whether this Anthropic OAuth flow is still supported / expected to work for Claude Pro/Max.
- Potentially make the Anthropic auth/user-agent behavior configurable for debugging.
If helpful, I can provide the exact debug patch used to expose the hidden exchange error.
Activity
github-actions commentedon Mar 20, 2026
This issue might be a duplicate of existing issues. Please check:
Please review those issues to see if your problem is already being tracked, and consider adding your findings there instead.
dotCipher commentedon Mar 20, 2026
Wrote a user agent configuration plugin to solve this actually, it did end up working: https://github.com/dotCipher/opencode-anthropic-user-agent-plugin
dotCipher commentedon Mar 20, 2026
Follow-up: I was able to work around this locally by changing the Anthropic-facing
User-Agent, and that resolved the login issue for me.So at least in my case, this does not appear to be a generic bad auth-code problem. It looks more like the Anthropic OAuth/token exchange path was sensitive to the client fingerprint / user-agent being sent by OpenCode on this flow.
What I observed:
claude.ai/oauth/authorizesucceededPOST https://console.anthropic.com/v1/oauth/tokenUser-Agent, the flow started workingI packaged the workaround as a small OpenCode plugin here:
This may help narrow the root cause:
User-Agentthat triggers throttling / rejection on Anthropic's token exchange path.User-Agentconfigurable for debugging.Failed to authorize.Nick-Hopps commentedon Mar 20, 2026
not work for me. btw the oAuth domain has changed to
platform.anthropic.comlehdqlsl commentedon Mar 20, 2026
I tried your user-agent plugin first — thanks for the detailed root cause analysis. In my case the OAuth flow itself was broken regardless of UA, so I took a different approach: syncing existing Claude CLI credentials directly into OpenCode's auth store, skipping the OAuth login entirely.
Not an npm package — plain shell scripts (~100 lines) you can audit before running. No supply chain risk.
Repo: https://github.com/lehdqlsl/opencode-claude-auth-sync
vinzabe commentedon Mar 20, 2026
here's the fix https://github.com/vinzabe/opencode-anthropic-oauth-fix
DerDummePunkt commentedon Mar 20, 2026
I'm not sure this will be fixed :/
#18186
JlMoreno00 commentedon Mar 20, 2026
Tested a working workaround on macOS with OpenCode 1.2.27 and Claude Code 2.1.80.
This does not fix the built-in Anthropic login flow itself, but it did restore Anthropic usage end-to-end here:
claude auth login --claudeai.opencode-claude-auth-sync:https://github.com/lehdqlsl/opencode-claude-auth-sync
Important detail: if the sync script reports
EXPIRED, syncing will not help. Refresh Claude CLI first, then sync again.After doing that, this worked:
opencode run --model anthropic/claude-sonnet-4-0 "Reply only with OK"Result:
OKSo the reliable workaround for me was: use Claude CLI as the source of truth for Anthropic OAuth, then sync those fresh credentials into OpenCode instead of relying on OpenCode's Anthropic login flow.
MoerAI commentedon Mar 20, 2026
Fix Available
The root cause of this 429 on token exchange has been identified and fixed in the
opencode-anthropic-authplugin:Two issues in
opencode-anthropic-authv0.0.13:Wrong
Content-Type: Token exchange and refresh requests useapplication/jsonwithJSON.stringify(), but Anthropic's/v1/oauth/tokenendpoint expectsapplication/x-www-form-urlencoded(per OAuth 2.0 RFC 6749 §4.1.3).Missing
User-Agentheader (primary cause of 429): The plugin setsUser-Agent: claude-cli/2.1.2 (external, cli)for API calls but omits it from token exchange/refresh requests. Anthropic's token endpoint rate-limits requests that don't match the expected Claude CLI request shape.PR with fix: ex-machina-co/opencode-anthropic-auth#12
After applying both changes,
opencode auth login→ Anthropic → Claude Pro/Max successfully obtains tokens and Claude models work correctly.cc @nichochar @julian-opencode
ultism commentedon Mar 20, 2026
it doesn't work
ggi-svg commentedon Mar 20, 2026
This is not an error ! Claude his blocking opencode now for legal reason se PR : #18186
What a shame ....
I just canceled my subscrption to claude and i m now switching to ChatGPT Plus !
MoerAI commentedon Mar 20, 2026
Update: OpenCode has officially dropped Claude support
Hi everyone — I want to provide an important update to clarify the situation here, as there seem to be many workarounds being shared that may no longer be relevant.
On March 20, 2026, Dax (OpenCode lead) announced on X that OpenCode is officially removing Claude OAuth support, following a formal legal request from Anthropic. The relevant commit is titled "Anthropic legal requests" and redirects users to alternative providers (OpenAI, GitHub, GitLab, etc.).
What this means
For those still looking for solutions
I'm closing my PR accordingly. Thank you to everyone who helped investigate this issue.
lehdqlsl commentedon Mar 20, 2026
Quick update on my workaround repo (
opencode-claude-auth-sync): I shipped v0.3.1 to clarify and fix the refresh semantics.Claude CLI does not proactively rotate tokens just because they are near expiry; it refreshes once the token is actually expired/unusable. The repo/docs now match that verified behavior.
Upgrade:
curl -fsSL https://raw.githubusercontent.com/lehdqlsl/opencode-claude-auth-sync/main/install.sh | bashRelease: https://github.com/lehdqlsl/opencode-claude-auth-sync/releases/tag/v0.3.1
5 remaining items
shahidshabbir-se commentedon Mar 21, 2026
@g14wx The 429 on token exchange means you're on an older version that used the wrong User-Agent.
Update to the latest:
Verify you're on v0.3.0:
Add to your opencode.json:
Then clear OpenCode's plugin cache and retry:
rm -rf ~/.cache/opencode/node_modules/opencode-anthropic-oauth oc auth loginv0.3.0 uses the correct
User-Agent: claude-cli/2.1.80on the token exchange — the old versions usedUser-Agent: anthropicwhich Anthropic blanket-rejects with 429.ErcinDedeoglu commentedon Mar 21, 2026
king. share your donate link!
vinzabe commentedon Mar 21, 2026
here's the permanent fix - https://github.com/vinzabe/PERMANENT-opencode-anthropic-oauth-fix
fix: dynamic OAuth User-Agent detection and curl-based token endpoints
fix: dynamic OAuth User-Agent detection and curl-based token endpoints (
g14wx commentedon Mar 21, 2026
Wow seriously thanks a lot @shahidshabbir-se , what a detailed solution
thank you so much!
dotCipher commentedon Mar 23, 2026
For anyone still hitting OAuth issues with Anthropic, I built opencode-claude-bridge which combines fixes from several community plugins into one. It auto-syncs tokens from Claude CLI's keychain (zero-click if you're already logged in), handles token refresh, and emulates Claude Code's exact request format. Install: just add
"plugin": ["opencode-claude-bridge"]to your OpenCode config — it auto-installs from npm.mateusz28011 commentedon Mar 23, 2026
On opencode 1.3 i have this error "Anthropic API key is missing. Pass it using the 'apiKey' parameter or the ANTHROPIC_API_KEY environment variable."
dotCipher commentedon Mar 23, 2026
@mateusz28011 file an issue on my project if you have problems and I'll look into them on a case-by-case basis
skhaz commentedon Mar 23, 2026
I had the same issue.
dotCipher commentedon Mar 23, 2026
Update for OpenCode 1.3+ — opencode-claude-bridge v1.6.1
For those still hitting issues (especially after the OpenCode 1.3 update that removed the built-in Anthropic plugin), I've released v1.6.1 of
opencode-claude-bridgewith several fixes:What was breaking on OpenCode 1.3:
x-anthropic-billing-headersystem block — Anthropic's API silently rejects these requests without itWhat v1.6.1 fixes:
x-anthropic-billing-headersystem block automatically (required for OAuth on OpenCode 1.3)ANTHROPIC_API_KEYinstead of deleting it, so the SDK initializes cleanly — the realAuthorization: Bearertoken is set in the request headers by the fetch wrapperprovider.modelsaccess in case OpenCode 1.3 passes an incomplete provider object during model selectionInstall / upgrade:
{ "plugin": ["opencode-claude-bridge"] }Or upgrade manually:
Then restart OpenCode. If you're logged into Claude CLI (
claude login), it auto-syncs your credentials — no re-auth needed.@mateusz28011 and @skhaz — the "API key missing" error should be resolved in v1.6.1.
Sleepful commentedon Mar 31, 2026
brew upgrade opencode:)dotCipher commentedon Apr 16, 2026
Closing, as this is not supported directly by opencode anymore, see thread: #18267
I wrote a plugin for opencode to support my use case, released here: https://github.com/dotCipher/opencode-claude-bridge
Default Avante to Copilot; run Claude via Claude Code CLI instead