Expand description
Claude Code hooks.
Implements handlers for Claude Code hook events.
§Hook Response JSON Format
Claude Code hooks have different response formats depending on the event type.
Only certain hooks support hookSpecificOutput with additionalContext.
§Hooks Supporting Context Injection
The following hooks can inject context via hookSpecificOutput.additionalContext:
| Event | hookEventName | additionalContext Content |
|---|---|---|
| Session start | SessionStart | Memory statistics, recent topics, tutorial info |
| User prompt | UserPromptSubmit | Relevant memories based on search intent |
| Post tool use | PostToolUse | Related memories surfaced by tool output |
Example response for context-supporting hooks:
{
"hookSpecificOutput": {
"hookEventName": "UserPromptSubmit",
"additionalContext": "# Memory Context\n\n..."
}
}§Hooks Without Context Injection
The following hooks do NOT support hookSpecificOutput:
| Event | Response | Notes |
|---|---|---|
| Pre-compact | {} | Context logged only, auto-capture performed |
| Stop | {} | Session summary logged only, sync performed |
These hooks perform their side effects (auto-capture, sync) and log context
for debugging, but return empty JSON since Claude Code’s schema doesn’t
support hookSpecificOutput for these event types.
§Empty Response
When no context is available, return an empty object {}.
§Handler Configuration
All handlers use a builder pattern for dependency injection. While handlers
can be created with Handler::new(), they require specific services to
function properly:
| Handler | Required Service | Builder Method |
|---|---|---|
PreCompactHandler | CaptureService | with_capture() |
UserPromptHandler | RecallService | with_recall() |
PostToolUseHandler | RecallService | with_recall() |
StopHandler | SyncService | with_sync() |
SessionStartHandler | ContextBuilderService | with_context_builder() |
Handlers degrade gracefully when required services are not configured, returning empty results and logging debug messages.
Modules§
- post_
tool_ 🔒use - Post tool use hook handler.
- pre_
compact 🔒 - Pre-compact hook handler.
- search_
context 🔒 - Search context builder for adaptive memory injection.
- search_
intent 🔒 - Search intent detection for proactive memory surfacing.
- search_
patterns 🔒 - Search intent detection patterns.
- session_
start 🔒 - Session start hook handler.
- stop 🔒
- Stop hook handler.
- user_
prompt 🔒 - User prompt submit hook handler.
Structs§
- Adaptive
Context Config - Configuration for adaptive memory context injection.
- Injected
Memory - An injected memory in the context response.
- Memory
Context - Memory context for hook response.
- Namespace
Weights - Namespace weight multipliers for intent-based search.
- Post
Tool UseHandler - Handles
PostToolUsehook events. - PreCompact
Handler - Handler for the
PreCompacthook event. - Search
Context Builder - Builder for search context with adaptive memory injection.
- Search
Intent - Result of search intent detection.
- Session
Start Handler - Handles
SessionStarthook events. - Stop
Handler - Handles Stop hook events.
- User
Prompt Handler - Handles
UserPromptSubmithook events.
Enums§
- Detection
Source - Source of intent detection.
- Guidance
Level - Level of guidance to provide in context.
- Search
Intent Type - Types of search intent detected from user prompts.
Traits§
- Hook
Handler - Trait for hook handlers.
Functions§
- classify_
intent_ with_ llm - Classifies search intent using an LLM provider.
- detect_
search_ intent - Detects search intent from a user prompt using keyword pattern matching.
- detect_
search_ intent_ hybrid - Detects search intent using hybrid keyword + LLM detection.
- detect_
search_ intent_ with_ timeout - Detects search intent with LLM classification and timeout.