进阶 / Hooks / MCP

Kition Hooks 深度指南:事件、过滤、副作用

Hooks 是 Kition Agent 的"中间件层" — 在工具调用前后插入代码,控制能做什么、留下什么记录。

Kition 团队·2026年7月24日·8 分钟阅读

5 种 Hook 时机

  • PreToolUse — 工具调用前;可以阻断或改 args
  • PostToolUse — 工具调用后;通常用于审计 / 通知
  • UserPromptSubmit — 用户提交 prompt 前;可以注入上下文
  • Stop — Agent 自然结束;可以做收尾
  • Notification — Agent 需要用户输入 — 可以推到外部系统

一份阻断 Bash 出站请求的 Hook

{
  "PreToolUse": [{
    "matcher": "Bash",
    "hooks": [{
      "type": "command",
      "command": "node check-no-curl.js"
    }]
  }]
}

设计原则

  • Pre 用于"防",Post 用于"记"
  • 不要在 Hook 里做长时间操作(同步运行)
  • 失败的 Hook 默认阻断 Agent — 注意 timeout
  • 把 Hook 自身的日志写进 Vault,方便复盘

下载 Kition

本地优先的 AI 工作空间。Markdown 文档、结构化数据表、AI Agent,全部跑在你自己的电脑上。