# OpenClaw Hooks
Hooks are event-driven handlers that fire on agent and gateway lifecycle events. They are how [[OpenClaw]] becomes programmatically extensible without modifying the core: drop a `HOOK.md` + `handler.ts` into a hooks directory and the runtime picks it up automatically.
The shape is intentionally similar to Claude Code hooks and the broader AgentSkills ecosystem ; same mental model, same authoring habits port over.
## Event Categories
- **Command events**: `command:new`, `command:reset`, `command:stop`
- **Session events**: `session:compact:before`, `session:compact:after`
- **Agent events**: `agent:bootstrap`
- **Gateway events**: `gateway:startup`
- **Message events**: `message:received`, `message:transcribed`, `message:preprocessed`, `message:sent`
Each event delivers a typed payload; the handler returns a structured result that the runtime applies (e.g., a `message:preprocessed` hook can rewrite the user message before it reaches the model).
## Discovery Order
Auto-discovered from three locations, **highest precedence first**:
1. Workspace ; `<workspace>/hooks/`
2. Managed ; `~/.openclaw/hooks/`
3. Bundled
Same override semantics as [[OpenClaw Skills]].
## Anatomy
Each hook is a directory with:
- `HOOK.md` ; metadata (which events it listens to, requirements, description)
- `handler.ts` ; an async TypeScript function that receives the event and returns a result
Distributable as **npm hook packs** so a vendor or community can ship a coherent set of related hooks together.
## Built-In Hooks
- **`session-memory`**: saves context on `/new` so it survives session reset
- **`bootstrap-extra-files`**: injects additional context files at agent bootstrap
- **`command-logger`**: audit logging for every command
- **`boot-md`**: executes a `BOOT.md` script when the agent starts
Disable any of these per-workspace if they conflict with custom flows.
## CLI
```bash
openclaw hooks list # see all loaded hooks
openclaw hooks info <name> # describe a hook
openclaw hooks check # validate definitions
openclaw hooks enable <name>
openclaw hooks disable <name>
openclaw hooks install <pkg> # install a hook pack
```
## Hooks vs Skills vs Standing Orders
- **Hooks** fire reactively on events ; passive
- **[[OpenClaw Skills]]** are invoked when the agent decides they're needed ; active
- **[[OpenClaw Standing Orders]]** are autonomous mandates that combine triggers, skills, and approval gates
A morning briefing routine, for example, uses a cron-fired *standing order* that spawns a *sub-agent* which loads briefing-related *skills*, with a `command-logger` *hook* recording everything for audit.
## References
- Hooks: https://docs.openclaw.ai/automation/hooks
## Related
- [[OpenClaw]]
- [[OpenClaw Skills]]
- [[OpenClaw Standing Orders]]
- [[OpenClaw Gateway]]
- [[Claude Code Hooks]]