Note: hooks
The hooks package manages lifecycle event dispatch for Attune AI. It exposes five public names at the package boundary: HookConfig, HookDefinition, HookEvent, HookExecutor, and HookRegistry.
How the package is structured
Three modules divide the responsibilities:
-
hooks.configdefines the data model:HookEvent(event types tied to the Claude Code lifecycle),HookType,HookDefinition,HookMatcher,HookRule, andHookConfig.HookConfigis the top-level container; you load it from a YAML file withHookConfig.from_yaml()and query it withget_hooks_for_event(). -
hooks.executorruns hook actions.HookExecutor.execute()accepts aHookDefinitionand a context dict and returns a result dict.HookExecutorSyncwraps the same interface for call sites that cannot use async code. -
hooks.registryis the dispatch layer.HookRegistryholds all registered hooks, matches them against incoming events viaget_matching_hooks(), and fires them withfire()orfire_sync(). It also tracks execution history throughget_execution_log()and exposes aggregate metrics throughget_stats().
Relationship to scripts
The scripts package contains Python callables that plug into the registry as handlers. Examples include run_evaluate_session, run_pre_compact, check_init, and suggest_compact. You pass these callables to HookRegistry.register() as the handler argument. The registry assigns each registration a string ID that unregister() accepts later.
Execution log
HookRegistry.get_execution_log() returns up to 100 entries by default. Pass event_filter to narrow results to a specific HookEvent. Call clear_execution_log() to reset it between test runs or sessions.