src/hooks/bundled/README.md
This directory contains hooks that ship with OpenClaw. These hooks are automatically discovered and can be enabled/disabled via CLI or configuration.
Automatically saves session context to memory when you issue /new or /reset.
Events: command:new, command:reset
What it does: Creates a dated memory file with LLM-generated slug based on conversation content.
Output: <workspace>/memory/YYYY-MM-DD-slug.md (defaults to ~/.openclaw/workspace)
Enable:
openclaw hooks enable session-memory
Injects extra bootstrap files (for example monorepo AGENTS.md/TOOLS.md) during prompt assembly.
Events: agent:bootstrap
What it does: Expands configured workspace glob/path patterns and appends matching bootstrap files to injected context.
Output: No files written; context is modified in-memory only.
Enable:
openclaw hooks enable bootstrap-extra-files
Logs all command events to a centralized audit file.
Events: command (all commands)
What it does: Appends JSONL entries to command log file.
Output: ~/.openclaw/logs/commands.log
Enable:
openclaw hooks enable command-logger
Runs BOOT.md whenever the gateway starts (after channels start).
Events: gateway:startup
What it does: Executes BOOT.md instructions via the agent runner.
Output: Whatever the instructions request (for example, outbound messages).
Enable:
openclaw hooks enable boot-md
Each hook is a directory containing:
Example structure:
session-memory/
āāā HOOK.md # Metadata + docs
āāā handler.ts # Handler implementation
---
name: my-hook
description: "Short description"
homepage: https://docs.openclaw.ai/automation/hooks#my-hook
metadata:
{ "openclaw": { "emoji": "š", "events": ["command:new"], "requires": { "bins": ["node"] } } }
---
# Hook Title
Documentation goes here...
["command:new", "session:start"])["workspace.dir"])["darwin", "linux"])[{"id":"bundled","kind":"bundled"}])To create your own hooks, place them in:
<workspace>/hooks/ (highest precedence)~/.openclaw/hooks/ (shared across workspaces)Custom hooks follow the same structure as bundled hooks.
List all hooks:
openclaw hooks list
Show hook details:
openclaw hooks info session-memory
Check hook status:
openclaw hooks check
Enable/disable:
openclaw hooks enable session-memory
openclaw hooks disable command-logger
Hooks can be configured in ~/.openclaw/openclaw.json:
{
"hooks": {
"internal": {
"enabled": true,
"entries": {
"session-memory": {
"enabled": true
},
"command-logger": {
"enabled": false
}
}
}
}
}
Currently supported events:
/new command specifically/reset command/stop commandHook handlers receive an InternalHookEvent object:
interface InternalHookEvent {
type: "command" | "session" | "agent" | "gateway" | "message";
action: string; // e.g., 'new', 'reset', 'stop', 'compact:before', 'received', 'sent'
sessionKey: string;
context: Record<string, unknown>;
timestamp: Date;
messages: string[]; // Push messages here to send to user
}
Example handler:
import type { HookHandler } from "../../src/hooks/hooks.js";
const myHandler: HookHandler = async (event) => {
if (event.type !== "command" || event.action !== "new") {
return;
}
// Your logic here
console.log("New command triggered!");
// Optionally send message to user
event.messages.push("⨠Hook executed!");
};
export default myHandler;
Test your hooks by:
pkill -9 -f 'openclaw.*gateway' && pnpm openclaw gatewayopenclaw hooks enable my-hook/new command)Full documentation: https://docs.openclaw.ai/automation/hooks