Caricamento in corso...
Caricamento in corso...
Last synced: Today, 22:00
Technical reference for the OpenClaw framework. Real-time synchronization with the official documentation engine.
Use this file to discover all available pages before exploring further.
Hooks are small scripts that run when something happens inside the Gateway. They can be discovered from directories and inspected with
openclaw hooksThere are two kinds of hooks in OpenClaw:
/new/reset/stopHooks can also be bundled inside plugins.
openclaw hooks listbash# List available hooks openclaw hooks list # Enable a hook openclaw hooks enable session-memory # Check hook status openclaw hooks check # Get detailed information openclaw hooks info session-memory
| Event | When it fires |
|---|---|
text command:new | text /new |
text command:reset | text /reset |
text command:stop | text /stop |
text command | Any command event (general listener) |
text session:compact:before | Before compaction summarizes history |
text session:compact:after | After compaction completes |
text session:patch | When session properties are modified |
text agent:bootstrap | Before workspace bootstrap files are injected |
text gateway:startup | After channels start and hooks are loaded |
text gateway:shutdown | When gateway shutdown begins |
text gateway:pre-restart | Before an expected gateway restart |
text message:received | Inbound message from any channel |
text message:transcribed | After audio transcription completes |
text message:preprocessed | After media and link preprocessing completes or is skipped |
text message:sent | Outbound message delivered |
Each hook is a directory containing two files:
textmy-hook/ ├── HOOK.md # Metadata + documentation └── handler.ts # Handler implementation
markdown--- name: my-hook description: "Short description of what this hook does" metadata: { "openclaw": { "emoji": "🔗", "events": ["command:new"], "requires": { "bins": ["node"] } } } --- # My Hook Detailed documentation goes here.
Metadata fields (
metadata.openclaw| Field | Description |
|---|---|
text emoji | Display emoji for CLI |
text events | Array of events to listen for |
text export | Named export to use (defaults to text "default" |
text os | Required platforms (e.g., text ["darwin", "linux"] |
text requires | Required text binstext anyBinstext envtext config |
text always | Bypass eligibility checks (boolean) |
text install | Installation methods |
typescriptconst handler = async (event) => { if (event.type !== "command" || event.action !== "new") { return; } console.log(`[my-hook] New command triggered`); // Your logic here // Optionally send message to user event.messages.push("Hook executed!"); }; export default handler;
Each event includes:
typeactionsessionKeytimestampmessagescontexttraceCommand events (
command:newcommand:resetcontext.sessionEntrycontext.previousSessionEntrycontext.commandSourcecontext.workspaceDircontext.cfgMessage events (
message:receivedcontext.fromcontext.contentcontext.channelIdcontext.metadatasenderIdsenderNameguildIdMessage events (
message:sentcontext.tocontext.contentcontext.successcontext.channelIdMessage events (
message:transcribedcontext.transcriptcontext.fromcontext.channelIdcontext.mediaPathMessage events (
message:preprocessedcontext.bodyForAgentcontext.fromcontext.channelIdBootstrap events (
agent:bootstrapcontext.bootstrapFilescontext.agentIdSession patch events (
session:patchcontext.sessionEntrycontext.patchcontext.cfgCompaction events:
session:compact:beforemessageCounttokenCountsession:compact:aftercompactedCountsummaryLengthtokensBeforetokensAftercommand:stop/stopbefore_agent_finalizeGateway lifecycle events:
gateway:shutdownreasonrestartExpectedMsgateway:pre-restartrestartExpectedMsHooks are discovered from these directories, in order of increasing override precedence:
~/.openclaw/hooks/hooks.internal.load.extraDirs<workspace>/hooks/Workspace hooks can add new hook names but cannot override bundled, managed, or plugin-provided hooks with the same name.
The Gateway skips internal hook discovery on startup until internal hooks are configured. Enable a bundled or managed hook with
openclaw hooks enable <name>hooks.internal.enabled=truehooks.internal.enabled=trueHook packs are npm packages that export hooks via
openclaw.hookspackage.jsonbashopenclaw plugins install <path-or-spec>
Npm specs are registry-only (package name + optional exact version or dist-tag). Git/URL/file specs and semver ranges are rejected.
| Hook | Events | What it does |
|---|---|---|
| session-memory | text command:newtext command:reset | Saves session context to text <workspace>/memory/ |
| bootstrap-extra-files | text agent:bootstrap | Injects additional bootstrap files from glob patterns |
| command-logger | text command | Logs all commands to text ~/.openclaw/logs/commands.log |
| boot-md | text gateway:startup | Runs text BOOT.md |
Enable any bundled hook:
bashopenclaw hooks enable <hook-name>
Extracts the last 15 user/assistant messages, generates a descriptive filename slug via LLM, and saves to
<workspace>/memory/YYYY-MM-DD-slug.mdworkspace.dirjson{ "hooks": { "internal": { "entries": { "bootstrap-extra-files": { "enabled": true, "paths": ["packages/*/AGENTS.md", "packages/*/TOOLS.md"] } } } } }
Paths resolve relative to workspace. Only recognized bootstrap basenames are loaded (
AGENTS.mdSOUL.mdTOOLS.mdIDENTITY.mdUSER.mdHEARTBEAT.mdBOOTSTRAP.mdMEMORY.mdLogs every slash command to
~/.openclaw/logs/commands.logRuns
BOOT.mdPlugins can register typed hooks through the Plugin SDK for deeper integration: intercepting tool calls, modifying prompts, controlling message flow, and more. Use plugin hooks when you need
before_tool_callbefore_agent_replybefore_installFor the complete plugin hook reference, see Plugin hooks.
json{ "hooks": { "internal": { "enabled": true, "entries": { "session-memory": { "enabled": true }, "command-logger": { "enabled": false } } } } }
Per-hook environment variables:
json{ "hooks": { "internal": { "entries": { "my-hook": { "enabled": true, "env": { "MY_CUSTOM_VAR": "value" } } } } } }
Extra hook directories:
json{ "hooks": { "internal": { "load": { "extraDirs": ["/path/to/more/hooks"] } } } }
bash# List all hooks (add --eligible, --verbose, or --json) openclaw hooks list # Show detailed info about a hook openclaw hooks info <hook-name> # Show eligibility summary openclaw hooks check # Enable/disable openclaw hooks enable <hook-name> openclaw hooks disable <hook-name>
void processInBackground(event)"events": ["command:new"]"events": ["command"]bash# Verify directory structure ls -la ~/.openclaw/hooks/my-hook/ # Should show: HOOK.md, handler.ts # List all discovered hooks openclaw hooks list
bashopenclaw hooks info my-hook
Check for missing binaries (PATH), environment variables, config values, or OS compatibility.
openclaw hooks list./scripts/clawlog.sh | grep hook© 2024 TaskFlow Mirror
Powered by TaskFlow Sync Engine