Sub topic 2
What counts as a risky action
This 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 disabled.
Risk comes from the effect, not the tool
An agent acts through tool calls such as running a shell command, writing a file, or calling a network service. A tool is not risky by itself. ls and rm both go through the shell tool, but only one can destroy work.
Judge an action on three questions:
- Can it be undone? Deleting a tracked file is recoverable from git. Deleting an untracked file, or dropping a database table, may not be.
- How far does it reach? Editing one test file is local. Rewriting shared branch history or changing production infrastructure affects other people.
- Does it expose something? Reading a secret is not destructive, but printing it into the conversation or sending it to a remote host is a leak.
Actions that are hard to undo, wide in reach, or exposing are the ones worth a hook.
Common categories
| Category | Example action | Why it is risky |
|---|---|---|
| Destructive file operations | `rm -rf /`, `rm -rf ~` | Data loss that cannot be reversed |
| History rewriting | `git push --force`, `git reset --hard` | Overwrites work, including other people's commits |
| Data destruction | `DROP TABLE users` | Permanent loss in a live database |
| Secret access | Reading `.env`, private keys | Credentials may enter logs or model context |
| Protected writes | Editing `.git/` or `infra/prod/` | Corrupts the repository or changes live systems |
| Outbound transfer | `curl` posting local files to a URL | Data leaves your machine |
| Privilege changes | `chmod -R 777`, `sudo` | Widens access beyond what the task needs |
The list is a starting point. Your own project decides what belongs on it. A script that deploys to production is harmless in one repository and a serious hazard in another.
Separate the actions you must stop from the ones you only watch
Not every risky action deserves a hard block. Sort them into three groups:
- Always block. The action is almost never correct for an agent, such as
rm -rf /. - Ask first. The action is sometimes legitimate but needs a person to confirm, such as a force push to your own feature branch.
- Log only. The action is common and low impact, but you want a record of it.
Chapter "Allow, deny, or ask the user" covers how a hook expresses these decisions. For now, tag each risk you find with one of the three labels.
Pitfalls when defining risk
- Listing tools instead of effects. Blocking the whole shell tool makes the agent useless. Describe the harmful pattern instead.
- Forgetting indirect routes. An agent can delete files with
find -delete, a Python one-liner, or a build script. A rule that only knowsrmmisses these. - Treating the list as complete. You will not predict every harmful command. Later chapters cover why hooks are one layer of defense and not a guarantee.
Exercise
An agent proposes git push --force origin feature/login. Using the three questions (undoable, reach, exposure) and the three groups (always block, ask first, log only), where would you place this action, and why?
Show answer
Place it in "ask first". A force push is hard to undo because it overwrites remote history, but on a personal feature branch the reach is limited to you and any collaborators on that branch. It is therefore sometimes legitimate. The same command aimed at a shared branch such as main would move to "always block", because its reach is wide.