01Chapter 1: How an agent acts: the loop and its tool callsAn AI coding agent does more than produce text. It reads files, edits code, and runs commands. A hook that blocks risky actions only makes sense once you know how those actions are requested and carried out. This chapter builds that working model. Later chapters add the hook itself.5 min read
02Chapter 2: What counts as a risky actionThis chapter assumes you can read basic shell commands and short Python scripts. It also assumes you know that an agent proposes tool calls, such as running a shell command or editing a file, and that the surrounding program carries them out. The previous chapter covered that loop. Here you decide w6 min read
03Chapter 3: Where hooks run in the agent lifecycleThis chapter places hooks inside the agent loop. You will learn which events a hook can attach to, what each point can and cannot control, and why the pre-action point is the one that matters for blocking risky actions.6 min read
04Chapter 4: The hook contract: event in, exit code and message outThis chapter assumes you can read and write JSON, run Python scripts from a shell, and understand that an AI coding agent calls tools such as a shell command or a file edit. Earlier chapters covered where hooks run in the agent lifecycle. This one covers the interface between the agent and the hook 6 min read
05Chapter 5: Scoping a hook with matchersThis chapter assumes you can read and write JSON, write a short Python script, and use a shell. It also assumes you know that an agent calls tools such as a shell command runner or a file editor. Earlier chapters covered the hook contract: the agent sends an event as JSON on stdin, and the hook answ6 min read
06Chapter 6: Blocking dangerous shell commandsShell commands are the riskiest tool call most agents can make. A single string can delete a directory, rewrite remote history, or drop a database table. This chapter builds a pre-action hook that inspects a proposed shell command and blocks it with exit code 2.5 min read
07Chapter 7: Protecting files and directoriesThis chapter assumes you can write a short Python script, read JSON, and run commands in a shell. It also assumes you have seen the hook contract from earlier chapters: the agent sends an event as JSON on stdin, and the hook answers with an exit code and a message on stderr. Exit code 2 blocks the a6 min read
08Chapter 8: Allow, deny, or ask the userThis chapter assumes you can write a small Python script, read JSON, and already know the hook contract from earlier chapters: the agent sends the tool-call event on stdin, and the hook answers with an exit code and a message. Here we look at the decision a hook makes after it inspects a call. A hoo5 min read
09Chapter 9: Telling the agent why it was blockedThis chapter assumes you can write a pre-action hook that reads a tool-call event from stdin and exits with code 2 to block it. It also assumes you know how to match a shell command against deny patterns. Here the focus is the message a blocked agent receives, because that message decides what the a5 min read
10Chapter 10: Failing closed when the hook breaksA pre-action hook is a safety check, and like any code it can crash, time out, or receive input it did not expect. This chapter covers what the agent does when that happens, why the default is often unsafe, and how to make the hook block the action instead.6 min read
11Chapter 11: Testing a hook with sample eventsThis chapter assumes you can write a small Python script, use a shell pipe, and read JSON. It also assumes you have a pre-action hook like the ones from earlier chapters: it reads a tool-call event from stdin and signals its decision with an exit code and a stderr message.5 min read
12Chapter 12: Logging decisions for reviewThis chapter assumes you have read the earlier chapters on the hook contract (event JSON on stdin, exit code and stderr message out), deny-pattern checks, and failing closed. You should be comfortable with Python and with reading JSON on the command line.5 min read
13Chapter 13: Timeouts and keeping hooks fastThis chapter assumes you can write a pre-action hook that reads a tool-call event as JSON from stdin and exits with code 2 to block. It also assumes you know what a matcher is. The chapter covers how much time a hook gets, what happens when it runs out, and how to keep a hook quick without making it6 min read
14Chapter 14: What hooks cannot guaranteeThis chapter assumes you can read the hook contract from earlier chapters: the event arrives as JSON on stdin, and the hook answers with an exit code and a stderr message. It also assumes you have written a deny-pattern check and a path check. Here you learn where those checks stop working, so you c6 min read
15Chapter 15: Layering hooks with permissions and sandboxesThis chapter assumes you can read a short Python script, work with JSON on stdin, and already know the hook contract from earlier chapters: the agent sends an event as JSON on stdin, and the hook answers with an exit code and a message. Exit code 2 blocks the call.6 min read