Quick Start
Core Events
Tool Events
| Event | Trigger | Input Type | Use Case |
|---|---|---|---|
BEFORE_TOOL | Before tool execution | BeforeToolInput | Security checks, logging |
AFTER_TOOL | After tool execution | AfterToolInput | Result validation, logging |
Agent Events
| Event | Trigger | Input Type | Use Case |
|---|---|---|---|
BEFORE_AGENT | Before agent runs | BeforeAgentInput | Setup, initialization |
AFTER_AGENT | After agent completes | AfterAgentInput | Cleanup, reporting |
LLM Events
| Event | Trigger | Input Type | Use Case |
|---|---|---|---|
BEFORE_LLM | Before LLM API call | BeforeLLMInput | Request modification |
AFTER_LLM | After LLM response | AfterLLMInput | Response validation |
Session Events
| Event | Trigger | Input Type | Use Case |
|---|---|---|---|
SESSION_START | When session starts | SessionStartInput | Session initialization |
SESSION_END | When session ends | SessionEndInput | Session cleanup |
Error Events
| Event | Trigger | Input Type | Use Case |
|---|---|---|---|
ON_ERROR | When error occurs | OnErrorInput | Error handling |
ON_RETRY | Before retry attempt | OnRetryInput | Retry logic |
OnRetryInput Fields
TheOnRetryInput event includes both new tool-specific fields and legacy fields for backward compatibility:
New fields (recommended):
tool_name: Name of the failing toolattempt: Current attempt number (1-based)max_attempts: Maximum attempts configureddelay_ms: Delay before this retry in millisecondserror_type: Classified error type (timeout,rate_limit,connection_error,unknown)error: Original exception object
retry_count: Same asattemptmax_retries: Same asmax_attemptserror_message: String representation oferror
Agent-Level Error Callbacks
In addition to hook events, agents support a directon_error callback for LLM failures:
Hook Events vs Agent Callbacks
| Approach | Scope | Return Value | When Called |
|---|---|---|---|
| HookEvent.ON_ERROR | Global, all agents | HookResult | Any hook system error |
| agent.on_error | Single agent | None | LLM chat completion errors |
Extended Events
User Interaction Events
| Event | Trigger | Use Case |
|---|---|---|
USER_PROMPT_SUBMIT | User submits prompt | Input validation, logging |
NOTIFICATION | Notification sent | Alert routing |
Subagent Events
| Event | Trigger | Use Case |
|---|---|---|
SUBAGENT_STOP | Subagent completes | Result handling |
System Events
| Event | Trigger | Use Case |
|---|---|---|
SETUP | Initialization/maintenance | Config loading |
BEFORE_COMPACTION | Before context compaction | Pre-compaction hooks |
AFTER_COMPACTION | After context compaction | Post-compaction validation |
Message Events
| Event | Trigger | Use Case |
|---|---|---|
MESSAGE_RECEIVED | Message received | Preprocessing |
MESSAGE_SENDING | Before message sent | Modification |
MESSAGE_SENT | After message sent | Confirmation |
Gateway Events
| Event | Trigger | Use Case |
|---|---|---|
GATEWAY_START | Gateway starts | Initialization |
GATEWAY_STOP | Gateway stops | Cleanup |
Storage Events
| Event | Trigger | Use Case |
|---|---|---|
TOOL_RESULT_PERSIST | Before result storage | Result modification |
Kanban Events
| Event | Input Type | Use Case |
|---|---|---|
KANBAN_TASK_CREATED | KanbanHookInput | Task added to board |
KANBAN_TASK_CLAIMED | KanbanHookInput | Task assigned |
KANBAN_TASK_MOVED | KanbanHookInput | Task status changed |
KANBAN_TASK_DONE | KanbanHookInput | Task completed |
KANBAN_TASK_BLOCKED | KanbanHookInput | Task blocked |
KANBAN_TASK_FAILED | KanbanHookInput | Task failed |
Complete Event Reference
| Event | Category | Description |
|---|---|---|
BEFORE_TOOL | Tool | Before tool execution |
AFTER_TOOL | Tool | After tool execution |
BEFORE_AGENT | Agent | Before agent runs |
AFTER_AGENT | Agent | After agent completes |
BEFORE_LLM | LLM | Before LLM API call |
AFTER_LLM | LLM | After LLM response |
SESSION_START | Session | Session starts |
SESSION_END | Session | Session ends |
ON_ERROR | Error | Error occurs |
ON_RETRY | Error | Before retry |
USER_PROMPT_SUBMIT | User | User submits prompt |
NOTIFICATION | User | Notification sent |
SUBAGENT_STOP | Subagent | Subagent completes |
SETUP | System | Initialization |
BEFORE_COMPACTION | Context | Before compaction |
AFTER_COMPACTION | Context | After compaction |
MESSAGE_RECEIVED | Message | Message received |
MESSAGE_SENDING | Message | Before message sent |
MESSAGE_SENT | Message | After message sent |
GATEWAY_START | Gateway | Gateway starts |
GATEWAY_STOP | Gateway | Gateway stops |
TOOL_RESULT_PERSIST | Storage | Before result storage |
KANBAN_TASK_CREATED | Kanban | Task added to board |
KANBAN_TASK_CLAIMED | Kanban | Task assigned |
KANBAN_TASK_MOVED | Kanban | Task status changed |
KANBAN_TASK_DONE | Kanban | Task completed |
KANBAN_TASK_BLOCKED | Kanban | Task blocked |
KANBAN_TASK_FAILED | Kanban | Task failed |
Best Practices
Keep hooks lightweight
Keep hooks lightweight
Hooks run synchronously. Avoid heavy operations that could slow down agent execution.
Use matchers for filtering
Use matchers for filtering
Use pattern matchers to only run hooks for specific tools or operations.
Return early
Return early
Return
HookResult.allow() quickly for non-matching cases to minimize overhead.Handle errors gracefully
Handle errors gracefully
Wrap hook logic in try/except to prevent breaking agent execution.
Related
Hooks
Hook system overview
Kanban Tasks
Kanban hook events and lifecycle
Plugins
Plugin system with hooks

