← Claude Code Hub
Nov 18, 2026 · 6 min read ✦ Tip #275

Claude Code login expired in claude -p: you can't stop it, only see it coming

Claude Code's stored login ends on a fixed date that renewing doesn't move. How to see it before a cron job or CI step running claude -p fails, and when to move the job to a one-year token.

Claude Code login expired in claude -p: without checking the date, the cron job fails with reached its time limit; with claude auth status you see loginExpiresAt first, and unattended jobs use claude setup-token

TL;DR On the machine that runs the job, claude auth status | jq -r .loginExpiresAt gives you the day the stored login ends; plan for it to end up to three days earlier. For anything that runs with nobody watching, generate a one-year token with claude setup-token, put it in CLAUDE_CODE_OAUTH_TOKEN and write the date down, because Claude Code won't show you that one.

Failed to authenticate: this login reached its time limit and cannot be renewed is what claude -p prints the day the claude.ai login you stored with /login or claude auth login hits its limit. That limit is set when you sign in, and using Claude Code every day doesn't push it back. Your terminal warns you three days ahead; a script, a cron job or a CI step never sees that warning and fails with nobody watching.

Why it expires even if you use it every day

A claude.ai login stores two tokens. The access token is short-lived, and Claude Code renews it on its own with the refresh token. The refresh token has its own end date, and in the v2.1.327 binary every renewal keeps the earlier of the two dates: renewing never extends it. Only a fresh sign-in starts a new countdown. Since v2.1.318, Claude Code shows that date in four places:

Where When What you see
claude auth status Always The loginExpiresAt field
claude -p --output-format json or stream-json On every result The credential_expires_at field, and no warning
claude -p with text output From 10 days before A one-line warning on stderr
Interactive session From 3 days before Your login expires in 3 days · run /login to renew

The gap is the second row: a job that reads JSON never gets the warning. It has to read the field itself.

What you see the day it fails

In claude -p and the Agent SDK, since v2.1.318:

Failed to authenticate: this login reached its time limit and cannot be renewed. Run `claude auth login` to sign in again, or use `claude setup-token` and set CLAUDE_CODE_OAUTH_TOKEN for unattended jobs

In an interactive session, Login reached its time limit · Please run /login. Before v2.1.318 both said something else, and it's what you'll still find in the issues:

Failed to authenticate: OAuth session expired and could not be refreshed

The structured error code is authentication_failed either way. One exception: if you also have an ant auth login profile, the job doesn't fail, it switches credentials and bills that profile's organization. It says so on stderr with Warning: the claude.ai login on this machine has ended. This run uses the sign-in from ant auth login instead, and its usage is billed to <organization>.

How to see the date ahead of time

1. Ask claude auth status on the job's machine

Use the same user and the same CLAUDE_CONFIG_DIR as the job: a cron job running as another user reads another login. The configDirectory field tells you which one it's reading. This is v2.1.327 on a machine that authenticates with a token rather than a stored login:

$ claude auth status | jq '{authMethod, configDirectory, loginExpiresAt}'
{
  "authMethod": "oauth_token",
  "configDirectory": "/root/.claude",
  "loginExpiresAt": null
}

null means there's no stored login to expire. With one, authMethod is claude.ai and loginExpiresAt holds an ISO date, such as "2026-11-25T09:12:44.000Z". claude auth status --text gives it as a window. Assembled from the v2.1.327 strings:

Sign-in ends: between 2026-11-22 and 2026-11-25 (2026-11-25T09:12:44.000Z)

The window is the three days before the date, and Claude Code always counts from the first one. Once you're inside the window it switches to Sign-in ends: any day now, by ..., and past the date to Sign-in may have ended: between ....

2. Read it from the claude -p result

If your job already uses --output-format json, every run carries it:

claude -p "$PROMPT" --output-format json | jq -r '.credential_expires_at // empty'

Tried on v2.1.327: with a token instead of a stored login, the field isn't in the JSON at all.

3. Don't throw stderr away

With text output, the warning shows up ten days ahead. Don't send it to /dev/null: if cron has mail set up, it sends you the job's output with stderr included. Assembled from the v2.1.327 strings, for a login ending on the 25th:

Warning: this sign-in ends between 2026-11-22 and 2026-11-25 (in 4 days at the earliest). Renewing it does not move those dates. Run claude auth login before then, or use claude setup-token for unattended jobs.

4. Check the date before the job starts

For a JSON job, which never gets the warning, these lines count the days the way Claude Code does, from the first day of the window:

#!/usr/bin/env bash
# Days left, at the earliest, before the stored login ends
days=$(claude auth status | jq -r '.loginExpiresAt // empty
  | sub("\\.[0-9]+Z$"; "Z") | fromdateiso8601
  | ((. - 3*86400) / 86400 | floor) - (now / 86400 | floor)')
if [ -n "$days" ] && [ "$days" -lt 10 ]; then
  echo "The Claude Code login may end in $days days: run claude auth login" >&2
fi

With the example date it prints The Claude Code login may end in 4 days, the same count as the warning. With a token it prints nothing.

When to switch to claude setup-token

If the job runs with nobody at the keyboard, don't leave it on your login. claude setup-token opens the same browser flow as /login and prints a one-year token it doesn't save anywhere: you copy it and set it as CLAUDE_CODE_OAUTH_TOKEN wherever the job runs.

Stored login claude setup-token token
How long it lasts Up to a limit set when you sign in One year
Where you see the date loginExpiresAt, credential_expires_at, the warning Nowhere: write it down when you create it
When it ends reached its time limit API Error: 401 OAuth token has expired
Remote Control and claude.ai connectors Yes No: model requests only

Three things the token won't do for you:

  • Claude Code doesn't show when it ends. claude auth status reads "authMethod": "oauth_token" and "loginExpiresAt": null, as above.
  • Once it expires, Claude Code keeps sending the variable's value and doesn't fall back to your stored login. Generate a new one and restart.
  • --bare doesn't read it. If your script starts with --bare, authenticate with ANTHROPIC_API_KEY or an apiKeyHelper.

It needs a Pro, Max, Ultra, Team or Enterprise plan. If the job ends green without having done anything, that's not the login: it's what permission_denials lists. And if it sits waiting on a permission prompt, denyInsteadOfPrompting denies it and carries on.

Official docs: Renew an expiring login · Generate a long-lived token · Login expired

Requirements

loginExpiresAt, credential_expires_at and the stderr warning need Claude Code v2.1.318 or later. Tried on v2.1.327 on Linux with a token: claude auth status, the claude -p JSON and the script. What only a stored claude.ai login shows (the date, the window and the warnings) comes from the v2.1.327 binary and the docs, with example dates.

Found this useful? See more of wmedia.es in your Google results.

Add wmedia.es as a preferred source on Google
Free guide

The 51 essentials, as a guide.

One page per tip. Five chapters. What I actually use daily in production. No theory, no fluff.

  • 1. Getting started 10 tips
  • 2. Awareness 3 tips
  • 3. Mastery 22 tips
  • 4. Autonomy 15 tips
  • 5. Comparison 1 tip
Are you a professional Web developer?

You'll receive the guide by email · You join the Gravitas newsletter · Unsubscribe anytime

of 51
#

Wmedia · 51 tips
Free guide · 51 tips · 5 chapters

The 51 essentials, as a guide.

One page per tip. Five chapters. What I actually use daily in production. No theory, no fluff.

Are you a professional Web developer? · Unsubscribe anytime
How I use AI

My Claude Code workflow.

The skills, agents and instructions I use as a professional Software Engineer. It's called Craft, and it's a plugin you can install.

See the skills

Want the 51 Claude Code essentials as a guide?