Skip to main content

Use hooks

Customize the behavior of Второй пилот SDK sessions at key points in the conversation lifecycle using hooks.

Quickstart for hooks

Get started with hooks in Второй пилот SDK to control tool execution, transform results, add context, handle errors, and audit interactions.

Pre-tool use hook

Use the onPreToolUse hook to control tool execution, modify arguments, and add context before a tool runs in Второй пилот SDK.

Post-tool use hook

Use the onPostToolUse hook to transform tool results, log tool execution, and add context after a tool runs in Второй пилот SDK.

User prompt submitted hook

Use the onUserPromptSubmitted hook to modify prompts, add context, and filter user input in Второй пилот SDK.

Session lifecycle hooks

Use the onSessionStart and onSessionEnd hooks to initialize context, clean up resources, and track session metrics in Второй пилот SDK.

Error handling hook

Use the onErrorOccurred hook to implement custom error logging, track error patterns, and provide user-friendly error messages in Второй пилот SDK.