A Claude Code login that expires in the middle of a task is a rude surprise. You can check where you stand from the shell, without starting a session.
claude auth status --text
Without --text the command prints your authentication status as JSON, which suits scripts. It exits with code 0 when you’re logged in and 1 when you’re not, so a script can branch on it. The authMethod field is one of none, claude.ai, oauth_token, api_key, api_key_helper or third_party, and the JSON also names the configuration directory in configDirectory (v2.1.268 or later).
claude auth status || echo "not signed in"
The --text form is for humans. On Claude Code v2.1.318 or later, a claude.ai login adds a line like this one from the docs:
Sign-in ends: between 2026-11-20 and 2026-11-23 (2026-11-23T17:04:11.000Z)
Sign in again in the browser with /login or claude auth login before the earlier date. Using Claude Code doesn’t extend the login. If the line says any day now or may have ended, sign in right away.
One caveat: the line is missing for other credentials, or when no end date is known, so a missing line says nothing about the login. Also, when the later date is under 10 days away, a claude -p run with text output prints a warning on stderr.
I’d put the exit-code check at the top of any unattended script.
Further reading: Claude Code docs: check when a stored login ends, Claude Code docs: CLI reference