跳到正文
Ado· @adocomplete · X·精选AI 评分66

Anthropic 员工讲解 Claude Code prompt hook 的配置与用法

AI 导读

Anthropic 开发者关系的 Ado 分享 Claude Code 的 prompt hook 用法:当规则不是机械判断时,hook 输入加一句描述会发给一个小型 Claude 后台模型,返回 { ok, reason }。

推荐理由

作者以亲历用法讲清 prompt hook 与 command hook 的分工,并给出 PreToolUse 和 Stop 的具体配置思路,可迁移到自己的 Claude Code 工作流。

正文 · 原文

Command hooks are great when a rule is mechanical. "Is this command touching production data?" is not. A prompt hook sends the hook input plus your sentence to a Claude model (the small background one by default) and gets back { ok, reason }.

On PreToolUse, add continueOnBlock: true so the reason goes back to Claude as a tool error and it adjusts, instead of ending the turn. On Stop, ok: false makes the reason Claude's next instruction, so it keeps working.

How I use it:

  • PreToolUse on Bash: "Block anything that deletes or rewrites shared data"
  • Stop: "Did Claude run the tests after its last edit?"

来源:Ado · x.com