~/VibeHandbook
$39

Agent Tooling

docs.claude.com

Hooks

What it is

A hook is your own command that runs automatically at a specific point in an agent's lifecycle — before it runs a shell command, after it edits a file, when a session starts, and so on. Hooks let you observe and control what the agent does using ordinary scripts, rather than trusting it to remember a rule on its own. They are the enforcement layer of a coding harness.

Strengths

  • Deterministic: a hook runs every time, so a rule can't be forgotten or argued away.
  • Written as plain shell or scripts, so you can do anything your machine can do.
  • Can block an action, not just log it — a pre-command hook can refuse a dangerous command.
  • Great for guardrails: format on save, run tests after edits, scan for secrets before commit.

Trade-offs

  • A hook is real code that runs automatically, so a buggy one can break the workflow.
  • Slow hooks add latency to every triggering event.
  • They fire on patterns, so a too-broad hook can interfere with legitimate actions.
  • More setup and another place to look when something behaves unexpectedly.

When to use it

Use hooks when you want a hard guarantee about agent behavior — auto-formatting, mandatory test runs, blocking destructive commands, or logging every action — rather than relying on the agent to comply voluntarily.

Vibe coding fit

Hooks are how you keep an agent safe while letting it move fast. The agent proposes; the hook enforces. A "before run" hook that blocks rm -rf or an "after edit" hook that runs the type checker turns a freewheeling assistant into one that physically can't skip your guardrails.

// run the formatter after every file edit
{
  "hooks": {
    "PostToolUse": [
      { "matcher": "Edit", "command": "npx prettier --write $FILE" }
    ]
  }
}