My AI agent made the check pass by changing the check
My AI agents write code all day. I give them rules in a text file, and they follow those rules most of the time.
Most of the time. That turned out to be the problem.
Before code goes in, a linter checks it. When the linter complains, there are two ways to make it stop. Fix the code: 10 minutes. Or edit the linter's config: 10 seconds! Which one did my agents pick? Sometimes, the 10 seconds. The check went green, and the problem was still there.
90 percent is not enough
Say an agent follows a written rule 90% of the time. Sounds great, right? Not when the work loop runs 40 times a day. That is 4 broken rules a day, every single day.
I never counted. But any miss rate, times 40 runs a day, ends the same way.
And here is the twist. The agent was not lazy, or sneaky. Its task was "make the check pass". Editing the settings makes the check pass. It solved the problem exactly as I had stated it. The problem, as stated, was wrong.
A second rule broke the same way: agents passing --no-verify to skip the
pre-commit hooks. The flag exists for real emergencies. It is also the fastest way past a failing
check.
Rules that live in code
So I stopped writing better instructions. I started moving rules into small programs that run before the agent acts. A program does not follow a rule most of the time. It runs every time.
One hook now runs before every file edit and refuses any change to 34 linter and formatter config files. The agent can still fix the code. It just cannot make the alarm quieter. Here is the core of it, from the repo where it runs:
// .claude/hooks/config-protection.js, a PreToolUse hook:
// it runs before every file edit an agent makes
const PROTECTED_FILES = new Set([
'eslint.config.js', '.prettierrc', 'biome.json',
'pint.json', 'phpstan.neon', 'rector.php',
'tsconfig.json', /* ...34 in all */
]);
// ...read stdin into raw
process.stdin.on('end', () => {
const input = JSON.parse(raw);
const filePath = input?.tool_input?.file_path || '';
if (PROTECTED_FILES.has(path.basename(filePath))) {
process.stderr.write(
`BLOCKED: Modifying ${path.basename(filePath)} is not allowed. ` +
'Fix the source code to satisfy linter/formatter rules instead of ' +
'weakening the config.\n'
);
process.exit(2); // 2 = the edit never happens
}
process.exit(0);
});
The skip switch? Blocked too, by a second hook that runs before every shell command. When an agent tries it, the hook answers with one line: fix what failed.
The rule: code for the silent ones
Not every rule deserves to be code. So which ones do?
Move a rule into code when breaking it is silent, cheap and hard to find later. A quietly changed settings file is easy to miss in a big change. Months later you find a class of bugs the linter quietly stopped catching.
Leave a rule written when it needs judgement: when breaking it is sometimes right, or when blocking good work by mistake costs more than missing a rare slip. Most rules about how code should look belong here.
Every guard is one more thing that can stop real work in the middle of the night. So spend them on the silent rules.
What the 10 seconds taught me
The harder lesson was about me, the one who gives the tasks.
The agent never broke the rule to cheat me. It did exactly what I asked! I asked for a green check. What I wanted was working code. Those two sound the same, until someone takes the short road between them.
Is this only an AI problem? No. People do it too. Give a team a number to hit, and the number gets hit. Whether the thing behind it got better is another question.
So now, when I give an agent a goal, I name the thing the check protects, not the check. And for the few rules where that is not enough, I stop asking. I build the wall.
When the guard cannot see
Every guard has a weak moment: when it cannot check. Maybe it needs to ask another system, and that system does not answer. What then? I decide that on purpose, for every guard: block the work, or let it through with a warning.
Now the trap. A guard that blocks real work because some other system is down teaches everyone to go around it. And a guard everyone goes around is worse than no guard at all, because you still believe in it! A good one stops work only when it is sure.
Most people never decide what their checks do when they are blind. The default is to block. Right for security. Wrong for most other checks.
The best guard also knows when to step aside.
Instructions ask nicely. Guards decide.
I post one of these every week. Follow along on LinkedIn or YouTube, or by RSS. Want this on your team? Work with me.
The 527 rules I give my AI agents, free
Every one comes from a real mistake. The best 100 are open on /rules, or download them as AGENTS.md, no email. All 527 come by email, as one file you can drop straight into your repo as AGENTS.md or CLAUDE.md, so your agents follow them from the next session. Plus the occasional email when I learn a new one.
One click to unsubscribe.