สถานะ: 🟢 Complete | อัพเดท: 2026-06-27
Hooks — Trigger Actions อัตโนมัติ
คืออะไร
Hooks คือ shell commands ที่รันอัตโนมัติเมื่อ Claude Code events เกิดขึ้น — เช่น ก่อน/หลัง tool call
Events หลัก
| Event | รันเมื่อ |
|---|---|
PreToolUse | ก่อน Claude รัน tool |
PostToolUse | หลัง Claude รัน tool |
UserPromptSubmit | user ส่ง message |
Stop | Claude จบการทำงาน |
ตัวอย่าง: Auto-format หลัง Edit
{
"hooks": {
"PostToolUse": [{
"matcher": "Edit",
"hooks": [{"type": "command", "command": "prettier --write $CLAUDE_TOOL_RESULT_FILE"}]
}]
}
}Use Cases
- Inject context อัตโนมัติ (caveman mode, date, project status)
- Log ทุก tool call
- Block commands อันตราย
- Auto-lint หลัง edit