{"record":{"id":"064bb05d4ea2b4f8","repo":"nikivdev/code","slug":"agent-exited-with-status","errorCode":null,"errorMessage":"Agent exited with status: {}","messagePattern":"Agent exited with status: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/agents.rs","lineNumber":909,"sourceCode":"    println!(\"Invoking {} agent...\\n\", agent);\n\n    let (tool, model) = get_agent_config();\n    let status = match tool.as_str() {\n        \"claude\" => invoke_claude(&full_prompt)?,\n        \"opencode\" => invoke_opencode(&full_prompt, model.as_deref())?,\n        _ => {\n            let gen_loc = find_gen().ok_or_else(|| {\n                anyhow::anyhow!(\n                    \"gen not found. Install with:\\n  cd {} && f install\\n  # or set GEN_REPO env var\",\n                    gen_repo_hint()\n                )\n            })?;\n            invoke_gen(&gen_loc, &full_prompt)?\n        }\n    };\n\n    if !status.success() {\n        bail!(\"Agent exited with status: {}\", status);\n    }\n\n    Ok(())\n}\n\n/// Invoke Claude Code with a prompt.\nfn invoke_claude(prompt: &str) -> Result<std::process::ExitStatus> {\n    Command::new(\"claude\")\n        .args([\"-p\", prompt])\n        .stdin(Stdio::inherit())\n        .stdout(Stdio::inherit())\n        .stderr(Stdio::inherit())\n        .status()\n        .context(\"failed to run claude\")\n}\n\n/// Invoke opencode with a prompt and optional model.\nfn invoke_opencode(prompt: &str, model: Option<&str>) -> Result<std::process::ExitStatus> {","sourceCodeStart":891,"sourceCodeEnd":927,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/agents.rs#L891-L927","documentation":"After building the full prompt and dispatching to the chosen backend (Claude Code, gen, etc.), run_agent checks the child process exit status. A non-zero status means the agent backend ran but failed, so run_agent bails with 'Agent exited with status: <status>'. The message carries only the exit code, not the backend's output.","triggerScenarios":"The invoked agent backend (claude, gen, or a custom binary) exits non-zero — e.g. auth failure, missing API key, crashed model CLI, or the prompt caused a fatal backend error.","commonSituations":"Expired or missing API credentials for the backend agent CLI; backend not installed despite the name resolving; network failure reaching the model provider; backend OOM/crash on a large prompt.","solutions":["Re-run the agent command directly (e.g. `claude ...` or `gen ...`) to see its stderr/stdout.","Authenticate the backend: run its login flow or set the required API key env var (e.g. ANTHROPIC_API_KEY).","Verify the backend binary is installed and up to date.","Retry with a smaller/simpler prompt if the backend crashed on input size."],"exampleFix":"// before\n$ f agents run claude \"review\"\nError: Agent exited with status: exit status: 1\n// after\n$ claude --version && claude login   # fix backend auth/install\n$ f agents run claude \"review\"       # now succeeds","handlingStrategy":"retry","validationCode":"command -v claude >/dev/null && claude --version >/dev/null 2>&1 \\\n  && f agents run claude \"prompt\" || echo \"backend agent not ready\"","typeGuard":"fn backend_ready(cmd: &str) -> bool {\n    std::process::Command::new(cmd).arg(\"--version\").output()\n        .map(|o| o.status.success()).unwrap_or(false)\n}","tryCatchPattern":"match run_agent(agent, prompt) {\n    Err(e) if e.to_string().starts_with(\"Agent exited with status\") => {\n        eprintln!(\"Backend '{agent}' failed; run it directly for details.\");\n        // optionally retry after fixing auth/install\n    }\n    other => other?,\n}","preventionTips":["Authenticate backend CLIs (login flows, API key env vars) before use.","Verify the backend binary is installed and current.","For flaky/network backends, retry with backoff.","Check backend logs by running the underlying command directly on failure."],"tags":["subprocess","agent","exit-code"],"backgroundTag":"subprocess-nonzero-exit","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}