# Watch This If Your Coding Agent is Ignoring Your Rules (You Need Hooks)
<!--
ref: @content/youtube/cole-medin/watch-this-if-your-coding-agent-is-ignoring-your-rules-you-need-hooks
tags: [coding agents, hooks, deterministic guardrails, rules audit, security, Claude Code, agent configuration]
version: 2
updated_at: 2026-11-24T05:25:45.187Z
-->

**[Watch on YouTube](https://www.youtube.com/watch?v=msfMqW92Y8Q)**

# Watch This If Your Coding Agent is Ignoring Your Rules (You Need Hooks)

*Synthesized from Cole Medin, 2026-08-27.*

Cole Medin presents solo on hooks in AI coding agents: scripts that run on defined events and can block or log an action. He demonstrates with Claude Code and says the same primitive exists in Codex and other agents.

## Core Thesis
Cole argues that anything a coding agent must always do should be a hook rather than a rule, because rules and skills only guide the agent while a hook guarantees the step runs. He adds that long rule files dilute attention, so each rule should be checked and either kept as a judgment or moved into a hook.

## Key Insights
- **Five building blocks.** Rules, subagents, MCP servers, skills and hooks. Hooks are the only deterministic one, which he treats as a guarantee.
- **Stop hook for tests.** When the agent says it is done, a stop hook runs the test suite. If tests fail, the hook returns an error code that blocks the stop, and the agent is forced to fix the failures.
- **Pre-tool hook for secrets.** Before the agent reads a file, a hook matches `.env` paths and blocks the call with a message, and can point the agent to a `.env.example` instead. Its feedback becomes part of the agent's next step.
- **Exit codes.** The hook's exit code decides the outcome: pass lets the action proceed, a blocking code stops it and sends the message back to the agent. A broken hook script produces a different error that matters less.
- **Other events.** Session-start hooks can inject context such as a memory file; post-tool hooks log each action for audit; a hook can notify the user when the agent finishes.
- **Rules audit.** For each line of the global rules file, ask whether it names an event (becomes a hook) or encodes a judgment (stays a rule). Lines that are neither can be deleted.
- **Research cited.** He refers to studies in which adding more rules hurt agent performance, while a hook-style layer helped on most task types except complex ones.
- **Skill for creating hooks.** A skill walks the user through the guarantee they want and writes the hook and its settings entry. He used it with a sentence copied from his own rules.

## Actionable Takeaways
1. Find each rule that says "after X, do Y" and convert it into a stop hook.
2. Add a pre-tool hook that blocks reading secrets such as `.env`, and point the agent to an example file instead.
3. Use a post-tool hook to log actions if you want an audit trail for later review.
4. Audit the global rules file line by line and delete lines that are neither events nor judgments.
5. Use a hook-creation skill to draft hooks from plain-language rules, then check the generated settings.

## Notable Quotes
> "The most underrated part of every AI-based coding assistant is hooks." — Cole Medin

> "hooks are actions that you want to be guaranteed to execute whenever we encounter certain events in our encoding agent." — Cole Medin

> "The basic mental model I would have here is hooks, you either block something or you watch something." — Cole Medin

---

*Related: `@content/web/github/2026-11-25-claude-code-v2-1-332` · `@content/youtube/sean-kochel/opus-4-7-is-insanely-powerful-and-insanely-expensive` · `@content/youtube/yifan-bth/i-reverse-engineered-claude-code-learn-these-agent-tricks` · `@content/youtube/yifan-bth/claude-code-beat-cursor-4-2-heres-why-im-still-using-both` · `@content/youtube/yifan-bth/the-complete-claude-code-workflow-90-skip-this`*

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*