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 |
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 |
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 |
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.

