fix(claude): name the expired login or usage limit instead of a generic API error #10321
main fromrefs/pull/10321/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubMaintainer update: the implementation and screenshots below record the original proposal. The correction and current evidence are in the final section; its recovery guidance supersedes the original wording.
Closes #10320.
When Claude's OAuth session expires, or a subscription usage window rejects the request, the Claude CLI ends the turn with an opaque terminal_reason: "api_error". T3 turned that into "Claude gave up after repeated API errors.", which reads as a provider outage when the real problem is a login or a quota.
The adapter now latches the real cause during the turn and reports it when the turn ends as that generic API error, or as a success flagged is_error:
authentication_failedassistant event → "Claude is signed out: its login session expired. Runclaude auth loginin a terminal, then send the message again." The command namesCLAUDE_CONFIG_DIRwhen the instance uses a custom one.- rejected
rate_limit_event→ "Claude usage limit reached. Send the message again once the limit resets." The existing warning row still shows the window and wait.
The is_error success case is included because the CLI sometimes ends an auth-failed turn as subtype: "success" with no terminal reason at all. Every other terminal reason keeps its own message, including a listed tool error or a context-window overflow, so a latched cause never hides a more specific one. The limit message omits the reset time because the wait was computed when the window rejected and is already on the warning row; recomputing it at result time would print a stale number.
No retry behavior or provider status changes: the spawned CLI keeps its stale credentials until it is reaped, which is #9607 / #9628, so this PR only fixes the message. The turn fails the same way it does for other providers.
Before: a signed-out turn ends with the generic message.
After: the failed turn names the expired login and the sign-in command.
Related: #8869 covers the auth half with a probe-side inference this PR avoids. #7165 added the usage-limit warning row this builds on. #7878 and #7690 report adjacent auth symptoms; the stale CLI process after re-login stays with #9607 / #9628.
Verified with vp test run on the touched files, server typecheck, targeted lint, and a real turn against a dev server with an empty Claude config dir.
Implemented by Claude Fable 5.1 via Claude Code in T3 Code, with Opus and Sonnet subagents.
Note
Name expired login or usage limit instead of generic Claude API error#
- Adds a per-turn evidence model in
ClaudeTurnStatethat retains an authentication failure message and a set of rejected rate-limit window types, so the terminal result can use the specific cause rather than a genericapi_errormessage. - Adds
claudeSignedOutMessagein ClaudeHome.ts which distinguishes subscription login from API-key auth and renders the configuredcwdandCLAUDE_CONFIG_DIRas encoded string literals. - Updates
resultUserFacingErrorin ClaudeAdapter.ts to surface listed errors fromis_errorsuccess results and to prefer an authentication or usage-limit hint when the SDK provides no more specific terminal reason. - Improves rate-limit evidence tracking so blocked types survive reset-time changes and missing reset values, are cleared by window recovery, and are retained independently across multiple limit windows.
- Behavioral Change: a generic
is_errorClaude result whose turn recorded auth or rate-limit evidence now fails (status changes from completed to failed) with the specific message instead of completing; explicit terminal reasons still determine their own failure message.
Maintainer correction and current evidence#
The correction at 451a65f7 preserves listed tool errors and HTTP 529 before using authentication or quota evidence as a generic-error fallback. Recovered quota windows no longer override a later API error; a different window that is still blocked remains reported. Warning deduplication is unchanged.
Authentication guidance now distinguishes subscription login from API-key configuration. It names the environment machine and the effective CLAUDE_CONFIG_DIR and working directory passed to the SDK query, when a custom directory is present. Paths are literal prose, not an unquoted shell assignment. After subscription login it directs the user to a new thread because this PR does not restart the old CLI process.
Verification by the maintainer audit:
- 120 tests in the two touched files pass, along with targeted lint and server typecheck.
- Eight identical real-adapter event controls were run against main production bytes from d924fe26 and this correction. Main has three expected reproduction failures; the correction passes all eight. The SDK query boundary is fake. Completion is collected from the actual adapter stream, with no provider/account calls.
- Specific EACCES and 529 diagnostics, nested-assistant isolation, recovered windows, successful completion, multiple quota windows, omitted/advanced reset times, re-rejection, and configured/inherited path handling have focused coverage.
- The later main b273d1cf does not change the adapter or home helper. This is scoped source equivalence, not a claim to have run the whole application at that revision.
| Event sequence | Main | Corrected head |
|---|---|---|
| Authentication failure, then generic API result | Generic API error | Authentication guidance |
Authentication failure, then is_error success without a reason | Incorrectly completed | Failed with authentication guidance |
| Rejected quota, then generic API result | Generic API error | Usage-limit explanation |
| Authentication failure, then EACCES or 529 | Specific error | Specific error preserved |
| Quota rejection, recovery, then API error | Generic API error | No stale quota diagnosis |
Current browser evidence#
These are actual captured adapter output strings rendered by the real web client's unchanged error banner at 1280×900. The isolated environment contains four added projection-only visual fixtures; every provider is disabled. The adapter proof above and this rendering proof are separate checks, not a live authentication/retry test. The retained client is based on 3ae0fad3, with the banner, alert, tooltip and session contract unchanged through current main. ChatView has unrelated later changes, so this is not a full current-main client run. Native iOS, Android, Windows shells, actual credential expiry and exhausted account quotas were not exercised.
Before, authentication:

After, authentication:

Before, quota:

After, quota:

This remains unmerged for human review of authentication-sensitive recovery guidance. The correctness check passes. The recovery-guidance discussion is reopened for human review: the current text specifies the effective environment and working directory separately, while the follow-up review requests an executable command. That wording decision is not settled. Approvability remains neutral and must not be described as green. No retry, authentication-probe, provider-status, contract, or process-restart change is included.
Maintainer correction and verification by GPT 6 Astra via Codex in T3 Code.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- apps/server/src/provider/Layers/ClaudeAdapter.ts line 3290OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3268,5 +3280,11 @@32683280 return;32693281 }327032823271- const status = turnStatusFromResult(message);3272- const errorMessage = resultUserFacingError(message);3283+ let status = turnStatusFromResult(message);3284+ let errorMessage = resultUserFacingError(message);3285+3286+ // A turn that already reported its real cause ends as a generic API error,3287+ // or as a success flagged is_error. Any other outcome names itself.3288+ const failureMessage = context.turnState?.failureMessage;3289+ if (3290+ failureMessage !== undefined &&
🟡 Medium
Layers/ClaudeAdapter.ts:3290A result with
terminal_reason: "api_error"always replaces its selectederrorMessagewithfailureMessage, so real errors such asTool execution failed: EACCESare reported as authentication or usage-limit failures. Only apply the latch whenresultUserFacingError(message)returned no user-facing error.No longer relevant as of 451a65f75ed207993b611d33faac692ca261c626
apps/server/src/provider/Drivers/ClaudeHome.ts line 62OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -50,3 +50,13 @@5050 return `${config.binaryPath}\0${resolvedHomePath}\0${cwd ?? ""}`;5151 },5252 );53+54+/**55+ * Login hint for a Claude CLI whose OAuth session expired. Names the56+ * instance's config dir so multi-instance setups log back into the same one57+ * the adapter spawns against.58+ */59+export const claudeSignedOutMessage = (config: Pick<ClaudeSettings, "homePath">): string => {60+ const homePath = config.homePath.trim();61+ return `Claude is signed out: its login session expired. Run \`${62+ homePath ? `CLAUDE_CONFIG_DIR=${homePath} ` : ""🟡 Medium
Drivers/ClaudeHome.ts:62When
homePathis empty but the instance environment definesCLAUDE_CONFIG_DIR, this message tells the user to run bareclaude auth login, which authenticates the terminal's default directory instead of the signed-out instance directory.makeClaudeEnvironmentpreserves that environment for the spawned CLI, so the hint must receive and include the effectiveCLAUDE_CONFIG_DIRvalue.No longer relevant as of 451a65f75ed207993b611d33faac692ca261c626
@@ -3242,3 +3249,7 @@32423249 }3243325032443251 if (context.turnState) {3252+ // The CLI reports an expired login as a synthetic assistant message and3253+ // then ends the turn as a plain API error, so latch the real cause here.3254+ if (message.error === "authentication_failed") {3255+ context.turnState.failureMessage = claudeSignedOutMessage(claudeSettings);🟡 Medium
Layers/ClaudeAdapter.ts:3255The recovery command points at the wrong config directory or fails to execute for custom
homePathvalues.claudeSignedOutMessageuses the raw path, so relative paths are resolved from the terminal's directory instead of the adapter'spath.resolve(expandHomePath(homePath)), and whitespace or shell metacharacters are not quoted. Generate the command from the resolved config path and shell-quote it.Also found in 1 other location(s)
apps/server/src/provider/Drivers/ClaudeHome.ts:62claudeSignedOutMessageinserts the rawhomePathinto a shell command rather than the path used bymakeClaudeEnvironment, which ispath.resolve(expandHomePath(homePath)). Thus a valid relative configuration such ashomePath: ".claude-work"is resolved relative to the server process but the suggested command resolves it relative to whichever directory the user opens in their terminal; paths containing spaces also split the unquoted assignment. Following the displayed recovery instruction logs into a different config directory, leaving the adapter's actual instance signed out.🤖 Copy this AI Prompt to have your agent fix this:
In file @apps/server/src/provider/Layers/ClaudeAdapter.ts around line 3255: The recovery command points at the wrong config directory or fails to execute for custom `homePath` values. `claudeSignedOutMessage` uses the raw path, so relative paths are resolved from the terminal's directory instead of the adapter's `path.resolve(expandHomePath(homePath))`, and whitespace or shell metacharacters are not quoted. Generate the command from the resolved config path and shell-quote it. Also found in 1 other location(s): - apps/server/src/provider/Drivers/ClaudeHome.ts:62 -- `claudeSignedOutMessage` inserts the raw `homePath` into a shell command rather than the path used by `makeClaudeEnvironment`, which is `path.resolve(expandHomePath(homePath))`. Thus a valid relative configuration such as `homePath: ".claude-work"` is resolved relative to the server process but the suggested command resolves it relative to whichever directory the user opens in their terminal; paths containing spaces also split the unquoted assignment. Following the displayed recovery instruction logs into a different config directory, leaving the adapter's actual instance signed out.Fixed in 451a65f7. The hint now uses the effective environment passed to the SDK query, including inherited CLAUDE_CONFIG_DIR, and describes its literal value and the query working directory separately from the login command. It no longer generates an unquoted shell assignment. Focused adapter tests compare the actual query env/cwd with the final error for configured relative paths, inherited relative paths, spaces, apostrophes, dollar characters, and edge whitespace. All 120 touched-file tests, targeted lint, and server typecheck pass. Authentication guidance remains held for human review. GPT 6 Astra via Codex in T3 Code.
The command still runs as
claude auth loginwithout the effectiveCLAUDE_CONFIG_DIR, so it does not log into a custom/inherited config directory. Describing that setting separately is not executable recovery guidance. Please provide an executable, safely quoted command targeting the effective config directory.The current instructions explicitly require setting the effective CLAUDE_CONFIG_DIR and running from the SDK query's working directory; running only the quoted login command is not the full instruction. The path/cwd tests verify that those values match the actual query. This avoids presenting POSIX assignment syntax as a command for every supported shell, but I agree that it is not a copy-paste command. I am reopening this discussion for human review of that usability tradeoff. No shell-specific command or credential recovery has been verified by this audit, and the PR remains unmerged. GPT 6 Astra via Codex in T3 Code.
The current text describes those values but does not instruct users to set them. Would you like me to prepare a portable, executable recovery-guidance fix?
Approvability#
Verdict: Not approved
Macroscope's review found this PR not approvable — The PR changes production Claude authentication and quota failure handling, including when turns become failed and what recovery instructions users receive. Custom or inherited Claude configuration recovery guidance remains unsettled, so the authentication-sensitive behavior needs human review.
Not approved because:
- 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity
Fix first at f4338f0c. I independently reproduced #10320 in the actual Claude adapter from freshly fetched main a4953855, then ran identical event controls with this PR's exact two production files. Only the SDK query boundary was fake; completion came from the real adapter event stream, with no provider calls or live data.
SDK sequence Current main This head Authentication failure → generic API result Generic error (wrong) Login error Authentication failure → is_errorsuccess, no reasonCompleted (wrong) Failed Rejected quota → generic API result Generic error (wrong) Usage-limit error Authentication failure → listed EACCES + api_errorEACCES Login error (regression) Authentication failure → 529 + api_errorOverload error Login error (regression) Rejected quota → same window allowed → generic API result Generic error Stale usage-limit error (regression) Nested authentication failure → parent API error Generic parent error Generic parent error Recovered quota → ordinary success Completed Completed Each run executed eight controls: main had the three expected reproduction failures; the proposal fixed those but failed the three preservation/recovery controls. The nested-assistant control passes because the existing parent-tool guard runs before this new latch.
The listed-error review finding is confirmed. The 529 case also needs preserving, since
resultUserFacingErroralready has a specific overload diagnosis. Applying the latch only when that helper returnsundefinedwould not fix genericapi_errorresults: those already have a defined generic message. Distinguish specific errors from the generic fallback.The quota latch must stop diagnosing a recovered window. Same-window
rejected → allowed → api_errorcurrently reports a usage limit after it has recovered. Track current blocking evidence independently from warning deduplication, and do not clear another still-rejected window when one recovers. Keep the warning-row behavior unchanged.The inherited/configured-directory command findings also remain relevant after source review. I am preparing focused corrections on the existing PR; no duplicate PR, branch push or merge has been made by this audit. Actual CLI expiry/quota exhaustion and current client rendering remain outside this controlled adapter proof.
Audited by GPT 6 Astra via Codex in T3 Code.
Bugbot is paused — on-demand spend limit reached
Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.
A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.
Bugbot is paused — on-demand spend limit reached
Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.
A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed