Guide · October 2026

When login expiry silently stops an overnight run

If you come back in the morning to Claude Code stuck on "Login expired · Please run /login" or "Authentication failed" for hours, your login ended overnight. The run stopped on an error and nothing told you.

Why it happens

Claude Code signed in with a Claude subscription uses a short-lived access token and renews it with a stored refresh token. If the renewal fails (the sign-in is rejected as too old, or several sessions and the desktop app race the same refresh token), the next request ends in an auth error and the turn stops there. At the keyboard it's one /login; an overnight run just sits until morning.

Plenty of people have hit it: subagents stopped for 8.5 hours after a login expired at night (#104806), the desktop app stuck on "Authentication failed - sign in again" with no remote recovery (#106089), concurrent sessions clobbering the refresh token and wiping the Keychain login (#88583), and a long-standing request for token refresh in autonomous workflows (#12447).

Handling it yourself

1. Get told the moment it stops: when a turn ends on an API error, Claude Code runs the StopFailure hook with a value such as authentication_failed in the input JSON's error. Register it in ~/.claude/settings.json as below and have the script call osascript -e 'display notification "run /login" with title "Claude Code stopped"'. For your phone, add curl -d "run /login" https://ntfy.sh/<your-topic> to the same script. A ready-made script: stop-failure-alert.sh.

{ "hooks": { "StopFailure": [ { "matcher": "authentication_failed",
  "hooks": [ { "type": "command", "command": "~/.claude/hooks/stop-failure-alert.sh" } ] } ] } }

Limits: on Claude Code 2.1.317 we confirmed authentication_failed reaching the hook with an invalid key; a real subscription login expiring mid-night, and failures only inside subagents, weren't reproduced. The alert only tells you; it can't log you back in.

2. Make expiry less likely: if you run unattended often, claude setup-token creates a long-lived auth token (Claude subscription required). Treat it like a password and keep it out of shell history and repos. Many concurrent sessions plus the desktop app can race the refresh (#88583), so running fewer sessions overnight also helps.

With Lidnight

Lidnight adds a StopFailure hook to Claude Code when you set it up, so it recognises a session that ended on a login error and shows a "Stopped, logged out: <project>" Mac notification right away (free; the "Looks stuck" alert in Settings, on by default). For older sessions without the hook and for Codex, it reads the error text in the transcript (/login, 401 and so on). With Pro the same alert also goes to your phone (ntfy). It keeps this separate from usage limits, so a session waiting on a limit isn't reported as a login problem. Logging back in is still up to you. Checking what Claude Code did while you were away

Try Lidnight free

Apple Silicon Macs · macOS 13 or later. Every download includes a free trial of everything in Pro (5 lid-closed runs or 14 days), no payment details needed. Pro is a one-time payment (1 Mac $9.99 · 3 Macs $14.99) with a 14-day refund.

Homebrew: brew install whereisdw/tap/lidnight