Skip to content

Claude Code CLI: OAuth token not auto-refreshed on headless server (refreshToken ignored) #50743

Closed as duplicate

Description

@kubasiak

Description

Claude Code CLI does not auto-refresh OAuth tokens when running on a headless Linux server (GCP VM). The .credentials.json file contains a valid refreshToken, but when the accessToken expires, the CLI returns a 401 instead of refreshing.

Steps to reproduce

  1. Run claude login interactively on a server, authenticate via browser
  2. Wait for accessToken to expire (~6 hours, expiresAt in .credentials.json)
  3. Run claude -p "hello" --output-format stream-json --verbose --dangerously-skip-permissions
  4. Expected: token auto-refreshes using refreshToken
  5. Actual: 401 authentication_error "Invalid authentication credentials"

Environment

  • Claude Code version: 2.1.114
  • OS: Debian 12 (GCP e2-micro VM, headless, no X/display)
  • .credentials.json has valid refreshToken and subscriptionType: "max"
  • No browser available (headless server)

Context

Running Claude Code as a backend agent (called via -p mode from a FastAPI app). The CLI works perfectly when the token is fresh, but silently fails after expiry. Manual token refresh via the OAuth endpoint returns 403 (Cloudflare blocks non-browser requests).

Expected behavior

The CLI should auto-refresh the token using the refreshToken in .credentials.json, similar to how the interactive CLI handles it on desktop machines.

Workaround

Currently falling back to a different agent framework (Kenzan) when OAuth is expired, but this means losing access to Claude Code's full toolset (Read, Write, Edit, Bash).

Activity

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

    @github-actions

    Found 3 possible duplicate issues:

    1. OAuth token not persisted/refreshed for --print mode, breaks automation #37402
    2. [BUG] OAuth token expiration disrupts autonomous workflows – refresh token handling needed #12447
    3. OAuth refresh token not used when credentials are copied to remote/headless machines #21765

    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:linux
    on Apr 23, 2026
  4. github-actions commented on Apr 23, 2026

    @github-actions

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

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

    🤖 Generated with Claude Code

  5. github-actions commented on May 1, 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 May 1, 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