Skip to content

Fall back to the API key when the claude CLI loses its login - #18

Merged
nerdburn merged 1 commit into
mainfrom
fix/fallback-on-lost-login
Nov 24, 2026
Merged

nerdburn merged 1 commit into
mainfrom
fix/fallback-on-lost-login

Conversation

@nerdburn

Copy link
Copy Markdown
Owner

Why

The claude CLI on lore-host lost its OAuth session around 2026-11-12 ("Failed to authenticate: OAuth session expired and could not be refreshed"). Every fold on every client failed for six days, and nothing said so: the fallback key only covered usage limits.

What

  • authFailureReason / cliFailureReason in src/llm-fallback.ts: a failed authentication (expired/revoked OAuth, HTTP 401, "Please run /login", invalid key or token) now switches the run to LORE_FALLBACK_ANTHROPIC_API_KEY, like a usage limit. Each new run still tries the subscription first, so it switches back once the login works.
  • The once-per-episode email to LORE_LLM_FALLBACK_NOTIFY distinguishes the two: "Lore lost its Claude login and switched to the API key", saying it will not fix itself and how to restore it (claude setup-token → 1Password → CLAUDE_CODE_OAUTH_TOKEN in /etc/lore/env). Never includes the key. The limit email is unchanged.
  • Other CLI failures still fail as before.

Testing

New tests use the exact host error from Nov 12; typecheck and the full suite pass (470).

The host itself now uses a long-lived CLAUDE_CODE_OAUTH_TOKEN from claude setup-token, so this is the safety net for when that expires (~1 year).

🤖 Generated with Claude Code

The host's CLI OAuth session expired on 2026-11-12 and every fold failed
for six days: the fallback key only covered usage limits. A failed
authentication (expired/revoked OAuth, 401, "Please run /login", invalid
key) now switches the run to LORE_FALLBACK_ANTHROPIC_API_KEY too, and
the once-per-episode email says the login was lost, that it will not
recover by itself, and how to restore it with `claude setup-token`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nerdburn
nerdburn merged commit fec4adb into main Nov 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant