Building the Brain: How Hooks Turn an LLM into an Agent
In the last post, we looked inside the "Black Box" and saw the chaos. Without structure, an LLM is just a probabilistic engine. It takes a "random walk" through a Markov chain of potential actions. There is no guarantee of how it will behave the next time. This is the difference between an LLM and an Agent. An LLM is just the engine. It gets lucky sometimes, and other times it fails. An Agent is that engine plus a Brain. ### The Agent's Brain: The `.claude/` Directory When you look at the Template Agent we are building, you'll see a `.claude/` directory. This isn't just a folder for settings. This is where your agent's knowledge, instructions, and context live. And the most critical part of this brain? Hooks. ### What Are Hooks? Technically, hooks are just logic files that live in your agent's brain. But conceptually? Hooks are your agent's learned reflexes. They are the dynamic pathways that sit *between* the LLM's decisions. They listen for specific events—like when you ask a question, or before the agent uses a tool—and they inject the best directive or instruction right into the context. Previously, with our Markov chain model with key states (e.g., Respond, Think, Tool call (16 built-in), Ask for permission, Create a task, Compact, stop), the transitions were mainly probabilistic and oversensitive to the context. But, with hooks placed around all these events/actions, organize all the transitions and a space to define reproducible behavior. As you would expect from a human personal assistant to learn and grow with experience, the hook layer is where the agent will grow. (and some other places -- a topic for later) Instead of the LLM guessing what to do, the Hook ensures it knows what to do. ### Creating Stable Directions Imagine you want your agent to *always* check your specific style guide before drafting an email. * The LLM Way (Getting Lucky): You ask it nicely in the prompt. "Please check my style guide." Maybe it remembers. Maybe it hallucinates. You are relying on luck.