concept · created Apr 27, 2026 · updated Apr 27, 2026

claude-hooks

#claude-code#deterministic-control#governance

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.
  • SessionStart context injection (current Git branch, env vars).
  • Completion notifications (e.g. macOS osascript notification).

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:

LayerRole
claude-mddeclares the rule (“must pass tests and lint before commit”)
[[claude-skillsSkill]]
Hookexecutes 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).

Referenced by 12

2026-04-27-claude-code-architecture-governance-engineering 2026-04-27-harness-engineering-codex-agent-first harness-why-it-matters-now agent-sandboxing architectural-invariants context-engineering harness six-layer-agent-architecture verifier-loop anthropic claude-code kaku
esc