OpenClaw Hooks: Event-Driven Automation
Use hooks to trigger custom actions when specific events occur in OpenClaw.
What Are Hooks?
Hooks are shell commands that execute in response to OpenClaw events. They let you extend OpenClaw's behavior without modifying its code.
Hook Types
Message Hooks
Triggered when messages are sent or received:
on_message_received— When a message arrives from any channelon_message_sent— When OpenClaw sends a responseon_message_error— When message processing fails
Tool Hooks
Triggered around tool execution:
before_tool— Before a tool runs (can block execution)after_tool— After a tool completes
Lifecycle Hooks
Triggered on gateway events:
on_start— When OpenClaw startson_stop— When OpenClaw shuts downon_channel_connect— When a channel connectson_channel_disconnect— When a channel drops
Configuring Hooks
In openclaw.json:
{
"hooks": {
"on_message_received": "echo 'Message received' >> ~/openclaw.log",
"on_start": "notify-send 'OpenClaw is running'",
"before_tool": {
"command": "python3 ~/scripts/validate-tool.py",
"blocking": true
}
}
}
Use Cases
Logging
{
"hooks": {
"on_message_received": "echo $(date) >> ~/openclaw-activity.log"
}
}
Notifications
{
"hooks": {
"on_channel_disconnect": "osascript -e 'display notification "OpenClaw channel disconnected" with title "Alert"'"
}
}
Security Validation
{
"hooks": {
"before_tool": {
"command": "python3 ~/scripts/check-tool-safety.py",
"blocking": true
}
}
}
A blocking hook that returns a non-zero exit code prevents the action from executing.
Integration
{
"hooks": {
"on_message_sent": "curl -X POST https://your-webhook.com/log -d '{"event": "message_sent"}'"
}
}
Hook Environment
Hooks receive event data through environment variables:
OPENCLAW_EVENT— The event typeOPENCLAW_CHANNEL— The channel involvedOPENCLAW_TOOL— The tool name (for tool hooks)
Tips
- Keep hooks lightweight — they run synchronously by default
- Use
blocking: falsefor non-critical hooks - Test hooks manually before adding to configuration
- Log hook output for debugging
Ready for your AI assistant?
Get started with Claw for All today. No setup, no terminal, just sign up and go.
Get StartedRelated Guides
Using OpenClaw Canvas: Visual Workspace Guide
Create interactive diagrams, dashboards, and visual content with OpenClaw's Canvas feature.
Voice Commands and Talk Mode with OpenClaw
Use voice wake words and hands-free conversation with OpenClaw on macOS, iOS, and Android.
Running Shell Commands Through OpenClaw
Execute terminal commands, scripts, and system operations through natural conversation.