Skip to content

docs(sdk-hooks): add explicit Exit Codes section to SDK hooks guide#494

Merged
neubig merged 1 commit intomainfrom
docs/sdk-hooks-exit-codes
May 7, 2026
Merged

docs(sdk-hooks): add explicit Exit Codes section to SDK hooks guide#494
neubig merged 1 commit intomainfrom
docs/sdk-hooks-exit-codes

Conversation

@neubig
Copy link
Copy Markdown
Contributor

@neubig neubig commented May 7, 2026

Context

A user asked whether the SDK's stop-hook behavior (only exit code 2 blocks) is (1) consistent with Claude Code, and (2) clearly documented everywhere people learn about hooks.

(1) Consistency: ✅ already consistent — no SDK behavior change needed

The SDK's HookExecutor does:

success = (returncode == 0)
blocked = (returncode == 2)

This matches Claude Code's documented hook contract exactly:

Exit 0 = success; Exit 2 = blocking error; any other exit code = non-blocking error.

Warning: For most hook events, only exit code 2 blocks the action. Claude Code treats exit code 1 as a non-blocking error and proceeds with the action, even though 1 is the conventional Unix failure code.

(2) Documentation gap

This repo's two hooks pages diverge:

Page Before
openhands/usage/customization/hooks.mdx ✅ Has explicit "Exit codes" section enumerating 0 / 2 / other
sdk/guides/hooks.mdx ⚠️ Only "Yes (exit 2)" in the can-block column of a table

So a developer reading the SDK guide could easily assume the conventional Unix "non-zero = failure = block" semantics — exactly the gotcha Claude Code calls out with a Warning.

Change

Add an explicit "Exit Codes" section to sdk/guides/hooks.mdx, mirroring the wording already used in openhands/usage/customization/hooks.mdx and Claude Code's own reference, plus a <Warning> callout that only exit 2 blocks.

Companion PR

The SDK side gets matching updates (HookResult docstring + the 33_hooks example README) in:

No code/behavior change; documentation only.


This PR was created by an AI agent (OpenHands) on behalf of the user.

@neubig can click here to continue refining the PR

The companion 'Hooks' page under openhands/usage/customization/ already
spells out the 0 / 2 / other exit-code semantics, but the SDK guide
(sdk/guides/hooks.mdx) only mentions 'Yes (exit 2)' in the can-block
column of the Hook Types table. That leaves SDK developers reading this
guide to assume the conventional Unix 'non-zero = failure = block'
behavior, which does not match how the SDK (or Claude Code) actually
treat hook exit codes.

Add an explicit 'Exit Codes' section, mirroring the wording used in the
customization docs and Claude Code's own hooks reference, including a
Warning that only exit code 2 blocks.

Companion to OpenHands/software-agent-sdk PR that updates the SDK
HookResult docstring and 33_hooks example README with the same
clarification.

Co-authored-by: openhands <openhands@all-hands.dev>
@mintlify
Copy link
Copy Markdown

mintlify Bot commented May 7, 2026

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
all-hands-ai 🟢 Ready View Preview May 7, 2026, 11:26 AM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@neubig neubig marked this pull request as ready for review May 7, 2026 12:48
@neubig neubig requested review from enyst and xingyaoww as code owners May 7, 2026 12:48
Copy link
Copy Markdown
Contributor

@all-hands-bot all-hands-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Good taste - Clean documentation improvement that addresses a real user confusion point.

[RISK ASSESSMENT]

  • [Overall PR] ⚠️ Risk Assessment: 🟢 LOW

Documentation-only change. Adds explicit exit code semantics to match the existing OpenHands app docs pattern. Solves the real problem that users might assume conventional Unix semantics (non-zero = block) when only exit code 2 actually blocks.

VERDICT:
Worth merging: Fills a documentation gap with clear, accurate content.

KEY INSIGHT:
The <Warning> callout is especially valuable here—exit code 1 not blocking is counterintuitive and worth explicit emphasis.

@neubig neubig merged commit 54d4326 into main May 7, 2026
9 checks passed
@neubig neubig deleted the docs/sdk-hooks-exit-codes branch May 7, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants