Files

338 lines
7.5 KiB
Markdown
Raw Permalink Normal View History

2026-01-15 06:12:54 +00:00
---
2026-01-30 03:15:10 +01:00
summary: "CLI reference for `openclaw hooks` (agent hooks)"
2026-01-15 06:12:54 +00:00
read_when:
2026-01-17 07:32:50 +00:00
- You want to manage agent hooks
- You want to inspect hook availability or enable workspace hooks
2026-01-31 16:04:03 -05:00
title: "hooks"
2026-01-15 06:12:54 +00:00
---
2026-01-30 03:15:10 +01:00
# `openclaw hooks`
2026-01-15 06:12:54 +00:00
2026-01-18 10:10:05 +02:00
Manage agent hooks (event-driven automations for commands like `/new`, `/reset`, and gateway startup).
2026-01-15 06:12:54 +00:00
2026-04-04 08:46:24 +01:00
Running `openclaw hooks` with no subcommand is equivalent to `openclaw hooks list`.
2026-01-15 06:12:54 +00:00
Related:
2026-01-31 21:13:13 +09:00
- Hooks: [Hooks](/automation/hooks)
- Plugin hooks: [Plugin hooks](/plugins/architecture#provider-runtime-hooks)
2026-01-17 01:31:39 +00:00
2026-01-17 07:08:04 +00:00
## List All Hooks
2026-01-17 01:31:39 +00:00
```bash
2026-01-30 03:15:10 +01:00
openclaw hooks list
2026-01-17 01:31:39 +00:00
```
2026-03-22 09:37:30 -07:00
List all discovered hooks from workspace, managed, extra, and bundled directories.
2026-01-17 01:31:39 +00:00
**Options:**
2026-01-31 21:13:13 +09:00
2026-01-17 01:31:39 +00:00
- `--eligible`: Show only eligible hooks (requirements met)
- `--json`: Output as JSON
- `-v, --verbose`: Show detailed information including missing requirements
**Example output:**
```
Hooks (4/4 ready)
2026-01-17 01:31:39 +00:00
Ready:
2026-01-18 10:10:05 +02:00
🚀 boot-md ✓ - Run BOOT.md on gateway startup
📎 bootstrap-extra-files ✓ - Inject extra workspace bootstrap files during agent bootstrap
2026-01-17 01:31:39 +00:00
📝 command-logger ✓ - Log all command events to a centralized audit file
💾 session-memory ✓ - Save session context to memory when /new or /reset command is issued
2026-01-17 01:31:39 +00:00
```
**Example (verbose):**
```bash
2026-01-30 03:15:10 +01:00
openclaw hooks list --verbose
2026-01-17 01:31:39 +00:00
```
Shows missing requirements for ineligible hooks.
**Example (JSON):**
```bash
2026-01-30 03:15:10 +01:00
openclaw hooks list --json
2026-01-17 01:31:39 +00:00
```
Returns structured JSON for programmatic use.
2026-01-17 07:08:04 +00:00
## Get Hook Information
2026-01-17 01:31:39 +00:00
```bash
2026-01-30 03:15:10 +01:00
openclaw hooks info <name>
2026-01-17 01:31:39 +00:00
```
Show detailed information about a specific hook.
**Arguments:**
2026-01-31 21:13:13 +09:00
2026-04-04 08:46:24 +01:00
- `<name>`: Hook name or hook key (e.g., `session-memory`)
2026-01-17 01:31:39 +00:00
**Options:**
2026-01-31 21:13:13 +09:00
2026-01-17 01:31:39 +00:00
- `--json`: Output as JSON
**Example:**
```bash
2026-01-30 03:15:10 +01:00
openclaw hooks info session-memory
2026-01-17 01:31:39 +00:00
```
**Output:**
```
💾 session-memory ✓ Ready
Save session context to memory when /new or /reset command is issued
2026-01-17 01:31:39 +00:00
Details:
2026-01-30 03:15:10 +01:00
Source: openclaw-bundled
Path: /path/to/openclaw/hooks/bundled/session-memory/HOOK.md
Handler: /path/to/openclaw/hooks/bundled/session-memory/handler.ts
Homepage: https://docs.openclaw.ai/automation/hooks#session-memory
Events: command:new, command:reset
2026-01-17 01:31:39 +00:00
Requirements:
Config: ✓ workspace.dir
```
2026-01-17 07:08:04 +00:00
## Check Hooks Eligibility
2026-01-17 01:31:39 +00:00
```bash
2026-01-30 03:15:10 +01:00
openclaw hooks check
2026-01-17 01:31:39 +00:00
```
Show summary of hook eligibility status (how many are ready vs. not ready).
**Options:**
2026-01-31 21:13:13 +09:00
2026-01-17 01:31:39 +00:00
- `--json`: Output as JSON
**Example output:**
```
2026-01-17 07:32:50 +00:00
Hooks Status
2026-01-17 01:31:39 +00:00
2026-01-18 10:10:05 +02:00
Total hooks: 4
Ready: 4
2026-01-17 01:31:39 +00:00
Not ready: 0
```
2026-01-17 07:08:04 +00:00
## Enable a Hook
2026-01-17 01:31:39 +00:00
```bash
2026-01-30 03:15:10 +01:00
openclaw hooks enable <name>
2026-01-17 01:31:39 +00:00
```
2026-04-04 08:46:24 +01:00
Enable a specific hook by adding it to your config (`~/.openclaw/openclaw.json` by default).
2026-01-17 01:31:39 +00:00
2026-03-22 09:37:30 -07:00
**Note:** Workspace hooks are disabled by default until enabled here or in config. Hooks managed by plugins show `plugin:<id>` in `openclaw hooks list` and cant be enabled/disabled here. Enable/disable the plugin instead.
2026-01-18 05:56:59 +00:00
2026-01-17 01:31:39 +00:00
**Arguments:**
2026-01-31 21:13:13 +09:00
2026-01-17 01:31:39 +00:00
- `<name>`: Hook name (e.g., `session-memory`)
**Example:**
```bash
2026-01-30 03:15:10 +01:00
openclaw hooks enable session-memory
2026-01-17 01:31:39 +00:00
```
**Output:**
```
✓ Enabled hook: 💾 session-memory
```
**What it does:**
2026-01-31 21:13:13 +09:00
2026-01-17 01:31:39 +00:00
- Checks if hook exists and is eligible
- Updates `hooks.internal.entries.<name>.enabled = true` in your config
- Saves config to disk
2026-03-22 09:37:30 -07:00
If the hook came from `<workspace>/hooks/`, this opt-in step is required before
the Gateway will load it.
2026-01-17 01:31:39 +00:00
**After enabling:**
2026-01-31 21:13:13 +09:00
2026-01-17 01:31:39 +00:00
- Restart the gateway so hooks reload (menu bar app restart on macOS, or restart your gateway process in dev).
2026-01-17 07:08:04 +00:00
## Disable a Hook
2026-01-17 01:31:39 +00:00
```bash
2026-01-30 03:15:10 +01:00
openclaw hooks disable <name>
2026-01-17 01:31:39 +00:00
```
Disable a specific hook by updating your config.
**Arguments:**
2026-01-31 21:13:13 +09:00
2026-01-17 01:31:39 +00:00
- `<name>`: Hook name (e.g., `command-logger`)
**Example:**
```bash
2026-01-30 03:15:10 +01:00
openclaw hooks disable command-logger
2026-01-17 01:31:39 +00:00
```
**Output:**
```
⏸ Disabled hook: 📝 command-logger
```
**After disabling:**
2026-01-31 21:13:13 +09:00
2026-01-17 01:31:39 +00:00
- Restart the gateway so hooks reload
2026-04-04 08:46:24 +01:00
## Notes
- `openclaw hooks list --json`, `info --json`, and `check --json` write structured JSON directly to stdout.
- Plugin-managed hooks cannot be enabled or disabled here; enable or disable the owning plugin instead.
## Install Hook Packs
2026-01-17 07:08:04 +00:00
```bash
openclaw plugins install <package> # ClawHub first, then npm
openclaw plugins install <package> --pin # pin version
openclaw plugins install <path> # local path
2026-01-17 07:08:04 +00:00
```
Install hook packs through the unified plugins installer.
`openclaw hooks install` still works as a compatibility alias, but it prints a
deprecation warning and forwards to `openclaw plugins install`.
2026-01-17 07:08:04 +00:00
Npm specs are **registry-only** (package name + optional **exact version** or
**dist-tag**). Git/URL/file specs and semver ranges are rejected. Dependency
installs run with `--ignore-scripts` for safety.
Bare specs and `@latest` stay on the stable track. If npm resolves either of
those to a prerelease, OpenClaw stops and asks you to opt in explicitly with a
prerelease tag such as `@beta`/`@rc` or an exact prerelease version.
2026-01-17 07:08:04 +00:00
**What it does:**
2026-01-31 21:13:13 +09:00
2026-01-30 03:15:10 +01:00
- Copies the hook pack into `~/.openclaw/hooks/<id>`
2026-01-17 07:08:04 +00:00
- Enables the installed hooks in `hooks.internal.entries.*`
- Records the install under `hooks.internal.installs`
**Options:**
2026-01-31 21:13:13 +09:00
2026-01-17 07:08:04 +00:00
- `-l, --link`: Link a local directory instead of copying (adds it to `hooks.internal.load.extraDirs`)
- `--pin`: Record npm installs as exact resolved `name@version` in `hooks.internal.installs`
2026-01-17 07:08:04 +00:00
**Supported archives:** `.zip`, `.tgz`, `.tar.gz`, `.tar`
**Examples:**
```bash
# Local directory
openclaw plugins install ./my-hook-pack
2026-01-17 07:08:04 +00:00
# Local archive
openclaw plugins install ./my-hook-pack.zip
2026-01-17 07:08:04 +00:00
# NPM package
openclaw plugins install @openclaw/my-hook-pack
2026-01-17 07:08:04 +00:00
# Link a local directory without copying
openclaw plugins install -l ./my-hook-pack
2026-01-17 07:08:04 +00:00
```
2026-03-22 09:37:30 -07:00
Linked hook packs are treated as managed hooks from an operator-configured
directory, not as workspace hooks.
## Update Hook Packs
2026-01-17 07:08:04 +00:00
```bash
openclaw plugins update <id>
openclaw plugins update --all
2026-01-17 07:08:04 +00:00
```
Update tracked npm-based hook packs through the unified plugins updater.
`openclaw hooks update` still works as a compatibility alias, but it prints a
deprecation warning and forwards to `openclaw plugins update`.
2026-01-17 07:08:04 +00:00
**Options:**
2026-01-31 21:13:13 +09:00
2026-01-17 07:08:04 +00:00
- `--all`: Update all tracked hook packs
- `--dry-run`: Show what would change without writing
When a stored integrity hash exists and the fetched artifact hash changes,
OpenClaw prints a warning and asks for confirmation before proceeding. Use
global `--yes` to bypass prompts in CI/non-interactive runs.
2026-01-17 01:31:39 +00:00
## Bundled Hooks
### session-memory
Saves session context to memory when you issue `/new` or `/reset`.
2026-01-17 01:31:39 +00:00
**Enable:**
```bash
2026-01-30 03:15:10 +01:00
openclaw hooks enable session-memory
2026-01-17 01:31:39 +00:00
```
2026-01-30 03:15:10 +01:00
**Output:** `~/.openclaw/workspace/memory/YYYY-MM-DD-slug.md`
2026-01-17 01:31:39 +00:00
**See:** [session-memory documentation](/automation/hooks#session-memory)
2026-01-17 01:31:39 +00:00
### bootstrap-extra-files
Injects additional bootstrap files (for example monorepo-local `AGENTS.md` / `TOOLS.md`) during `agent:bootstrap`.
**Enable:**
```bash
openclaw hooks enable bootstrap-extra-files
```
**See:** [bootstrap-extra-files documentation](/automation/hooks#bootstrap-extra-files)
2026-01-17 01:31:39 +00:00
### command-logger
Logs all command events to a centralized audit file.
**Enable:**
```bash
2026-01-30 03:15:10 +01:00
openclaw hooks enable command-logger
2026-01-17 01:31:39 +00:00
```
2026-01-30 03:15:10 +01:00
**Output:** `~/.openclaw/logs/commands.log`
2026-01-17 01:31:39 +00:00
**View logs:**
```bash
# Recent commands
2026-01-30 03:15:10 +01:00
tail -n 20 ~/.openclaw/logs/commands.log
2026-01-17 01:31:39 +00:00
# Pretty-print
2026-01-30 03:15:10 +01:00
cat ~/.openclaw/logs/commands.log | jq .
2026-01-17 01:31:39 +00:00
# Filter by action
2026-01-30 03:15:10 +01:00
grep '"action":"new"' ~/.openclaw/logs/commands.log | jq .
2026-01-17 01:31:39 +00:00
```
**See:** [command-logger documentation](/automation/hooks#command-logger)
2026-01-18 05:24:47 +00:00
2026-01-18 10:10:05 +02:00
### boot-md
Runs `BOOT.md` when the gateway starts (after channels start).
**Events**: `gateway:startup`
**Enable**:
```bash
2026-01-30 03:15:10 +01:00
openclaw hooks enable boot-md
2026-01-18 10:10:05 +02:00
```
**See:** [boot-md documentation](/automation/hooks#boot-md)