Prompt Engineering · ~7 min
Every lever in this course raises the odds of compliance. None guarantees it. For the rules that must never fail, stop asking — and move them outside the model entirely.
Prompt instructions are probabilistic. Under task pressure — context filling, attention diverted — compliance degrades toward the ceiling and the agent reverts to training defaults. Hooks are deterministic: a pre-command hook runs outside the agent's context, and the model cannot overrule it.
Reach for a hook only when all three hold; otherwise the rule stays in the prompt.
| Hook (deterministic) | Prompt (probabilistic) |
|---|---|
Block git push --force to main | "Prefer composition over inheritance here" |
Enforce pnpm, block npm install | "Raise a concern before editing auth code" |
| Block writes to secrets files | "Write a test for business-logic changes" |
The left column is absolute, binary, and opposed by a prior. The right needs judgement and context a hook can't inspect — intent, trade-offs, architectural fit.
Injection resistance. An injected instruction can change what the agent tries to do, not
what a hook allows. Without a hook, a prompt-injection
payload and your CLAUDE.md compete in the same reasoning loop — non-deterministic. With a hook,
PreToolUse fires before execution — deterministic.
Zero context cost. Prompt rules occupy context and compete for attention; moving an absolute rule
to a hook both improves reliability and frees the budget. And the idea predates AI agents — a pre-commit
hook enforces its rule regardless of origin, whether a developer, an agent, or a script triggered it.
A hook is deterministic at the tool-call boundary — not beyond it. Four gaps narrow the rule (hooks-vs-prompts):
rm and the model reaches for /bin/rm or a
truncating Write; each call is judged alone.--force on a personal branch from a dangerous one.So rules that must hold everywhere also need CI or git-level gates. The hook is one layer, not the whole wall.
Determinism cuts both ways. A hook that's too aggressive blocks legitimate work, and false positives from over-blocking can cost more than the occasional non-compliance you were preventing. When a rule needs judgement to apply — "prefer X when working in Y" — that judgement is exactly what a hook lacks. Keep it in the prompt, where polarity (Lesson 2) governs how you phrase it.
Retrieval practice — recall, don't peek
Question 1A rule belongs in a hook only when it is non-negotiable, binary, and…
Question 2Against prompt injection, a hook protects by bounding…
Question 3"Intent-blindness" means a hook cannot…
Question 4Contextual guidance like "prefer X when in Y" stays in the prompt because a hook…
Question 5 · spaced recall from Lesson 10Event-driven reminders are injected as user messages, rather than added to the system prompt, mainly to…