OpenClawSkills
GitHub
CLI 参考 • 5 分钟阅读

钩子

“openclaw hooks”(代理挂钩)的 CLI 参考

管理代理挂钩(事件驱动的自动化命令,如 ''/new''、''/reset'' 和网关启动)。

相关:

- 挂钩:''挂钩''

- 插件挂钩:''插件''

Tutorial.step

列出所有钩子

Bash
openclaw hooks list

列出从工作区、托管目录和捆绑目录中发现的所有挂钩。

选项:

- ''--eligible'':仅显示符合条件的挂钩(满足要求)

- ''--json'':输出为 JSON

- ''-v, --verbose'':显示详细信息,包括缺少的要求

输出示例:

示例(详细):

Terminal
Hooks (4/4 ready)

Ready:
  🚀 boot-md ✓ - Run BOOT.md on gateway startup
  📝 command-logger ✓ - Log all command events to a centralized audit file
  💾 session-memory ✓ - Save session context to memory when /new command is issued
  😈 soul-evil ✓ - Swap injected SOUL content during a purge window or by random chance

显示不合格挂钩的缺失要求。

Bash
openclaw hooks list --verbose

示例(JSON):

返回结构化 JSON 以供编程使用。

Bash
openclaw hooks list --json

ReferenceCliHooksPage step 01: P11

Tutorial.step

获取钩子信息

Bash
openclaw hooks info <name>

显示有关特定钩子的详细信息。

参数:

- ''<name>'': Hook name (e.g., ''session-memory'')

选项:

- ''--json'':输出为 JSON

Bash
openclaw hooks info session-memory

示例:

Terminal
💾 session-memory ✓ Ready

Save session context to memory when /new command is issued

Details:
  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/hooks#session-memory
  Events: command:new

Requirements:
  Config: ✓ workspace.dir
Tutorial.step

检查 Hooks 资格

Bash
openclaw hooks check

显示挂钩资格状态摘要(准备就绪与未准备就绪的数量)。

选项:

- ''--json'':输出为 JSON

Terminal
Hooks Status

Total hooks: 4
Ready: 4
Not ready: 0
Tutorial.step

启用钩子

Bash
openclaw hooks enable <name>

通过将特定挂钩添加到您的配置 (''~/.openclaw/config.json'') 来启用它。

''Note:'' Hooks managed by plugins show ''plugin:<id>'' in ''openclaw hooks list'' and

无法在此处启用/禁用。而是启用/禁用插件。

参数:

- ''<name>'': Hook name (e.g., ''session-memory'')

Bash
openclaw hooks enable session-memory

示例:

Terminal
✓ Enabled hook: 💾 session-memory

输出:

它的作用:

- 检查钩子是否存在并且符合条件

- Updates ''hooks.internal.entries.<name>.enabled = true'' in your configuration

- 将配置保存到磁盘

启用后:

Tutorial.step

禁用钩子

Bash
openclaw hooks disable <name>

通过更新您的配置来禁用特定的挂钩。

参数:

- ''<name>'': Hook name (e.g., ''command-logger'')

Bash
openclaw hooks disable command-logger

示例:

Terminal
⏸ Disabled hook: 📝 command-logger

输出:

禁用后:

Tutorial.step

安装钩子

Bash
openclaw hooks install <path-or-spec>

从本地文件夹/存档或 npm 安装挂钩包。

它的作用:

- Copies hook package to ''~/.openclaw/hooks/<id>''

- 启用 ''hooks.internal.entries.*'' 中安装的挂钩

- 在 ''hooks.internal.installs'' 下记录安装

选项:

- ''-l, --link'':链接本地目录而不是复制(将其添加到 ''hooks.internal.load.extraDirs'')

''支持的档案:'' ''.zip''、''.tgz''、''.tar.gz''、''.tar''

Bash
openclaw hooks install ./my-hook-pack


openclaw hooks install ./my-hook-pack.zip


openclaw hooks install @openclaw/my-hook-pack


openclaw hooks install -l ./my-hook-pack
Tutorial.step

更新挂钩

Bash
openclaw hooks update <id>
openclaw hooks update --all

更新已安装的钩子包(仅限 npm 安装)。

选项:

- ''--all'':更新所有跟踪的钩子包

- ''--dry-run'':显示无需编写即可更改的内容

Tutorial.step

捆绑挂钩

#

Tutorial.step

会话内存

当您发出 ''/new'' 时,将会话上下文保存到内存中。

启用:

Bash
openclaw hooks enable session-memory

输出: ~/.openclaw/workspace/memory/YYYY-MM-DD-slug.md

参见: 会话内存文档

#

Tutorial.step

命令记录器

将所有命令事件记录到集中审核文件中。

启用:

Bash
openclaw hooks enable command-logger

输出: ~/.openclaw/logs/commands.log

查看日志:

Bash
tail -n 20 ~/.openclaw/logs/commands.log


cat ~/.openclaw/logs/commands.log | jq .


grep '"action":"new"' ~/.openclaw/logs/commands.log | jq .

参见: 命令记录器文档

###灵魂邪恶

在清除窗口期间或随机地用 ''SOUL_EVIL.md'' 交换注入的 ''SOUL_EVIL.md'' 内容。

Bash
openclaw hooks enable soul-evil

参见: 灵魂邪钩文档

#

Tutorial.step

启动 md

网关启动时(通道启动后)运行 ''BOOT.md''。

活动: gateway:startup

启用:

Bash
openclaw hooks enable boot-md

参见: boot-md 文档