Rules for an AI Agent: What Goes in the Rules File and What Becomes a Check Script
When an AI works for you over a long stretch, rules pile up. There is a simple way to decide where each one goes. If a program can tell whether the rule was followed, make it a check script that blocks the AI's action before it runs. If the rule needs a trade-off, put it in the rules file, and keep it short. This works for any AI coding tool that can load a rules file and run a script before a tool call.
First ask whether a program can judge it
For each new rule, look at whether it governs an action or a judgment.
A rule about an action is easy to verify. Did the commit include file paths? Was the working copy created in the designated location? Is the command that kills a process written too broadly? If you put these in a rules file, the AI will forget one time in ten, and usually at the busiest moment. Once it is a script, the command is blocked before it runs, and the message gives the correct form. The AI fixes it on the spot, and you may never know it happened. The commit check we described in multiple sessions sharing one repo came about this way.
A rule about judgment cannot be checked by a program. Should this come to me or not? Is this approach just a patch on the last fix? How much testing is enough before it goes to users? These can only be written as principles in the rules file and calibrated afterward through reviews.
A third kind is a multi-step process, such as releasing, submitting for review, or organizing invoices. These do not need to be read at the start of every session. Write each one as a separate runbook and load it when needed.
A script can check that it was done, not that it was done well
The easiest mistake is to use a check script to govern judgment.
We had a rule that when dispatching a subtask, the AI should pick a model tier that fits the job. The first version of the script forced the cheap tier. Work that needed judgment got pushed down too, and errors and rework went up noticeably. The second version only blocks one case: dispatching without saying which tier to use. If a tier is stated, any tier passes.
That back and forth showed us where scripts stop. A script can make sure the AI thought about the question. It cannot make sure the AI thought correctly. Whether the choice was right depends on the principles in the rules and on a weekly look at the usage bill. If a script stands in for judgment, the rule gets satisfied on paper and fails in practice.
Rules need a way to be deleted
A rules file that only grows is a more common problem than a wrong rule. Our habit is that when the same correction comes up a second time, it becomes a rule or a script. That habit works well, but it only adds. In October alone, more than thirty rules were added to the file. When we took inventory in early November, the rules and memory index the AI had to read at the start of every session came to tens of thousands of words. Of the twenty or so check scripts, none kept a log of what it blocked, and nobody could say which rule had not done anything for a month.
During the inventory, we sorted every rule by what it was originally patching. Rules that patched a weakness in the model could mostly go once the model improved. One example was "guess at an API once, and if the guess is wrong, read the docs". Current models already read first. Rules stating facts about the environment stay, such as that this computer must be silent at night, which no model will ever know on its own. Rules about my personal preferences stay too, though the count can shrink. What is left is process inertia: task cards, receipts, and acceptance steps set up to manage a weaker model, which kept running after the model changed. Those we deleted outright.
We then set three rules. The rules file has a size limit, and adding one means merging or deleting one first. If a script can check a rule, the main text keeps one line for it, and the history and reasons go in an archive. Every check script writes a block log, and once a month a list of scripts with zero triggers is produced, which we use to delete. The inventory itself became a scheduled task.
The rules file has been trimmed three times, and it is now under 60% of its longest length.
What to do
- Look through the corrections you made to the AI in the past month. Anything you said twice or more should be codified.
- For each one, ask whether a program can judge it. If yes, make it a check script that runs before the action and gives the correct form when it blocks.
- If not, put it in the rules file, one or two sentences per rule with only the rule itself.
- Write multi-step processes as separate runbooks that load on demand.
- Keep check scripts in your global config, and have them log every block.
- Give the rules file a size limit. Adding a rule means deleting or merging one.
- Once a month, look at the zero-trigger list, and for each rule ask what weakness it was patching and whether that weakness is still there.
Sources
- Inventory of rules and check scripts, 2026-11-05
- Archive of three rounds of trimming the rules file, September to November 2026
Related
I'm Jiang. I build apps with AI after my day job and write down how it goes. Four of the apps are free and open source on GitHub.