fix: use plain HTTP client with claude-cli User-Agent for OAuth token exchange#52
Merged
mirrorange merged 1 commit intomirrorange:mainfrom Mar 28, 2026
Conversation
… exchange Anthropic rejects requests to console.anthropic.com/v1/oauth/token that carry browser fingerprinting or non-matching User-Agent headers with 429. Use a plain httpx session with User-Agent matching Claude Code's format. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
OAuth token exchange to
console.anthropic.com/v1/oauth/tokenreturns 429 because Anthropic now rejects requests carrying browser fingerprinting headers (TLS JA3, browser User-Agent) or non-matching User-Agent values.The current
exchange_token()andrefresh_access_token()use_request()which creates a session withimpersonate="chrome", triggering the rejection.Changes
create_plain_session()inhttp_client.py— prefers httpx (no TLS fingerprinting), falls back to curl_cffi/rnet withimpersonate=None_token_request()inoauth.py— uses the plain session withContent-Type: application/x-www-form-urlencodedandUser-Agent: claude-cli/2.1.81 (external, cli)exchange_token()andrefresh_access_token()to use_token_request()What #51 was missing
PR #51 correctly identified the need for a plain HTTP session and
application/x-www-form-urlencodedcontent type, but usedUser-Agent: anthropicwhich Anthropic also blanket-rejects with 429. Per the opencode discussion, the token endpoint requires a User-Agent matching Claude Code's format (claude-cli/<version> (external, cli)).References