Module 6Episode 68 min
The whole of module 6 as one video. Jump to any chapter, or read the lesson it comes from.
What it teaches, what that builds on, and what it opens up next.
Builds on
Covered in this episode
An agent that can rename three hundred photos can also delete three hundred photos. Most of the time, it does exactly what you asked. But most of the time isn't good enough for delete. So who decides what an agent is allowed to do? Today, three ways to keep an agent in check. Permissions, hooks, and planning first.
Leila says, my agent keeps asking, allow this command? Forty times a day. I've started clicking yes without reading. Omid asks, who is asking you? The model wrote the command. But it can't run anything. So the harness is stopping it, before it runs. And what do forty yes clicks mean? Nothing. If it asked to delete the archive, she'd probably click yes to that too. So the trick is to let the routine things through, so the questions you do get are rare, and worth reading.
A permission is a decision the harness makes, before a tool call runs. Allow it. Ask you first. Or refuse. When an action is refused, the model is told, and usually tries another way. Nothing touched your computer.
A permission mode sets how careful the agent is overall. In Claude Code, you switch with shift tab. Default. Reading is allowed. It asks before editing, running commands, or using the network. Accept edits. File edits happen without asking. Commands still ask. Plan. It can look, but not change anything. Auto. A separate checker reviews each action, and lets the safe ones through. And bypass permissions. Everything allowed. Only ever in a throwaway sandbox, never with your own files.
Modes are broad. Rules are precise. They live in a settings file. The allow list. Running the tests, and git status, go ahead without a question. The deny list. Never read the file with the passwords. Never push code to the shared copy. Leila does that herself. Deny rules are checked first, then ask, then allow. So a deny always wins. You can't allow by accident what you meant to forbid. Rules decide which actions run. A sandbox limits what an action can reach. Which folders it can see, and whether it can use the network. Many agents run in a container in the cloud. A fresh, empty computer, thrown away afterwards. Nothing of yours is there to lose.
Four habits. One. Allow the routine, safe things. Two. Deny what must never happen. Write it once, rather than clicking no every time. Three. Read every question you do get. It now means something unusual. Four. Give a free hand only inside a sandbox.
Leila's instruction file says, after editing a report, always run the check. Most days, the agent does. But twice this week, it edited a report and moved on. Both times the report had an error. The instruction was there. Why wasn't it followed? The instruction file is text in the model's context. And the model predicts the next token from its context. So the instruction makes run the check very likely. But not certain. Especially in a long, busy session. An instruction is a strong push, not a guarantee. And she needs it every single time. So don't leave it to the model. Ask the harness. The harness doesn't predict. It just does it. From words, to code.
A hook is a command the harness runs automatically, at a fixed moment, every time. Whatever the model has in mind. User prompt submit. You've sent a message. Pre tool use. The model asked for a tool, and it hasn't run yet. A hook here can block it. Post tool use. A tool has just run. A hook can check or tidy up the result. Stop. The agent is about to say it's finished. A hook here can send it back to work.
Here's a hook that runs a small script before every shell command. The script looks at the command. If it contains r m dash r f, delete everything in a folder, it blocks it, with exit code two. The command never runs. And the reason goes back to the model, so it can try another way. And a hook that always tidies up. After every edit, it runs a formatter on the file. Leila's report check works the same way. After every edit, the check runs. Every time.
So, words or code? An instruction is words the model usually follows. A hook is code the harness always runs. Usually belongs in the instruction file. Always belongs in a hook. One word of care. A hook runs on your computer, with your permissions. Use only hooks you've read.
Four habits. One. Hooks for musts. Instructions for shoulds. Two. Make a stop hook your definition of finished. Run the tests, and send it back if they fail. Three. When you block, give a useful reason. The model reads it, and tries again. Four. Keep hooks fast. They run every time.
Leila asks her agent to update the quarterly report with the new sales figures. It gets to work at once. Thirty minutes. Forty edits. Three new charts. It rebuilt last year's report. Every edit was careful. The whole thing was wrong. When was the cheapest moment to find the mistake? Before the first edit. This is the shape of most agent mistakes. Not a slip in one step. A wrong idea of the job, carried out very well. A wrong plan costs a sentence to fix. A wrong report costs an afternoon.
Plan mode is a way of working where the agent may look, but not touch. It reads files, searches and thinks. Then it comes back with a plan. You read it, and correct it. Step one, open last year's report? Wrong report. Fixed in one line. Only when you approve does it start. In Claude Code, it's one of the permission modes. Shift tab, or start a message with slash plan.
Why does it work? A mistake is cheapest at the start. Every step built on it makes it costlier. A plan is easy to check. You can't easily review forty edits. You can read ten lines. And the plan stays in the context, keeping the work on track. For a big job, save it to a file. Two more habits make big jobs safer. Break the work into steps you can check. Update the sales table, then stop, so I can look. And know how to go back. Claude Code keeps checkpoints as it works. Slash rewind takes you back to an earlier point.
Four habits. One. Plan first for anything big, or unclear. Two. Read the plan for the wrong idea, not the wrong word. Three. Make the plan say how each step will be checked. Four. Undo early. Rewind and fix the plan, rather than patching mistakes on top.
Let's put it together. Permissions check every action before it runs. Allow the routine, deny what must never happen. Hooks are rules that always run. And a plan catches a wrong idea while it costs one sentence. Next time, many agents, many tools. Helper agents with their own context, and one standard plug for every tool. The lessons and quizzes for this course are free on knaph dot com. See you in the next episode.