Skip to main content

Module hooks

Module hooks 

Source
Expand description

Lifecycle hook callbacks (pre/post tool use, prompt submission, session start/end). Lifecycle hook callbacks invoked at key session points.

Hooks let you intercept and modify CLI behavior — approve or deny tool use, rewrite user prompts, inject context at session start, and handle errors. Implement SessionHooks and pass it to Client::create_session.

Structs§

ErrorOccurredInput
Input for the errorOccurred hook.
ErrorOccurredOutput
Output for the errorOccurred hook.
HookContext
Context provided to every hook invocation.
PostToolUseInput
Input for the postToolUse hook — received after a tool executes.
PostToolUseOutput
Output for the postToolUse hook.
PreToolUseInput
Input for the preToolUse hook — received before a tool executes.
PreToolUseOutput
Output for the preToolUse hook.
SessionEndInput
Input for the sessionEnd hook.
SessionEndOutput
Output for the sessionEnd hook.
SessionStartInput
Input for the sessionStart hook.
SessionStartOutput
Output for the sessionStart hook.
UserPromptSubmittedInput
Input for the userPromptSubmitted hook — received when the user sends a message.
UserPromptSubmittedOutput
Output for the userPromptSubmitted hook.

Enums§

HookEvent
Events dispatched to SessionHooks::on_hook at CLI lifecycle points.
HookOutput
Response from SessionHooks::on_hook back to the SDK.

Traits§

SessionHooks
Callback trait for session hooks — invoked by the CLI at key lifecycle points (tool use, prompt submission, session start/end, errors).