{"record":{"id":"9a786f63dd8dfbb6","repo":"tinyhumansai/openhuman","slug":"claude-agent-sdk-claude-subprocess-exited-with-n","errorCode":null,"errorMessage":"[claude_agent_sdk] claude subprocess exited with non-zero status {} and no output; stderr={}","messagePattern":"\\[claude_agent_sdk\\] claude subprocess exited with non-zero status (.+?) and no output; stderr=(.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/openhuman/inference/provider/claude_agent_sdk/subprocess.rs","lineNumber":236,"sourceCode":"        let status = timeout(Duration::from_secs(30), child.wait())\n            .await\n            .map_err(|_| {\n                anyhow::anyhow!(\"[claude_agent_sdk] subprocess timed out while waiting for exit\")\n            })??;\n        let stderr_output = stderr_task.await.unwrap_or_default();\n        tracing::debug!(\"[claude_agent_sdk] subprocess exited status={}\", status);\n\n        if let Some(err) = error_message {\n            anyhow::bail!(\"[claude_agent_sdk] error from claude CLI: {err}\");\n        }\n\n        // Use the final result message if present; otherwise join streaming text parts.\n        let output = result_text\n            .filter(|s| !s.is_empty())\n            .unwrap_or_else(|| text_parts.join(\"\"));\n\n        if !status.success() && output.is_empty() {\n            anyhow::bail!(\n                \"[claude_agent_sdk] claude subprocess exited with non-zero status {} and no output; stderr={}\",\n                status,\n                stderr_output\n            );\n        }\n\n        tracing::debug!(\n            \"[claude_agent_sdk] response collected output_len={}\",\n            output.len()\n        );\n\n        Ok(output)\n    }\n}\n\n#[async_trait]\nimpl ChatModel<()> for ClaudeAgentSdkProvider {\n    fn profile(&self) -> Option<&ModelProfile> {","sourceCodeStart":218,"sourceCodeEnd":254,"githubUrl":"https://github.com/tinyhumansai/openhuman/blob/749120085864ce16e0f273c7b86fac7740b39c5b/src/openhuman/inference/provider/claude_agent_sdk/subprocess.rs#L218-L254","documentation":"The claude CLI child process exited with a non-zero status AND the provider collected no usable output — neither a final `Result` text nor any streamed `Text` parts. The captured stderr is included in the message. This is the last-resort diagnosis when the CLI died before saying anything useful on stdout.","triggerScenarios":"The `claude` binary crashes at startup (bad flag, missing runtime like an incompatible Node version), fails auth before emitting NDJSON, or is killed by the OS (OOM, signal). Only fires when `!status.success() && output.is_empty()` — a non-zero exit WITH output is treated as success.","commonSituations":"CLI binary/arch mismatch after an OS update, claude CLI auto-update mid-run leaving a broken install, node runtime unavailable to the CLI wrapper, OOM killer terminating the child on memory-constrained machines, or an invalid CLI flag introduced by a version skew between the core's arg builder and the installed CLI.","solutions":["Read the `stderr=` portion of the message — it usually contains the crash reason (missing module, bad flag, auth failure).","Run the same CLI manually (`claude --version`, then a trivial prompt) to reproduce the crash outside the app.","Reinstall/upgrade the claude CLI (`npm i -g @anthropic-ai/claude-code` or the native installer) to repair a broken auto-updated install.","If stderr shows OOM/signal kill, free memory or reduce parallel agent turns."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight: does the CLI start and emit a version at all?\nfn claude_cli_bootable() -> bool {\n    std::process::Command::new(\"claude\")\n        .arg(\"--version\")\n        .output()\n        .map(|o| o.status.success())\n        .unwrap_or(false)\n}","typeGuard":null,"tryCatchPattern":"match provider.chat(req).await {\n    Err(e) if e.to_string().contains(\"non-zero status\") => {\n        log::error!(\"claude CLI crashed: {e}\"); // stderr is embedded — log it for triage\n        Err(e)\n    }\n    other => other,\n}","preventionTips":["Pin/verify the claude CLI version at deploy time so auto-updates can't break the binary mid-service.","Run a `--version` smoke check in startup health checks.","Reserve headroom for the CLI process on memory-constrained hosts."],"tags":["claude-cli","subprocess","crash","stderr"],"backgroundTag":"cli-process-crash","analyzedSha":"749120085864ce16e0f273c7b86fac7740b39c5b","analyzedAt":"2026-08-17T21:21:45.363Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}