← All writing
23 Nov 2026AI Engineering8 min read中文

A Rule My AI Agent Can Ignore Is Just a Wish

Why every new rule in my setup now has to replace an old one or come with a check outside the model

In the last post I described the control tower: one repo of rules that every agent session loads, whichever project I open. Getting the rules to every repo turned out to be the easy part. Getting the agent to follow them was harder.

This post is about what I changed when I accepted that a rule written in a prompt is a request, not a guarantee. It ends with the small pieces you can copy.

The Rules Were Loaded. The Agent Still Skipped Them.

Early on, the agent and I wrote down a set of ground rules: weigh efficiency first, challenge rules that cost more than they give, search for an existing tool before building one. They went into the shared AGENTS.md that every session loads.

Soon after, I asked the agent what to do next. Its answer ignored most of what we had just agreed. So I asked it directly:

“The ground rules we discussed are recorded. When you talk to me, are you following them, or ignoring them?”

It admitted it had skipped them, and its explanation stuck with me: the rules were only text in the prompt, a soft constraint. Nothing checked whether it followed them. The model follows instructions with some probability, and as the rules pile up, its default habits (answer fast, sound complete) push them out. For the rules that matter, it said, you need guardrails as code: hooks and CI checks.

That’s the model’s own account, but it matches what others measure. The behaviour is often called instruction drift, and benchmarks such as IFScale show instruction following dropping as the number of instructions grows.

My First Fix Was More Rules

I agreed in principle, and then reached for the familiar tool. Each time an agent slipped, I added a rule that named the slip. It felt responsible: every incident left a trace.

Before long, the tower had merged around 40 PRs, all of them documentation and none of them a check. Before a product-planning task in the fitness coach, the agent had about 8,000 words of rules and method to read. Some incidents were written down in three places. My own lessons file already opened with: “A process that lives only in a prompt or a plan file is not followed reliably by an LLM agent.” I was answering that with more prompt.

The Cleanup That Made It Longer

I asked the agent to clean this up. Its first version made the shared AGENTS.md longer by almost 200 words. I asked:

“I thought this cleanup would remove a little content, but it added a lot. Doesn’t that increase the context and the cost?”

It condensed the file instead, every rule kept, the repetition removed, and ended up around 10% shorter than before the cleanup. Small, but it taught me something useful: an agent asked to fix rule bloat will happily do it by writing more rules, so the fix has to be a rule about rules.

The Rule Budget

That’s the change I kept. A new rule either replaces an existing rule, or comes with a check outside the model. A lesson with neither goes into my notes, and is not a rule.

Diagram: a new rule rides a belt through a scanner called the rule budget. With a check outside the model it goes to enforced rules; if it replaces an old rule, it goes in and the old one comes out; with neither, it goes to notes.

Replacing a rule doesn’t enforce anything; it keeps the count flat. The check is what turns a wish into a rule. It can be one of four things:

Check Runs What it is good for
Hook In the agent’s tool loop, before or after a tool call or a prompt Blocking a command, injecting context at the moment it’s needed
CI check On every PR Anything visible in the diff: files, formats, generated indexes
A skill loaded for the step When a specific kind of work starts A method that’s too long for the always-on rules
A second model’s cross-check Before a plan reaches me Judgment calls no script can make

The first three are what Anthropic recommends for Claude Code. Its hooks guide presents hooks as the way to make an action always happen instead of relying on the model, and its steering guide says to keep CLAUDE.md short and move procedures into skills. I got there by hitting the problem first; the guides confirmed the direction.

The budget has a check of its own. A PR that changes the rules lists each new rule with what it replaces or which check enforces it, and a second model (Codex, read-only) reviews the PR against that list. On the first such PR it found six problems, including a claim of mine with no source.

What the Checks Look Like

None of these is clever. Three are short standard-library Python scripts or a few lines of config; the fourth is a prompt to a second model. One example of each kind (a worker is a separate agent session started to do delegated work):

Rule Check Kind
A Claude worker must be started with an explicit model A PreToolUse hook that denies the start command without --model Hook
Product scope questions use the product-manager method A UserPromptSubmit hook that loads the skill when the prompt is about what to build Skill loaded
The index of decision records is current A script fails the PR when the index is stale CI check
A new plan is consistent with the rules Codex reviews it read-only before I see it Second model

Terminal: the worker-start hook, fed a sample tool call with no model, returns a deny decision and the reason the agent sees (output formatted)

Three examples show how a slip turned into a check.

Pick a model for every helper agent. The rule said to run simple delegated work on a cheaper model. When I looked at the logs, almost every helper had still run on the most expensive one, because none was started with a model. Now a hook refuses the start until it names one (the screenshot above).

A product question loads the product skill. The agent planned features without its product method, and once changed its answer twice when I pushed back. Now a hook spots a prompt about what to build and loads the product-manager skill before the agent answers.

A rule that holds without a hook. “Search for an existing tool before building one” is the rule the agent follows best today, and no script checks it. It failed twice while the agent listed tools from memory. The fix was the form of the rule: every plan opens with an Existing tools considered: line naming where it searched and what it found. I approve every plan anyway, so a missing search is obvious. The check is me, at no extra cost.

Two details made these work in practice:

  • A blocking check says why. The denial message names the rule and where to read it, so the agent fixes the command instead of trying a workaround.
  • A check must never break the session. The worker check catches every error of its own and stays silent. A hook that crashes on odd input blocks real work, and you’ll turn it off. The price is that it fails open: if the hook breaks, the rule isn’t enforced. For a hard stop, back it with the platform, as below.

What Stayed a Note

Not every slip earns a check. One agent read the rule that cross-checks run as a separate worker, and then ran it in its own shell because it was one command. The check was no longer independent: the same agent wrote the prompt and relayed the findings.

I chose not to add a hook for it. My call at the time: wait until it happens again. It stays in my notes, with the failure named (shortcut around delegation). A check costs something to build and to keep working, and one incident doesn’t justify it.

Has It Worked?

Yes, as far as I can see. Most rules are followed now, and I correct the agent less often. That’s my own observation, not a measurement, and the rule budget is still a pilot. What it has already done is stop the pile-up: rules no longer grow one incident at a time.

Two things to know if you try it:

  • A check only guards its own rule. Rules without one still depend on the agent remembering them.
  • The budget stops growth; it doesn’t shrink what’s there. Long methods, like my product method, still grow with real work. Their place is a skill that loads only when it’s needed, which I’m doing now. That’s a later post.

If You Want to Try This

You can start with four pieces, each small enough to copy.

1. Ask for evidence where you already look. If you approve the agent’s plans, make the plan’s first line carry the evidence for your most important rule, for example: “Existing tools considered: the sources you searched, the candidates found, and why each is used or skipped. A list from memory does not count.” No code needed.

2. Turn one rule your agent keeps breaking into a reminder hook. The hooks guide has the details. In ~/.claude/settings.json (all projects) or .claude/settings.json (one repo):

{
"hooks": {
"UserPromptSubmit": [
{
"hooks": [
{
"type": "command",
"command": "echo 'Reminder: <the rule your agent keeps breaking>'",
"timeout": 5
}
]
}
]
}
}

The text is added to the agent’s context on every prompt. It raises the odds; it doesn’t enforce.

3. Turn one rule that must hold into a blocking hook. A PreToolUse hook reads the tool call as JSON on stdin; exit code 2 blocks the call and sends stderr back to the agent. This one refuses git push to main:

import json
import sys
try:
call = json.load(sys.stdin)
command = call.get("tool_input", {}).get("command", "")
except Exception:
sys.exit(0) # a broken check must never break the session
if "git push" in command and "main" in command:
print("Blocked: never push to main. Open a branch and a PR.", file=sys.stderr)
sys.exit(2)

Register it under PreToolUse with "matcher": "Bash". It’s a deliberately crude string match: it also blocks a branch named domain-fix, and misses a bare git push while you’re on main. A real one parses the command. For a hard stop, back it with branch protection on the platform as well.

4. Add a rule budget to your rule PRs. Paste this into the PR template of the repo that holds your agent rules:

## Rule budget
| New rule | Replaces | Check outside the model |
|---|---|---|
| | | hook / CI / skill / second model, or empty |

If both Replaces and Check are empty, the rule goes into your notes instead.

Thanks

Eric Dong