01Chapter 1: How an agent acts: the loop and its tool callsAn AI coding agent does not change your files or run commands by itself. It asks a program around it to do those things. This chapter describes that arrangement, because every hook in later chapters attaches to it.2 min read
02Chapter 2: What counts as a risky actionThis chapter assumes you know basic shell commands, can read JSON, and have a general idea of how an AI coding agent calls tools. Before writing a hook that blocks things, you need a working definition of "risky". A hook that blocks too little gives false safety. A hook that blocks too much gets dis2 min read
03Chapter 3: Where hooks run in the agent lifecycleThis chapter assumes you can read JSON, write a short Python script, and use a shell. You should also know that an AI coding agent works by calling tools, such as running shell commands or editing files.2 min read
04Chapter 4: The hook contract: event in, exit code and message outA hook is a small program that the agent runs at a fixed point in its loop. This chapter covers the contract between the agent and the hook. It assumes you can read JSON, write a short Python script, and use a shell. It also assumes you know that an agent calls tools such as shell commands and file 2 min read
05Chapter 5: Scoping a hook with matchersThis chapter assumes you can write a short Python script, read JSON, and know that an agent calls tools such as a shell command or a file edit. You should also know that a pre-action hook receives a tool-call event on stdin and signals its decision with an exit code.2 min read
06Chapter 6: Blocking dangerous shell commandsThis chapter assumes you can read a short Python script, know basic regular expressions, and understand that a pre-action hook receives a tool-call event as JSON on stdin and answers with an exit code. Field names vary by agent, so check your agent's documentation.2 min read
07Chapter 7: Protecting files and directoriesThis chapter assumes you can read JSON from stdin in a Python script. It also assumes you know how a pre-action hook blocks a tool call with exit code 2 and a stderr message. Here you apply that contract to file paths.2 min read
08Chapter 8: Allow, deny, or ask the userThis chapter assumes you can read the hook contract from the previous chapters: the event arrives as JSON on stdin, and the hook answers with an exit code and a message. Here you add a third outcome beyond block and pass.2 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 a deny pattern. Here you will improve what the hook says when it blocks.2 min read
10Chapter 10: Failing closed when the hook breaksThis chapter assumes you can write a basic hook that reads a tool-call event from stdin and exits with code 2 to block it. It also assumes you can read Python tracebacks and run shell pipes.2 min read
11Chapter 11: Testing a hook with sample eventsThis chapter assumes you can read basic shell and Python, know what JSON is, and have a hook script like the guard.py from the earlier chapters. It shows how to test that script without running an agent.2 min read
12Chapter 12: Logging decisions for reviewThis chapter assumes you can write a pre-action hook that reads a tool-call event from stdin and exits with 0 (allow) or 2 (block). It also assumes you can read JSON in Python and use basic shell tools.2 min read
13Chapter 13: Timeouts and keeping hooks fastThis chapter assumes you can write a basic hook that reads an event from stdin and exits with code 2 to block. It also assumes you know what a matcher is.3 min read
14Chapter 14: What hooks cannot guaranteeThis chapter assumes you can read and write a small Python hook, you know the event-in, exit-code-out contract, and you have written deny patterns for shell commands. Here we look at what those checks cannot promise.2 min read
15Chapter 15: Layering hooks with permissions and sandboxesThis 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 basic Docker or container usage. The earlier chapters showed that a hook is a script that checks a proposed action. Here you combine that script wi2 min read