Skip to content

[Bug] OAuth refresh token race condition in multi-instance scenarios #22600

Closed as not planned

Description

@paulchubatyy

Bug Description
❯ It seems like this issue happens intermittently when more than one claude instance is running on this machine. One instance will
update the token, continue successful communication with the MCP server, but other instances will try to renew the OAuth token
(same as the first one), but the server will reject the renewal as it already happened. Then those instances usually need a
restart to pick up new token.

⏺ That's a great diagnosis. Classic OAuth refresh token race condition:

  1. Instance A refreshes token → server invalidates old refresh token, issues new one
  2. Instance B (still has old refresh token) tries to refresh → server rejects because old token was revoked
  3. Instance B shows "Failed to reconnect" until restarted to pick up the new token from shared storage

This is a known challenge with OAuth in multi-instance scenarios. The fix would typically involve:

  • Token refresh locking/coordination between instances
  • Or: server-side refresh token rotation that allows brief grace period for old tokens
  • Or: Claude Code detecting "refresh token invalid" and re-reading from storage before giving up

You can submit feedback using /bug or by reporting at https://github.com/anthropics/claude-code/issues with details about:

  • Multiple instances sharing ~/.claude.json / ~/.claude/.credentials.json
  • Race condition on HTTP MCP OAuth token refresh
  • The debug log pattern showing the failure

For now, restarting the affected instance (as you noted) is the workaround.

Environment Info

  • Platform: darwin
  • Terminal: ghostty
  • Version: 2.1.29
  • Feedback ID: 37039963-4be1-4a0f-a815-b453c98ec6ed

Errors

[{"error":"MaxFileReadTokenExceededError: File content (25567 tokens) exceeds maximum allowed tokens (25000). Please use offset and limit parameters to read specific portions of the file, or use the GrepTool to search for specific content.\n    at RVB (/$bunfs/root/claude:3523:5255)\n    at async call (/$bunfs/root/claude:3532:1511)\n    at async <anonymous> (/$bunfs/root/claude:3544:1608)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-02-02T19:41:59.164Z"},{"error":"MaxFileReadTokenExceededError: File content (66317 tokens) exceeds maximum allowed tokens (25000). Please use offset and limit parameters to read specific portions of the file, or use the GrepTool to search for specific content.\n    at RVB (/$bunfs/root/claude:3523:5255)\n    at async call (/$bunfs/root/claude:3532:1511)\n    at async <anonymous> (/$bunfs/root/claude:3544:1608)\n    at processTicksAndRejections (native:7:39)","timestamp":"2026-02-02T19:42:09.098Z"}]

Activity

  1. added
    stale
    on Feb 16, 2026
  2. github-actions commented on Mar 3, 2026

    @github-actions

    Closing for now — inactive for too long. Please open a new issue if this is still relevant.

  3. github-actions commented on Mar 12, 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.

  4. locked as resolved and limited conversation to collaborators on Mar 12, 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

    stale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions