GuidesRunning & maintaining

Claude Code "Not logged in · Please run /login" on a server

Why Claude Code says Not logged in, Login expired or another process is refreshing your login on a server or scheduled job, and which credential fixes it.

November 15, 2026The Everpod team
The short answer

Not logged in · Please run /login means Claude Code found no credential for that run. On a server, that usually means the job runs as a different user, or with a different HOME or CLAUDE_CONFIG_DIR, from the one you signed in as. Login expired and OAuth token revoked mean there was a sign-in and it no longer works. A message about another process refreshing your login means a second Claude Code on the machine holds the refresh lock. Run claude auth status as the job’s user to see what it finds. Then give the job a credential that doesn’t depend on you being there: a one-year token from claude setup-token on your plan, or an API key billed to a Console account.

Which message, which cause

Anthropic’s errors reference lists each of these messages. In a claude -p run they read differently from the terminal versions:

The headless docs say a failure such as missing authentication is printed “as the result on stdout”, so a cron job that saves only stderr never records it. Capture both, and check the exit status.

“Not logged in” when you are logged in

On Linux the sign-in lives in your account’s ~/.claude/.credentials.json, or under CLAUDE_CONFIG_DIR when that is set. A job only finds it if it runs as the same user, with the same home folder and the same CLAUDE_CONFIG_DIR. The usual ways to break that are a system service with no User=, which runs as root, a job started with sudo, a container that doesn’t mount the folder, and a job that sets its own HOME. To see what the job’s account finds, run:

sudo -u <job-user> -i claude auth status
Copied

On 2.1.323, a signed-out account prints JSON with "loggedIn": false and "authMethod": "none" and exits 1. If the job is meant to use an API key, check that ANTHROPIC_API_KEY is exported in the environment the job actually starts in, not only in your interactive shell’s ~/.bashrc.

The errors page names one more cause. When someone signs in again with the same claude.ai account on the machine while claude -p jobs are running, jobs could fail with this message, because “Before v2.1.318, Claude Code removed the stored login during that sign-in, before saving the new one.” Update Claude Code with claude update.

A login that lapses overnight

Login expired is the one that catches unattended work. Anthropic doesn’t publish how long a /login sign-in lasts. Claude Code warns three days before it expires, but only at startup, which a scheduled run or a session left open for days never shows you. The same page says a background session in agent view “that outlives the login stops making progress once the credential expires and can’t recover until you sign in again.”

A report on Claude Code’s tracker shows what a forced sign-in can cost, issue #108585, opened on November 9, 2026: a forced sign-in during a multi-agent session left running overnight killed every background subagent, threw away their unfinished work, and was only noticed about six hours later. The issue is open, and no maintainer has replied. Until it changes, renew before you leave a long session running: /login renews the sign-in, and /status shows a Login row reading Expired — log in again once it has lapsed.

For a -p job, the errors page’s fix is to run claude “in the same environment, complete /login, then rerun your command”: same user and same config folder, or the new sign-in goes somewhere the job doesn’t look. Installing Claude Code on Linux covers signing in on a machine with no browser, where you paste a code back from your phone or laptop.

“Another Claude Code process is refreshing it”

Claude Code processes on one machine take turns renewing a login through a shared lock. The errors page says this message appears when another process “held the shared refresh lock, or exited and left it behind”. Retry in a minute. If it keeps coming back, close other Claude Code processes, and if none are running, sign in again, which “doesn’t wait on the refresh lock.”

A server can leave that lock behind itself. Issue #105729, opened on 2.1.280 on Linux, traces it to a health check. An agent gateway was running claude auth status --json as an availability probe. The probe started a token refresh, created ~/.claude/.oauth_refresh.lock, and was killed by its caller’s timeout. With SIGTERM or SIGKILL straight after the lock appeared, the lock stayed behind in 8 of 8 runs, and every other Claude Code process on the account failed with this message until it went stale, about 60 seconds later. On a normal exit the lock is released. The issue is open, with no maintainer reply.

So if a monitor, a gateway or the top of a script runs claude auth status, let it finish rather than wrapping it in a short timeout, and don’t run it more often than you need to. To see whether a lock is there right now:

ls -l ~/.claude/.oauth_refresh.lock
Copied

“/<command> isn’t available in this environment.”

A -p run can’t open an interactive command. The headless docs say that skills and custom commands you invoke yourself do work in a prompt, but “built-in commands that only run in the terminal interface, such as /login, aren’t available.” Plugins are the common case: in a non-interactive run, Anthropic’s plugin docs say “/plugin doesn’t run, and Claude replies /plugin isn't available in this environment. Plugins you already installed do load.” Install them from the shell instead:

claude plugin marketplace add anthropics/claude-plugins-official
claude plugin install <plugin>@claude-plugins-official
Copied

The first line matters on a new server. The official marketplace is added the first time someone opens an interactive session there, so a setup script adds it before the install. For /login, there is no non-interactive form: sign in once in a terminal on the machine, or use one of the credentials below. Claude Code plugins covers the rest of the plugin setup.

A plan’s sign-in or an API key for the job

The two are different credentials with different purposes, and Anthropic says so on its legal and compliance page. Signing in with a Claude plan “is designed to support ordinary use of Claude Code and other native Anthropic applications”, and developers building products or services “should use API key authentication through Claude Console or a supported cloud provider.”

Running Claude Code on a schedule covers the rest of an unattended job: the timer, permissions, limits, and hearing about a run that failed.

Run Claude Code on an always-on developer pod.

A developer pod is a permanent cloud computer (VPS), set up and secured for you, with your pick of Claude Code, Codex, OpenCode, Pi, Hermes and OpenClaw installed. Run more agents at once than your laptop can hold, and keep them working when it’s closed. From $24 a month, built in about ten minutes.