Skip to content

[Bug] MCP OAuth refresh tokens stored but never used - causing widespread auth failures #21333

Closed as duplicate

Description

@aneym

Summary

Claude Code stores MCP OAuth refresh tokens but never uses them to refresh expired access tokens. This causes authentication failures requiring manual re-authentication, sometimes multiple times per day.

Evidence

Refresh tokens ARE stored

// From macOS Keychain - Claude Code-credentials
"supabase|...": {
  "accessToken": "sbp_oauth_...",
  "refreshToken": "UVemFCAEqbCNEpPqkG",  // ← Stored but never used
  "expiresAt": 1769635674007
}

MCP servers DO support refresh

Both Linear and Sentry OAuth metadata explicitly support refresh tokens:

// https://mcp.linear.app/.well-known/oauth-authorization-server
// https://mcp.sentry.dev/.well-known/oauth-authorization-server
"grant_types_supported": ["authorization_code", "refresh_token"]

Tokens expire with no refresh attempt

After ~24 hours (or less), tokens expire and users see:

  • "Invalid grant: refresh token is invalid"
  • MCP servers showing empty accessToken: "" and expiresAt: 0
  • Silent failures where MCP appears connected but returns "Unauthorized"

Impact

MCP Spec Compliance

The MCP Authorization spec states:

"Authorization servers SHOULD issue short-lived access tokens to reduce the impact of leaked tokens."

This implies clients MUST implement refresh token handling. Claude Code does not.

Related Issues (20+)

This is the root cause of many fragmented issues:

Issue Problem
#5706 Original feature request (7+ months, no response)
#16957 Exit-time refresh tokens not persisted
#19456 Keychain permission errors on token update
#12447 OAuth expiration disrupts autonomous workflows
#19481 /mcp reconnect doesn't refresh expired tokens
#10784 OAuth expiration causes retry storm (3.75M wasted tokens)
#18225 Repeated 401 errors during active sessions
#10250 OAuth succeeds but MCP reconnection fails

Expected Behavior

  1. When access token expires, Claude Code should use stored refresh token
  2. On successful refresh, persist new access + refresh tokens
  3. On refresh failure, prompt user to re-authenticate (not fail silently)

Environment

  • Claude Code: 2.1.x (affects multiple versions)
  • Platform: macOS (also reported on Linux)
  • MCP servers affected: Linear, Sentry, Supabase, Atlassian, custom OAuth servers

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

Activity

  1. added
    bug
    has repro
    platform:macos
    on Jan 27, 2026
  2. github-actions commented on Jan 27, 2026

    @github-actions

    Found 3 possible duplicate issues:

    1. [BUG] Claude Code MCP client ignores scopes_supported from OAuth protected resource metadata, preventing refresh token issuance #7744
    2. [BUG] Claude Code can't find refresh_token in connecting with MCP Server using OAuth #12614
    3. Missing Token Refresh Mechanism for MCP Server Integrations #5706

    This issue will be automatically closed as a duplicate in 3 days.

    • If your issue is a duplicate, please close it and 👍 the existing issue instead
    • To prevent auto-closure, add a comment or 👎 this comment

    🤖 Generated with Claude Code

  3. added
    duplicate
    and removed
    bug
    has repro
    platform:macos
    on Jan 31, 2026
  4. github-actions commented on Jan 31, 2026

    @github-actions

    This issue has been automatically closed as a duplicate of #7744.

    If this is incorrect, please re-open this issue or create a new one.

    🤖 Generated with Claude Code

  5. github-actions commented on Feb 8, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  6. locked as resolved and limited conversation to collaborators on Feb 8, 2026
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

    duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions