Skip to main content
Watch: I Built an AI App Without Leaving Databricks

Claude Code error

Claude Code: Please run /login · API Error: 401 OAuth token has expired

Error message
Please run /login · API Error: 401 OAuth token has expired

Status: WorkaroundLast verified 4 documented fixes3 sources

What it means

Your saved login is no longer valid. A revoked token means you signed out everywhere or an admin removed access; an expired token means the automatic refresh failed mid-session. The revoked variant reads OAuth token revoked · Please run /login. In -p mode and the Agent SDK it reads Failed to authenticate. API Error: 401 OAuth token has expired.

Causes

  • Signing out everywhere or an admin removing access
  • Automatic token refresh failing mid-session
  • An expired or revoked long-lived token in CLAUDE_CODE_OAUTH_TOKEN
  • An inaccurate system clock (token validation depends on correct timestamps)

How to fix it

  1. Fix 1.

    Run /login at the Claude Code prompt to sign in again.

    Slash command
    /login
  2. Fix 2.

    For automation that cannot sign in interactively, authenticate with ANTHROPIC_API_KEY or generate a long-lived token.

    Terminal
    claude setup-token
  3. Fix 3.

    If you use CLAUDE_CODE_OAUTH_TOKEN, generate a fresh token with claude setup-token and restart with it, or unset the variable and run /login.

  4. Fix 4.

    If prompted to log in repeatedly, check your system clock; on macOS run claude doctor and unlock the login Keychain if it reports macOS Keychain is not writable.

    Snippet
    security unlock-keychain ~/Library/Keychains/login.keychain-db

More Claude Code errors

All 18 Claude Code errors

FAQ

What does "Please run /login · API Error: 401 OAuth token has expired" mean in Claude Code?

Your saved login is no longer valid. A revoked token means you signed out everywhere or an admin removed access; an expired token means the automatic refresh failed mid-session. The revoked variant reads OAuth token revoked · Please run /login. In -p mode and the Agent SDK it reads Failed to authenticate. API Error: 401 OAuth token has expired.

How do I fix "Please run /login · API Error: 401 OAuth token has expired"?

There are 4 documented fixes. Start with the first: Run /login at the Claude Code prompt to sign in again.

Is this Claude Code error fixed?

Status: Workaround. No release removes the cause. The documented fixes work around it. Affected versions: All versions. Before v2.1.211, waking from sleep could revoke the saved login across sessions; before v2.1.225, CLAUDE_CODE_OAUTH_TOKEN could be replaced mid-session by a short-lived token; v2.1.126 fixed a race that could clear a valid refresh token.

Sources

Last verified against 3 sources: official docs, maintainer replies and release notes.

Newsletter

Fixes for the tools you use, weekly

One email per week. New coding agent releases, what broke, and how developers are working around it.