NachschlagenQuellenregister

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 onFailure: "block" am matcher (in Python on_failure), die Ereignisse, bei denen er nicht oder anders wirkt (Stop, SubagentStop, TaskCompleted, TeammateIdle, PostToolUse, PermissionRequest), und der Abbruch beim Start, wenn Claude Code die Option nicht kennt. Gelesen am 04.11.2026.

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 eventsbestätigt 10.11.2026
  • On most events, if a callback throws or returns output that fails validation, the action goes aheadbestätigt 10.11.2026
  • the action goes ahead and your app receives an SDKInformationalMessage warning whose tag is hook_callback_failedbestätigt 10.11.2026
  • A callback that returns nothing, such as a path with no return, also counts as failing.bestätigt 10.11.2026
  • Requires TypeScript Agent SDK v0.3.317 or later, or Python Agent SDK v0.2.177 or later.bestätigt 10.11.2026
  • Claude doesn’t see your error textbestätigt 10.11.2026
  • A callback that catches its own error and returns {} isn’t failingbestätigt 10.11.2026
  • these events ignore the option, so the action goes aheadbestätigt 10.11.2026
  • the tool has already run, so Claude receives the failure as feedbackbestätigt 10.11.2026
  • the query fails at startup and sends no prompt when it can’t honor the optionbestätigt 10.11.2026
  • the block counts only if it arrives before your canUseTool callback answersbestätigt 10.11.2026
  • a timeout also blocks PreCompact, Elicitation, and WorktreeCreatebestätigt 10.11.2026

18 Hooks und Mods

Alle Quellen

↑↓ auswählenEnter öffnenDie Suche läuft im Browser. Nichts wird übertragen.