Fix Guide

Claude Code "OAuth Session Expired and Could Not Be Refreshed": How to Fix It

RS
Raiyan Shahid Building ExamAI, FileForge, CodeCompiler & Party Rush under BrynFlow · Get in touch

Quick fix: the Claude Code "OAuth session expired" error means your saved claude.ai login could not be renewed, so Claude Code signed you out. Type /login at the Claude Code prompt and sign in again. If you hit it in claude -p, a CI job or an Agent SDK script, run claude and /login once in that same environment, or switch the automation to an API key or a token from claude setup-token (steps 3 and 4).

Type "claude code error" into Google and the first suggestion is "failed to authenticate oauth session expired and could not be refreshed". The message usually appears in scripts and the Agent SDK. In an interactive session, the same problem shows up as a different line:

# non-interactive mode (claude -p) and the Agent SDK
Failed to authenticate: OAuth session expired and could not be refreshed

# interactive Claude Code
Login expired · Please run /login

This guide explains why the Claude Code OAuth session expires, then gives the fixes in order, quickest first. Every step comes from Anthropic's official Claude Code error reference or from bug reports on the Claude Code GitHub repository.

Why the Claude Code OAuth session expires

When you sign in with a claude.ai account, Claude Code stores two things: a short-lived access token and a refresh token that it uses to get new access tokens in the background. The error reference says this message appears when the sign-in service rejects the stored refresh token. Claude Code then clears the saved credentials, and with nothing else to fall back on, every request stops. Common reasons:

How to fix "OAuth session expired" in Claude Code

Work through these in order and test with a short prompt after each one.

  1. Run /login and sign in again. At the Claude Code prompt, type /login and complete the browser sign-in. This is the fix the official error reference gives for both "Login expired" and "OAuth token revoked or expired". If the error came from claude -p or an Agent SDK program, open Claude Code in the same environment (same user, same machine or container), sign in there, then rerun your command:
    claude
    # then, at the prompt:
    /login
  2. Check which credential is active with /status. Run /status. It shows whether Claude Code is using your claude.ai login, an ANTHROPIC_API_KEY, or a token from the CLAUDE_CODE_OAUTH_TOKEN environment variable. A 401 Invalid authentication credentials message is a different problem (a revoked credential, or an organization removed your access), so /status tells you which fix applies.
  3. Renew or unset CLAUDE_CODE_OAUTH_TOKEN. If /status shows an Auth token row reading CLAUDE_CODE_OAUTH_TOKEN, that long-lived token has expired or been revoked. Claude Code keeps sending the value you set, so /login alone does not help. Generate a fresh token and restart with it, or unset the variable and sign in normally:
    # create a new long-lived token
    claude setup-token
    
    # or stop using the variable (macOS / Linux)
    unset CLAUDE_CODE_OAUTH_TOKEN
    claude
  4. Use an API key or a long-lived token for automation. Scripts, CI jobs, cron tasks and background agents cannot complete a browser sign-in. For these, the docs recommend ANTHROPIC_API_KEY or a long-lived token from claude setup-token instead of a saved interactive login. Store either one as a secret in your CI system, never in the repository.
  5. Close other Claude Code windows and retry. If the message says another Claude Code process "is refreshing it", wait a minute and try again: when the other process finishes, your session uses the renewed login. If it keeps returning, close other Claude Code windows, terminals and background processes, then retry. If nothing else is running, run /login, which does not wait on the refresh lock.
  6. Check your computer's clock. A sign-in token is only valid for a time window, so a wrong system clock can make a fresh login look expired straight away. Turn on automatic date and time in your OS settings, then sign in again. For repeated login prompts across launches, the official error reference points to system clock checks and macOS credential-storage recovery steps in the Claude Code troubleshooting docs.
  7. Update Claude Code. Run claude update (or update with the package manager you installed it with) and restart your sessions. Users have reported on GitHub that the login sometimes expires mid-session without refreshing, including in long-running background sessions, and login fixes ship in regular releases. If you use the VS Code extension, update it too: one open report describes the error appearing there even with a valid saved credential.

If nothing works

Run /status and note the credential type and Claude Code version, then check the Claude status page for a login or API incident. If the service is healthy, search the Claude Code GitHub issues for your exact message and add your details to an existing report rather than opening a duplicate. If your account shows "Your account is on hold" or your organization's admin removed access, only the account owner or admin can fix it.

New to the tool? Our Claude Code tutorial for beginners covers installing, signing in and your first tasks. For other developer errors, see npm "could not determine executable to run" and Flutter "error connecting to the service protocol".

Frequently asked questions

What does "OAuth session expired and could not be refreshed" mean?

Claude Code tried to renew your claude.ai login, the sign-in service rejected the stored refresh token, and Claude Code cleared the saved credentials. In interactive mode the same event shows as Login expired · Please run /login.

Why do I see this error in claude -p or the Agent SDK but not in the terminal?

Non-interactive mode and the Agent SDK cannot open a browser to sign you in, so they report the failure with the error code authentication_failed. Sign in once by running claude and /login in the same environment, or use an API key or a token from claude setup-token.

Will I lose my conversation if I run /login?

Signing in again replaces the credential, not your project files. You can keep working in the same session after the login succeeds, or resume an earlier session with claude --resume.

Is "Not logged in · Please run /login" the same error?

It is closely related: Claude Code has no valid saved credential. The fix is also /login, but check /status first if you expected an API key or CLAUDE_CODE_OAUTH_TOKEN to be used.

Sources

Last checked November 29, 2026 against the Claude Code error reference.

Where to go next

Signed back in? Put Claude Code to work

The free AI Agents track shows you how to build, test and ship agents and tools step by step.

Start the AI Agents Track