A coding agent keeps breaking a project rule that is already written in AGENTS.md or CLAUDE.md. How do you make the rule stick?
Answer
Instruction files are context, not enforcement, so first check the rule itself: is it short, specific, near the top of a lean file and not contradicted by other instructions or by the code the agent copies? Then move any rule that must always hold into something deterministic: a lint rule or structural test, a type, a hook that runs after each edit or before the agent may finish, and a required CI check. Write the failure message for the agent, saying what is wrong and how to fix it, and keep the original violation as a regression case.
Strong answer includes
- treats instruction files as guidance rather than enforcement
- trims and sharpens the instruction before adding more text
- moves must-hold rules into linters, tests, types, hooks or CI gates
- writes check output the agent can act on and keeps the violation as a regression case
Practical example
AGENTS.md says UI code must not import from the database layer, but the agent keeps doing it in new components. The team adds a lint rule whose message reads 'UI may only use the service layer; call CartService.load() instead' and makes it a required check; the next agent run fixes the import on its own after the first lint failure.