OpenClaw Hooks
OpenClaw Hooks
OpenClaw has two distinct hook systems: internal gateway hooks and plugin hooks.
Internal (Gateway) hooks
Event-driven shell scripts triggered by agent and command lifecycle events.
| Hook | Trigger |
|---|---|
agent:bootstrap |
While building bootstrap files, before system prompt is finalized. Use to add/remove bootstrap context files. |
/new, /reset, /stop |
Command-level events. |
Plugin hooks
Extension points inside the agent/tool lifecycle and gateway pipeline. Registered via the plugin API.
| Hook | Phase | Purpose |
|---|---|---|
before_model_resolve |
Pre-session (no messages) | Deterministically override provider/model |
before_prompt_build |
After session load (with messages) | Inject prependContext, systemPrompt, prependSystemContext, appendSystemContext |
before_agent_start |
Legacy | Compatibility alias; prefer explicit hooks above |
before_agent_reply |
After inline actions, before LLM call | Claim turn → return synthetic reply or silence it |
agent_end |
After completion | Inspect final message list + run metadata |
before_compaction / after_compaction |
Compaction cycle | Observe or annotate |
before_tool_call / after_tool_call |
Tool execution | Intercept params/results |
before_install |
Skill/plugin install | Inspect scan findings, optionally block |
tool_result_persist |
Before transcript write | Synchronously transform tool results |
message_received |
Inbound message | Observe/modify incoming messages |
message_sending / message_sent |
Outbound message | Guard or observe outgoing messages |
session_start / session_end |
Session boundaries | Session lifecycle |
gateway_start / gateway_stop |
Gateway lifecycle | Startup/shutdown |
Block/cancel decision rules
before_tool_call { block: true }— terminal; stops lower-priority handlers.before_tool_call { block: false }— no-op; does NOT clear a prior block.before_install { block: true }— terminal.before_install { block: false }— no-op.message_sending { cancel: true }— terminal.message_sending { cancel: false }— no-op.
Related
- OpenClaw — parent system
- Agent Loop (OpenClaw) — where hooks fire in the loop
- OpenClaw Plugin Hooks — plugin API registration details