Build with AI and trust what you make. Free guide, no signup

Hooks that always run

A prompt gives a tendency and a hook gives a guarantee. Where a rule must always hold, it belongs in code that runs every time.

Asking a model to always do something gives you a tendency. A hook gives you a guarantee, because it is code wired in at design time that runs every time and is never chosen or skipped. Where a rule has to hold without exception, that is the difference that matters.

Common questions

  1. What is the real difference between a hook and a prompt?
    A hook always runs, so where a deterministic outcome is required it is what ensures the thing is actually done. Hooks give a guarantee and prompts give a tendency, so choose a hook when the rule must always hold.
  2. Is there a cost difference too?
    Yes. Asking a model to make sure something is valid gives a probabilistic answer and consumes tokens. Asking a callback to validate it in code is an absolute pass or fail, and no tokens are consumed.
  3. What can I do before a tool runs?
    Look at the call the model is about to make and block or allow it. That lets you enforce a rule before the action happens rather than fixing the result afterwards, so it is a gate rather than a transform.
  4. And after a tool runs?
    Transform the result before it goes back to the model. Different tools answer in different dialects, so mapping them to one house shape in code means the model never does the conversion itself.
  5. Does the model choose whether a hook runs?
    No. A hook is wired in at design time and the model never selects it or skips it, it only ever sees the result. Nothing runs there unless you register a handler, and once you do, it fires every time.
  6. Is a hook allowed to make decisions?
    It transforms, it does not decide. Think of it as a function over the response that changes the shape rather than the meaning, and runs over every result rather than some of them.
  7. What does a hook policy need to look like?
    Precise enough to be code, because a hook cannot hold a vague rule the way a prompt can. Given this, when this, then that, defined up front as an absolute acceptance criterion.
  8. Is blocking a call enough on its own?
    No. A block on its own leaves the model holding a no with nowhere to go, so the criterion is not finished until you have named the route it should take instead.

Back to For developers. The craft around it is Working with AI.