Skip to main content

Module hooks

Module hooks 

Source
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:

EventhookEventNameadditionalContext Content
Session startSessionStartMemory statistics, recent topics, tutorial info
User promptUserPromptSubmitRelevant memories based on search intent
Post tool usePostToolUseRelated 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:

EventResponseNotes
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:

HandlerRequired ServiceBuilder Method
PreCompactHandlerCaptureServicewith_capture()
UserPromptHandlerRecallServicewith_recall()
PostToolUseHandlerRecallServicewith_recall()
StopHandlerSyncServicewith_sync()
SessionStartHandlerContextBuilderServicewith_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§

AdaptiveContextConfig
Configuration for adaptive memory context injection.
InjectedMemory
An injected memory in the context response.
MemoryContext
Memory context for hook response.
NamespaceWeights
Namespace weight multipliers for intent-based search.
PostToolUseHandler
Handles PostToolUse hook events.
PreCompactHandler
Handler for the PreCompact hook event.
SearchContextBuilder
Builder for search context with adaptive memory injection.
SearchIntent
Result of search intent detection.
SessionStartHandler
Handles SessionStart hook events.
StopHandler
Handles Stop hook events.
UserPromptHandler
Handles UserPromptSubmit hook events.

Enums§

DetectionSource
Source of intent detection.
GuidanceLevel
Level of guidance to provide in context.
SearchIntentType
Types of search intent detected from user prompts.

Traits§

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