要定義 Hooks,你需要編輯配置檔案(通常是 .claude/config.json 中的 hooks 字段)。
配置結構
{
"hooks": {
"PostToolUse": [
{
"matcher": "Edit",
"hooks": [
{
"type": "command",
"command": "npm run lint"
}
]
}
]
}
}
這個配置的意思是:
- 事件:
PostToolUse(工具使用後) - 匹配器:
Edit(僅當使用的工具是 'Edit' 時觸發) - 動作:執行命令
npm run lint
匹配器 (Matcher)
你可以指定 Hook 針對哪些工具觸發:
"*":匹配所有工具"Edit":僅匹配檔案編輯"Bash":僅匹配終端命令["Edit", "Bash"]:匹配多個工具