Skip to content

Anthropic OAuth login (auth add anthropic --type oauth) fails with 404 — login flow uses stale token endpoint #45250

Closed

Description

@warren-ja

Version: v0.16.0, commit a118b94a

Symptom

Claude Pro/Max subscription login via hermes auth add anthropic --type oauth fails at the token-exchange step:

Token exchange failed: HTTP Error 404: Not Found
Anthropic OAuth login did not return credentials.

Browser authorization succeeds (a valid code#state is pasted back), but the token exchange returns 404.

Root cause

In agent/anthropic_adapter.py, the login and refresh flows disagree on the token endpoint:

  • Login flow — run_hermes_oauth_login_pure() (~line 1337) POSTs to a single hardcoded endpoint _OAUTH_TOKEN_URL = "https://console.anthropic.com/v1/oauth/token" → 404.
  • Refresh flow — refresh_anthropic_oauth_pure() (~line 994) already uses a fallback list that tries https://platform.claude.com/v1/oauth/token first, then the console host — and works.

The refresh path already "knows" the current host; the login path was simply not updated alongside it.

Fix

Make the login token exchange iterate the same endpoint list (platform.claude.com first), mirroring refresh_anthropic_oauth_pure():

_token_endpoints = [
    "https://platform.claude.com/v1/oauth/token",
    _OAUTH_TOKEN_URL,  # console.anthropic.com fallback
]
result = None
last_error = None
for _endpoint in _token_endpoints:
    try:
        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",
        )
        with urllib.request.urlopen(req, timeout=15) as resp:
            result = json.loads(resp.read().decode())
        break
    except Exception as e:
        last_error = e
        continue
if result is None:
    print(f"Token exchange failed: {last_error}")
    return None

Verification (after patch)

  • hermes auth add anthropic --type oauth stores the credential (anthropic-oauth-1).
  • hermes chat -q "Reply with exactly: OK" -m anthropic/claude-opus-4.8 --provider anthropic -Q returns OK on the subscription (no tier rejection).

Environment

  • macOS, Hermes v0.16.0 (commit a118b94), Python 3.11.15.

Activity

  1. added
    type/bugSomething isn't working
    comp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint
    area/authAuthentication, OAuth, credential pools
    P2Medium — degraded but workaround exists
    on Jun 12, 2026
  2. liuhao1024 commented on Jun 13, 2026

    @liuhao1024

    This is fixed by #45254 — fix(auth): iterate token endpoints in Anthropic OAuth login flow.

  3. prasadus92 commented on Jun 21, 2026

    @prasadus92

    Confirmed on v0.17.0 (5aec00f). Root cause is one stale constant: run_hermes_oauth_login_pure posts the code exchange to _OAUTH_TOKEN_URL = https://console.anthropic.com/v1/oauth/token (agent/anthropic_adapter.py:1254), which 404s. The refresh path at ~:997 was already migrated and iterates ["https://platform.claude.com/v1/oauth/token", "https://console.anthropic.com/v1/oauth/token"]. The login path just needs the same list; the open PRs that do this are correct.

    Worth flagging for anyone here hunting a workaround: putting a claude setup-token value in ANTHROPIC_TOKEN is not a substitute. auth status anthropic reports "logged in", but the gateway 401s at inference against api.anthropic.com and silently falls back. Only the credential minted through the OAuth login (stored in .anthropic_oauth.json) gets the bearer/beta handling the Messages API expects. Fixing the login endpoint is the real unblock, not the env var.

    Minor: repeated exchange attempts 429 on both hosts for a few minutes, which can read as a second failure mode. It isn't.

  4. teknium1 commented on Jun 24, 2026

    @teknium1
    Collaborator

    Fixed on main via #51723. The Anthropic OAuth login token exchange now targets platform.claude.com first (with console.anthropic.com as fallback), mirroring the refresh path — both the CLI login and the dashboard OAuth flow. Credit to @yusekiotacode (salvage of #48706).

    #51723

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existsarea/authAuthentication, OAuth, credential poolscomp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpointprovider/anthropicAnthropic native Messages APItype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions