Security · 2 min read · 19 October 2026

Guardrails for AI agents: hooks, not hopes

A rule in a prompt is a suggestion. I moved the rules I can't afford to break into hooks and narrow agents, then audited them and found the gap in my most-used setup.

A cartoon robot bowling down a lane with bumper rails, next to a padlocked envelope and a closed gate
5
hard rules the commit agent can't break
0
pushes the commit agent is allowed to make
1
regex hook between agents and env files

01 · Why hooks

Agents run shell commands faster than I can read them.

Three mistakes I can't afford: a secret read into a transcript, a commit pushed to main, an AI attribution line in a client's git history. A sentence in a prompt asks the model not to. A hook stops the command before it runs.

02 · env-guard

A pre-tool-use hook reads every shell command and refuses anything that touches an env file.

It matches .env and its variants as a word, so cat .env and source .env.local are blocked, while environment and dotenv pass. It over-blocks on purpose: there is no good reason for an agent to open an env file, so a false positive costs me one manual command. Read and edit deny rules sit beside it. One agent tool needed a JavaScript port, because its permission globs can't express word boundaries.

(^|[^A-Za-z0-9_.])\.env(\.[A-Za-z0-9_-]+)?([^A-Za-z0-9]|$)

03 · A commit agent that can't push

commit-warden decides whether work is a finished unit and commits it. Nothing else.

  • never pushes, not even with force
  • no AI attribution and no author override
  • no commits to main, master or develop
  • stages named paths only, never everything
  • one logical change per commit, message as type: description within 72 characters

It flags leftover console logs, TODOs and mixed concerns, and tells me how many commits are waiting to be pushed instead of pushing them.

04 · Attribution off at the source

This one came from a mistake.

An AI trailer slipped into a commit once and I had to amend and force-push to get it out. Now it's off in the settings, not just in a rule.

{
  "attribution": "",
  "includeCoAuthoredBy": false
}

05 · Memory that can only propose

My memory agent can read, but it can't write.

It drafts what's worth remembering, and the main agent checks it before anything is saved. It never records secrets or transcripts, and when nothing new happened it says so instead of inventing an entry. When sources disagree, the order is: current code, then a fresh check, then the snapshot, then history.

06 · The audit that humbled me

A guardrail you never test is a belief.

When I audited my setup, the profile I use most had no shell hook at all, even though my own notes said it did. Search and write tools weren't covered, and one profile had no guardrails. The rules were written well; the wiring had drifted.

Next storyiOS Safari's compositor ignores your z-index