openclaw - 💡(How to fix) Fix Feature: Hook 系统(生命周期事件钩子)

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
RAW_BUFFERClick to expand / collapse

问题

当前 OpenClaw 的行为约束完全依赖 SOUL.md 中的"铁律"文本规则。虽然有效,但存在两个局限:

  1. 铁律只能约束"记得"做的事,无法强制执行
  2. 铁律膨胀(目前 20 条),维护成本上升

来源

Claude Code 源码(Plugin 系统)支持 26 种 hook 类型: PreToolUse, PostToolUse, PostToolUseFailure, PermissionDenied, Notification, UserPromptSubmit, SessionStart, SessionEnd, Stop, StopFailure, SubagentStart, SubagentStop, PreCompact, PostCompact, PermissionRequest 等

建议

第一阶段:支持核心 hook

  • onMessageReceived — 消息预处理(如链接提取、意图识别)
  • onBeforeReply — 回复前质量检查(对应铁律 #12 输出质量)
  • onSubagentSpawn — spawn 前输入校验(对应铁律 3.1)
  • onToolCall — 工具调用前后处理

实现方式:

  • hook 定义为函数或脚本,注册在 skills/hooks/ 目录
  • 从 Claude Code 借鉴 discriminated union 错误类型

参考

  • Claude Code 源码:src/plugin/ hooks 系统
  • 设计文档:OpenClaw workspace self-improving/design-hooks.md

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - 💡(How to fix) Fix Feature: Hook 系统(生命周期事件钩子)