Stop Hook
A stop hook is a stored instruction that is automatically executed as soon as an AI assistant finishes its work on a task. It can be used to trigger completion checks, cleanup work, or notifications without a human having to initiate them every time.
Modern AI assistants don’t just write text, they carry out entire work assignments. They change files, run programs, and report at the end: done. This is exactly the point where a stop hook comes in. A hook is an attachment point: a place in the process where you can insert your own commands. The stop hook is the attachment point for the end. As soon as the assistant completes its response, the stored command is automatically started. The name comes from the English word “stop”, meaning to halt or cease.
Why the end of a task is the critical moment
AI assistants tend to declare work finished that isn’t actually finished. They write code that doesn’t compile. They change one file and forget a second one that depends on it. A human would notice this upon review. But with hundreds of automatic runs per day, nobody checks every single time.
A stop hook makes this check mandatory. It isn’t phrased as a request in the prompt, but as a fixed rule in the system. A prompt is an instruction in ordinary language that the model may or may not follow. A hook, on the other hand, is executed by the software, regardless of what the model currently considers reasonable. That’s the crucial difference: requests can be ignored, hooks cannot.
Many stop hooks can even reject the result. If the check finds an error, the message goes back to the assistant, and it keeps working. This creates a loop of working, checking, and revising. The assistant is only allowed to truly stop once the check is satisfied.
From trigger to executed command
Technically, the stop hook is stored in a configuration file. This is a simple text file with settings that the program reads at startup. It specifies which event should trigger the hook and which command must then run. The command is usually a small script, meaning a short list of commands for the computer.
The process is always the same. The assistant finishes its work step. The software intercepts this event before the response goes to the user. It starts the stored script and passes it information about the process, such as which files were changed. The script ultimately returns a value: zero means everything is fine, anything else means there’s a problem.
A typical example from software development: the stop hook starts the project’s automated tests. If they all pass, the session ends. If a test fails, the assistant receives the error message and must make corrections. It’s important to have an upper limit on the number of retries here. Otherwise, the assistant can get stuck in an infinite loop, repeatedly waking itself back up.
Stop hooks in development tools and agent systems
Stop hooks are most commonly encountered in AI coding tools like Claude Code, Cursor, or similar assistants. There, developers use them for formatting, testing, and security checks. Some also simply have a message sent to their phone at the end, once a long task has completed.
The term also comes up in the context of so-called agents. These are AI systems that work through tasks independently over extended periods of time. The more autonomously a system acts, the more important fixed checkpoints become. Stop hooks are among the simplest of these and are therefore often cited as an example of practical AI safety.
A common misconception is that a stop hook would stop the assistant. The opposite is closer to the truth. It reacts to the halt and can even set the work back in motion again. Anyone looking for a tool that aborts a running AI action beforehand needs a different attachment point, one that takes effect before execution.