Plugin hooks reference
This is the exhaustive contract reference for WednesdayAI’s plugin lifecycle hooks — the typed events registered inside a plugin withapi.on(name, handler, opts?). Source of truth: PluginHookName, PluginHookHandlerMap, and the PluginHook* types in src/plugins/types.ts, re-exported from openclaw/plugin-sdk.
For the authoring guide (which hook to pick, mutation categories, examples) see Hooks. For standalone HOOK.md hooks and the bundled hook catalogue, see Hooks catalogue — those are a different system.
Registration
- Handlers may be synchronous or
async; the runtime awaits them. - Handlers for the same hook run sequentially in registration order;
{ priority }orders across plugins. - Context lifecycle hooks (
context.collect,context.project,context.prune,compaction.plan) are awaited with a 5 000 ms timeout; a timed-out handler is logged and skipped. Other hooks have no dedicated timeout but sit on the run’s critical path — keep them fast. - A thrown handler error is caught and logged per
catchErrorspolicy; it does not crash the gateway.
Shared context types
Most hooks receive one of these as the second (ctx) argument:
PluginRuntimeIdentity carries resolved identity: agentId/agentName, sessionId/sessionKey, channelConversationId, opaque providerConversationId + hashedUserId, raw sender fields (senderId/senderName/senderUsername/senderE164), canonicalIdentity + identitySource ("sender" | "parent-session" | "job-config"), senderIsOwner, messageProvider, channelId, and laneId (opaque workspace-lane digest). PluginTurnIdentity carries turnId (equals runId), sequence numbers (userSeq/assistantSeq, global variants), and entry ids.
Hook catalogue
Model and prompt hooks
model_call_ended fires per attempt, not per individual LLM API call inside a
tool-use loop. Use llm_output for a stable post-run observation point.Message hooks
Tool hooks
Session hooks
Subagent hooks
Subagent hooks receive
PluginHookSubagentContext: { runId?, childSessionKey?, requesterSessionKey?, runtimeIdentity?, turn? }.
Gateway hooks
Transform hooks
Storage and context lifecycle hooks
All receiveContextLifecycleContext (see Context engine). These are the context-engine surface:
Compaction observer hooks
Scheduling and outcome hooks
What not to do
Related
- Hooks — authoring guide and mutation categories
- Context engine — the
context.*/compaction.planpipeline in depth - Hooks catalogue — standalone
HOOK.mdhooks and bundled hooks (a separate system)