claude-hooks
claude-code Hooks — shell commands the harness runs at lifecycle events (PostToolUse, Notification, SessionStart, etc.). Per tw93: best understood not as “automation,” but as the place to put things you don’t want the model deciding on case-by-case. They convert ad-hoc model judgment into deterministic flow (2026-04-27-claude-code-architecture-governance-engineering).
What belongs in Hooks
- Block edits to protected files.
- Post-Edit lint / format / lightweight check.
SessionStartcontext injection (current Git branch, env vars).- Completion notifications (e.g. macOS
osascriptnotification).
What doesn’t
- Anything requiring model-style multi-step reasoning.
- Long-running business processes.
- Decisions that need weighing alternatives — those belong in a Skill or Subagent.
Truncate the output
Hook output also enters the context window — defeating the point if cargo check dumps thousands of lines. Always cap (e.g. | head -30). For systematic command-output rewriting across many commands, the source mentions RTK (Hook-based command wrapper) (context-engineering).
Example: per-language post-edit checks
From kaku‘s mixed Rust + Lua codebase (2026-04-27-claude-code-architecture-governance-engineering):
{
"hooks": {
"PostToolUse": [
{ "matcher": "Edit", "pattern": "*.rs",
"hooks": [{ "type": "command",
"command": "cargo check 2>&1 | head -30",
"statusMessage": "Checking Rust..." }] },
{ "matcher": "Edit", "pattern": "*.lua",
"hooks": [{ "type": "command",
"command": "luajit -b $FILE /dev/null 2>&1 | head -10",
"statusMessage": "Checking Lua syntax..." }] }
]
}
}
Saves ~30–60s per fix-up cycle in a 100-edit session — couple of hours over a heavy day.
Three-layer composition
Hooks compose with the other two governance layers:
| Layer | Role |
|---|---|
| claude-md | declares the rule (“must pass tests and lint before commit”) |
| [[claude-skills | Skill]] |
| Hook | executes the hard check on the critical path — blocks if it fails |
Cleanliness reminder
Hooks live in .claude/settings.json under allowedTools and hooks lists. Periodically audit — stale rm -rf entries from one-time approvals are the kind of thing that bites later (2026-04-27-claude-code-architecture-governance-engineering).