Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions agent/anthropic_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1349,18 +1349,36 @@ def run_hermes_oauth_login_pure() -> Optional[Dict[str, Any]]:
"code_verifier": verifier,
}).encode()

req = urllib.request.Request(
# Anthropic migrated the OAuth token endpoint to platform.claude.com;
# console.anthropic.com/v1/oauth/token now returns 404. Try the new
# host first and fall back to the legacy one (mirrors token refresh).
token_endpoints = [
"https://platform.claude.com/v1/oauth/token",
_OAUTH_TOKEN_URL,
data=exchange_data,
headers={
"Content-Type": "application/json",
"User-Agent": f"claude-cli/{_get_claude_code_version()} (external, cli)",
},
method="POST",
)
]
result = None
last_error = None
for endpoint in token_endpoints:
req = urllib.request.Request(
endpoint,
data=exchange_data,
headers={
"Content-Type": "application/json",
"User-Agent": f"claude-cli/{_get_claude_code_version()} (external, cli)",
},
method="POST",
)
try:
with urllib.request.urlopen(req, timeout=15) as resp:
result = json.loads(resp.read().decode())
break
except Exception as exc:
last_error = exc
logger.debug("Anthropic token exchange failed at %s: %s", endpoint, exc)
continue

with urllib.request.urlopen(req, timeout=15) as resp:
result = json.loads(resp.read().decode())
if result is None:
raise last_error if last_error is not None else ValueError("Token exchange failed")
except Exception as e:
print(f"Token exchange failed: {e}")
return None
Expand Down