Skip to content

OAuth refresh token not used when credentials are copied to remote/headless machines #21765

Closed as not planned

Description

@khaledfouad0

Bug Description

When copying ~/.claude/.credentials.json from an authenticated machine to a remote/headless machine, Claude Code throws a 401 authentication_error ("OAuth token has expired") instead of using the refreshToken present in the credentials file to obtain a new access token.

Steps to Reproduce

  1. Authenticate Claude Code on a local workstation via claude login (Max subscription, OAuth flow)
  2. Copy ~/.claude/.credentials.json to a remote headless machine (e.g., via scp)
  3. Run claude on the remote machine after the accessToken has expired

Expected Behavior

Claude Code should detect the expired accessToken, use the refreshToken to obtain a new access token, and continue normally — the same way it does on the original machine.

Actual Behavior

API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth token has expired. Please obtain a new token or refresh your existing token."},"request_id":"req_011CXc8h3VFKY9jGum2N2rTZ"}

Credentials File Structure

The .credentials.json contains all necessary fields for a refresh:

{
  "claudeAiOauth": {
    "accessToken": "...",
    "refreshToken": "...",
    "expiresAt": ...,
    "scopes": [...],
    "subscriptionType": "max",
    "rateLimitTier": "..."
  }
}

The refreshToken is present but is not being used when the accessToken expires.

Use Case

Managing multiple headless Linux machines (Proxmox LXCs, Incus containers) where browser-based claude login is not practical. These machines are on a Tailnet and the intended workflow is to authenticate once on a workstation and distribute credentials to headless nodes. The copy-paste authorization code flow on headless machines is unreliable.

Environment

  • Source machine: Windows 11, Claude Code (Max subscription, OAuth)
  • Target machines: Headless Linux (Debian/Ubuntu LXCs and VMs)
  • Network: Tailscale mesh
  • Claude Code version: Latest (as of Jan 2026)

Activity

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

    @github-actions

    Found 3 possible duplicate issues:

    1. [Bug] MCP OAuth refresh tokens stored but never used - causing widespread auth failures #21333
    2. [BUG] OAuth token expiration disrupts autonomous workflows – refresh token handling needed #12447
    3. [BUG] claude setup-token/CLAUDE_CODE_OAUTH_TOKEN is not enough to authenticate claude #8938

    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. fahreddinozcan commented on Jan 30, 2026

    @fahreddinozcan

    Yes, I can confirm this is the issue. I've verified our refresh token flow to be working, however Claude Code doesn't use refresh tokens to get new access tokens, so users are forced to re-authenticate too often.

  4. added
    stale
    on Feb 14, 2026
  5. removed
    stale
    on Feb 28, 2026
  6. lonetis commented on Feb 28, 2026

    @lonetis

    This issue stems from refresh token rotation (Claude uses this), which is a security best practice. When a client redeems a refresh token, the server invalidates it and issues a new one. As a result, two machines can’t share the same refresh token. One machine redeems it and stores the rotated token, while the other keeps using the old token and fails.

  7. added
    stale
    on Mar 14, 2026
  8. github-actions commented on Mar 28, 2026

    @github-actions

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

  9. github-actions commented on Apr 6, 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.

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

    area:authbughas reproplatform:linuxstale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions