Dokumentationerreichbar
Anthropic, Intercept and control agent behavior with hooks (Agent SDK)
code.claude.com (externe Seite)
Hooks als Funktionen im Agent SDK: wie ein Programm einen Callback an ein Ereignis hängt, was er zurückgeben kann und was geschieht, wenn er scheitert. Im Abschnitt zum Scheitern stehen die Voreinstellung (die Handlung läuft weiter), der Schalter on
geprüft 10.11.2026
Worauf sich diese Seite beruft, wörtlich, abgerufen am 04.11.2026:
Hooks are callback functions that run your code in response to agent events
bestätigt 10.11.2026On most events, if a callback throws or returns output that fails validation, the action goes ahead
bestätigt 10.11.2026the action goes ahead and your app receives an SDKInformational
bestätigt 10.11.2026Message warning whose tag is hook_callback_failed A callback that returns nothing, such as a path with no return, also counts as failing.
bestätigt 10.11.2026Requires Type
bestätigt 10.11.2026Script Agent SDK v0.3.317 or later, or Python Agent SDK v0.2.177 or later. Claude doesn’t see your error text
bestätigt 10.11.2026A callback that catches its own error and returns {} isn’t failing
bestätigt 10.11.2026these events ignore the option, so the action goes ahead
bestätigt 10.11.2026the tool has already run, so Claude receives the failure as feedback
bestätigt 10.11.2026the query fails at startup and sends no prompt when it can’t honor the option
bestätigt 10.11.2026the block counts only if it arrives before your canUseTool callback answers
bestätigt 10.11.2026a timeout also blocks Pre
bestätigt 10.11.2026Compact, Elicitation, and Worktree Create