Hooks
Hook 是加速器和护栏——它们不替代计划、契约、审查或检查。每条路由由 event + routeId + matcher 寻址,护栏路由会 fail closed。
| Event | Route | Matcher | 做什么 |
|---|---|---|---|
SessionStart | .default | all sessions | 注入上一次会话的 resume 包 |
PreToolUse | .edit 🛡 | Edit / Write | 在计划获批前挂起编辑 |
PreToolUse | .subagent 🛡 | Task / Agent | 限定被委派工作的范围 |
PostToolUse | .edit | Edit / Write | 架构漂移 + 契约检查 |
PostToolUse | .bash | Bash | 追踪 shell 命令 |
PostToolUse | .always | all tools | 追加到事件追踪 |
UserPromptSubmit | .default | all prompts | 路由意图,展示计划状态 |
Stop | .default 🛡 | session stop | 写出下一个 handoff 包 |
🛡 = fail closed。
它们存放在哪里
Section titled “它们存放在哪里”可安装的源在 assets/hooks/;活动的运行时按 central-first 解析。用户级的 ~/.claude/settings.json 和 ~/.codex/hooks.json 是把每个事件派发进 harness 的宿主适配器。Repo-local 的 .claude/hooks/ 和 .codex/hooks.json 是遗留的清理目标——只有你自己的 custom-*.sh hook 会被保留。