hooks.json.template 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // ============================================================================
  2. // hooks.json.template — starter Claude Code plugin hooks file (JSONC)
  3. // ----------------------------------------------------------------------------
  4. // COPY THIS, then STRIP EVERY COMMENT: the live `hooks/hooks.json` must be
  5. // STRICT JSON (no `//` lines, no trailing commas). Claude Code does NOT parse
  6. // comments. Save the comment-free result as `hooks/hooks.json` in your plugin.
  7. //
  8. // Validate after editing:
  9. // python skills/claude-code-ops/scripts/validate-hooks-json.py hooks/hooks.json
  10. //
  11. // Contract source of truth: skills/claude-code-ops/references/hooks-reference.md
  12. // ----------------------------------------------------------------------------
  13. // Rules this template demonstrates:
  14. // * Shape is { "hooks": { <Event>: [ <matcher-group>, ... ] } }.
  15. // * Event keys must be in the 30-event catalog (PreToolUse, PostToolUse,
  16. // SessionStart, ... — see hooks-reference.md).
  17. // * "matcher" is a STRING, never an array. Use "Edit|Write", not ["Edit","Write"].
  18. // A "*"/""/omitted matcher matches everything.
  19. // * Command paths use ${CLAUDE_PLUGIN_ROOT} (plugin install dir) so they
  20. // resolve no matter the cwd. Project hooks use ${CLAUDE_PROJECT_DIR}.
  21. // ============================================================================
  22. {
  23. "hooks": {
  24. // Before every Bash tool call — e.g. block/flag dangerous commands.
  25. "PreToolUse": [
  26. {
  27. "matcher": "Bash",
  28. "hooks": [
  29. {
  30. "type": "command",
  31. "command": "bash \"${CLAUDE_PLUGIN_ROOT}/hooks/pre-bash-check.sh\"",
  32. "timeout": 10
  33. }
  34. ]
  35. }
  36. ],
  37. // After a file is written or edited — note the string "Edit|Write" matcher.
  38. "PostToolUse": [
  39. {
  40. "matcher": "Edit|Write",
  41. "hooks": [
  42. {
  43. "type": "command",
  44. "command": "bash \"${CLAUDE_PLUGIN_ROOT}/hooks/post-edit-format.sh\"",
  45. "timeout": 30
  46. }
  47. ]
  48. }
  49. ],
  50. // At session start — no matcher needed (this event takes none).
  51. "SessionStart": [
  52. {
  53. "hooks": [
  54. {
  55. "type": "command",
  56. "command": "bash \"${CLAUDE_PLUGIN_ROOT}/hooks/session-start.sh\"",
  57. "timeout": 30
  58. }
  59. ]
  60. }
  61. ]
  62. }
  63. }