diff --git a/sdk/guides/hooks.mdx b/sdk/guides/hooks.mdx index 72ec3f26..2ceefb87 100644 --- a/sdk/guides/hooks.mdx +++ b/sdk/guides/hooks.mdx @@ -25,6 +25,27 @@ Hooks let you observe and customize key lifecycle moments in the SDK without for | SessionStart | When conversation starts | No | | SessionEnd | When conversation ends | No | +## Exit Codes + +Hook scripts signal their result through their exit code. The SDK matches the +[Claude Code hook contract](https://docs.claude.com/en/docs/claude-code/hooks): + +- **`0` — success.** The operation proceeds. `stdout` is parsed as JSON for + structured output (`decision`, `reason`, `additionalContext`, `continue`). +- **`2` — block.** The operation is denied. For `PreToolUse` and + `UserPromptSubmit` this rejects the action; for `Stop` it prevents the + agent from finishing and the conversation continues. `stderr` / `reason` + is surfaced as feedback. +- **Any other non-zero exit code — non-blocking error.** `success` is set to + `False` and the error is logged via `HookExecutionEvent`, but the + operation still proceeds. + + +Only exit code `2` blocks. Exit code `1` (the conventional Unix failure +code) is treated as a non-blocking error. A hook intended to enforce a +policy must exit with `2`. + + ## Key Concepts - Registration points: subscribe to events or attach pre/post hooks around LLM calls and tool execution