สถานะ: 🟢 Complete | อัพเดท: 2026-06-27

Hooks — Trigger Actions อัตโนมัติ

คืออะไร

Hooks คือ shell commands ที่รันอัตโนมัติเมื่อ Claude Code events เกิดขึ้น — เช่น ก่อน/หลัง tool call

Events หลัก

Eventรันเมื่อ
PreToolUseก่อน Claude รัน tool
PostToolUseหลัง Claude รัน tool
UserPromptSubmituser ส่ง message
StopClaude จบการทำงาน

ตัวอย่าง: 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