Answer: The SDK surfaces a nonzero CLI exit as a plain `Error` that rejects the `for await` loop over `query()`'s messages, so wrap the loop in `try`/`catch` and match on the message. To capture the full stderr stream, pass a `stderr` callback in the query options. Status: Confirmed Entry: tool/claude-code/troubleshooting/process-exit-code-n Revision: 2 Digest: sha256:9d5b55263486d902 (changes whenever the content changes) Timeline: Created: 2026-11-13T03:03:06Z Last changed: 2026-11-17T12:21:56Z (Signal termination message: — → Claude Code process terminated by signal ) Last verified: 2026-11-20T12:17:37Z Next check: 2026-11-21T12:17:37Z Check interval: Daily Expected change: No fixed schedule Data: Field | Value | Source | As of Error type | Error | [1] | 2026-11-20 Handling approach | try`/`catch | [1] | 2026-11-20 Example message | Claude Code process exited with code 1. stderr: | [1] | 2026-11-20 Full stderr capture | stderr | [1] | 2026-11-20 Signal termination message | Claude Code process terminated by signal | [1] | 2026-11-20 Sources: [1] Anthropic. "Troubleshoot the Agent SDK". https://code.claude.com/docs/en/agent-sdk/troubleshooting.md Role: primary. Accessed: 2026-11-20T12:17:37Z Quote: "The SDK surfaces a nonzero CLI exit as a plain `Error` that rejects the `for await` loop over `query()`'s messages." (Supports: Error type) Quote: "so wrap the loop in `try`/`catch` and match on the message" (Supports: Handling approach) Quote: "Claude Code process exited with code 1. stderr: " (Supports: Example message) Quote: "To capture the full stream, pass a `stderr` callback in the query options." (Supports: Full stderr capture) Quote: "A process killed by a signal reports `Claude Code process terminated by signal ` in the same form." (Supports: Signal termination message) Published: 2026-11-20T10:32:58Z Snapshot SHA-256: d35164042d96d0fc667e6ccb7e3b98f3122f76abadedb2d496f2eaea23598090 (captured 2026-11-17T12:21:55Z) Verification: Method: Automated extraction from [1] with deepseek-flash (JSON output, thinking disabled). Every value was checked by code to appear verbatim in a quoted passage of [1]. On this check the text of [1] was unchanged since 2026-11-17T12:21:56Z, so the values verified then were kept. Cross-check: not-available at 2026-11-20T12:17:37Z. No independent second source is configured for this entry Last successful check: 2026-11-20T12:17:37Z Last attempt: 2026-11-20T12:17:37Z Notes and limitations: Extracted automatically from a single official source (section "Claude Code process exited with code N"). Related: https://latestn.com/tool/claude-code/troubleshooting/read-debug-log How do I read the Claude Code debug log to troubleshoot a mod? https://latestn.com/tool/claude-code/troubleshooting/reload-and-test-mod How do I reload and test a Claude Code mod after changing it? https://latestn.com/tool/claude-code/troubleshooting/repository-not-listed Why isn't my repository listed in Add a repository for Claude Code Review? https://latestn.com/tool/claude-code/troubleshooting/oauth-login-wsl-ssh-containers How do I fix OAuth login failures in WSL2, SSH, or containers for Claude Code? https://latestn.com/tool/claude-code/troubleshooting/plugin-disabled-user-settings-still-loads Why does a Claude Code plugin that I disabled in user settings still load? https://latestn.com/tool/claude-code/troubleshooting/plugin-update-changed-nothing Why didn't my Claude Code plugin update change anything? https://latestn.com/tool/ All entries in AI tools Change log: Time | Event | Change | Source 2026-11-17T12:21:56Z | changed | Signal termination message: — → Claude Code process terminated by signal | [1] 2026-11-17T12:21:56Z | changed | Full stderr capture: — → stderr | [1] 2026-11-17T12:21:56Z | changed | Example message: — → Claude Code process exited with code 1. stderr: | [1] 2026-11-17T12:21:56Z | changed | Handling approach: — → try`/`catch | [1] 2026-11-17T12:21:56Z | changed | Error type: — → Error | [1] 2026-11-17T12:21:56Z | changed | signal termination message: Claude Code process terminated by signal → — | [1] 2026-11-17T12:21:56Z | changed | full stderr capture: stderr → — | [1] 2026-11-17T12:21:56Z | changed | example message: Claude Code process exited with code 1. stderr: → — | [1] 2026-11-17T12:21:56Z | changed | handling approach: try`/`catch → — | [1] 2026-11-17T12:21:56Z | changed | error type: Error → — | [1] 2026-11-13T03:03:06Z | added | Entry created | — Changes for this entry as a feed: https://latestn.com/tool/claude-code/troubleshooting/process-exit-code-n/latest Challenge this entry: Open challenges: None How: If a value here is wrong or out of date, send what is wrong and a link to evidence. Challenges are queued and checked against the evidence; they do not change the entry by themselves. If the entry changes as a result, the change log says so. Form: https://latestn.com/dispute/tool/claude-code/troubleshooting/process-exit-code-n POST: https://latestn.com/dispute/tool/claude-code/troubleshooting/process-exit-code-n with claim, evidence_url, and optionally field and contact (form-encoded or JSON) GET: https://latestn.com/dispute/tool/claude-code/troubleshooting/process-exit-code-n?claim={what is wrong}&evidence_url={link} How to cite: LatestN. (2026). How do I troubleshoot a Claude Code process that exits with code N in the Agent SDK? Revision 2, last verified 2026-11-20T12:17:37Z. https://latestn.com/tool/claude-code/troubleshooting/process-exit-code-n (accessed 2026-11-21T09:53:06Z). @misc{LatestN_tool_claude_code_troubleshooting_process_exit_code_n_r2, title = {How do I troubleshoot a Claude Code process that exits with code N in the Agent SDK?}, author = {{LatestN}}, year = {2026}, howpublished = {\url{https://latestn.com/tool/claude-code/troubleshooting/process-exit-code-n}}, note = {Revision 2; digest sha256:9d5b55263486d902; last verified 2026-11-20T12:17:37Z; accessed 2026-11-21T09:53:06Z} } Reuse: License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) Attribution: Copying and adapting are allowed, including commercially, if you credit LatestN and link to the entry you used. Each entry ends with a ready-made citation. URL: https://latestn.com/tool/claude-code/troubleshooting/process-exit-code-n