The Research Report
Guardrails Beat Guidance in Coding Agents
Every CLAUDE.md and .cursorrules file on GitHub follows the same logic: tell the agent what to do. Follow the code style. Write clean code. Use descriptive variable names. Keep functions small. Write thorough tests.
A new study says those instructions are not just unhelpful. They actively hurt performance.
The paper is "Do Agent Rules Shape or Distort? Guardrails Beat Guidance in Coding Agents" by Xing Zhang, Guanghui Wang, Yanwei Cui, Wei Qiu, Ziyuan Li, Bing Zhu, and Peiyang He, published April 13, 2026 on arXiv. It is the first large-scale empirical evaluation of instruction files for coding agents. The findings overturn how most developers think about prompting AI.
The Study
The researchers scraped 679 rule files from GitHub. These are real CLAUDE.md and .cursorrules files written by actual developers. The files contained 25,532 individual rules. They then ran over 5,000 agent evaluations on SWE-bench Verified, the standard benchmark for coding agent performance, using a state-of-the-art coding agent.
Four findings stand out.
Rules improve performance by 7 to 14 percentage points over no rules. Adding any instruction file makes the agent better at solving real GitHub issues. This is the good news.
Random rules help as much as expert-curated ones. The researchers compared hand-written rules from experienced developers against randomly selected rules. The performance difference was negligible. The content of your rules barely matters. What matters is that something is there.
Negative constraints are the only individually beneficial rule type. Rules that say "do not" something, like "do not refactor unrelated code," improve performance when added one at a time. Every other category of rule, including positive directives like "follow code style," either has no effect or actively degrades performance.
Individual rules are mostly harmful in isolation but collectively helpful. This is the strangest finding. Most single rules hurt when tested alone. But bundle them together and the aggregate effect is positive. No performance degradation appeared up to 50 rules in the tested range.
Why Guardrails Work and Guidance Fails
The authors analyze this asymmetry through potential-based reward shaping, a concept from reinforcement learning. In PBRS, you can add auxiliary rewards to an agent's environment without changing what it learns, as long as those rewards are potential-based. The key insight: negative constraints act like discrete cuts to the search space. They remove infeasible branches. The agent either crosses the boundary or it does not. Binary. Clean.
Positive directives do the opposite. They add soft preferences that compete with the agent's existing training. When you tell a coding agent to "follow code style," you are asking it to weigh your preference against millions of examples of code style it has already internalized. This creates objective conflict. The agent now has two goals: solve the bug and satisfy your vague instruction about style. The second goal often wins in ways that hurt the first.
The context-priming effect explains the random-rules result. Any domain-relevant text activates the coding-task subspace in the model's representations. The model does not follow your rules carefully. It just gets nudged into the right neighborhood. Your CLAUDE.md file works like a warm-up exercise, not a training manual.
What This Means for Prompt Engineering
This study demands a rethink of how we instruct coding agents. The conventional approach is to write detailed positive directives: tell the agent exactly what to do, how to do it, and what good looks like. The data says this approach is wrong, or at least mostly wrong.
Here are the practical takeaways.
Rewrite your positive directives as negative constraints. Instead of "follow the existing code style," write "do not introduce formatting that differs from surrounding code." Instead of "write clear commit messages," write "do not squash unrelated changes into one commit." Instead of "keep changes focused," write "do not refactor code outside the task scope." Each negative rule defines a hard boundary. The agent either crosses it or does not. No interpretation required.
Keep positive directives for information the agent cannot infer. If your project uses a non-standard build command like pnpm test:integration --filter $PKG, the agent will never discover this from the codebase. That is a legitimate positive directive. But most of what developers put in instruction files is not like this. It is generic advice the model already knows.
Shorter is still better. This study tested up to 50 rules without degradation. But other research shows the compliance ceiling is real. Distyl AI's IFScale benchmark found that frontier models reach only 68% accuracy at 500 instructions. The paddo.dev analysis of the same research recommends keeping instruction files in the low hundreds. The guardrails finding does not give you license to add more rules. It tells you which kind to keep.
Random rules working as well as expert ones is a feature, not a bug. It means you do not need to spend hours crafting the perfect CLAUDE.md. Write a few negative constraints for your project's real failure modes and call it done. The marginal return on the 20th rule is noise.
Move enforcement out of the prompt. A lint rule that flags raw hex colors runs in 20 milliseconds and costs zero tokens. A prompt instruction that says "only use design tokens" competes for attention with everything else in the context window and fails unpredictably. The fuzzycomputer.com piece on guardrail coding makes this point well: use the prompt for things only the prompt can do, and use the environment for everything else.
The Deeper Implication
This finding is counterintuitive because it conflicts with how we teach humans. With junior developers, you give them positive direction. "Here is how we write code. Here is what good looks like." We assume the same approach works for AI agents because it works for people.
It does not. Coding agents are not junior developers. They come pre-trained on millions of code examples. They already know what good code style looks like. They already know how to write tests and use type systems and follow common patterns. What they lack is project-specific knowledge of what not to do. Which files not to touch. Which patterns not to introduce. Which conventions are wrong for this particular codebase.
Telling an agent what good looks like is redundant. It already knows. Telling it what bad looks like for your project is information it genuinely lacks.
The synthesis is simple. Reserve negative constraints for failure modes the agent already knows how to avoid but might not know apply here. Reserve positive directives for information the agent cannot reach any other way. Delete everything else.
The Bigger Picture
This study sits at the intersection of several converging lines of research. The ETH Zurich group (Gloaguen et al., February 2026) found that LLM-generated rules files actually reduce task success by 3% while increasing cost by 20%. Human-written rules improved success by only 4% at a 19% cost increase. Their recommendation: omit generated context files entirely and limit human-written instructions to non-inferable details.
The IFScale work from Distyl AI shows that instruction compliance degrades predictably with scale. Every instruction you add dilutes attention to all the others. The lost-in-the-middle effect means rules buried in the center of a long instruction file are essentially invisible.
Put it all together and the picture is clear. The most effective instruction file for a coding agent is short, negative, and specific. It tells the agent what not to do and what it cannot discover on its own. Everything else is noise that competes for attention and degrades performance.
Your CLAUDE.md file is not a knowledge base. It is an attention budget. The Zhang et al. study tells you how to spend it: on guardrails, not guidance.
Citations
- Zhang, X., Wang, G., Cui, Y., Qiu, W., Li, Z., Zhu, B., & He, P. (2026). "Do Agent Rules Shape or Distort? Guardrails Beat Guidance in Coding Agents." arXiv:2604.11088. https://arxiv.org/abs/2604.11088
- Gloaguen, M., et al. (2026). "Evaluating AGENTS.md." arXiv:2602.11988.
- Distyl AI (2025). "How Many Instructions Can LLMs Follow at Once?" (IFScale benchmark). arXiv:2507.11538.
- AgentPatterns.ai. "Guardrails Beat Guidance: Rule Design for Coding Agents." https://agentpatterns.ai/instructions/guardrails-beat-guidance-coding-agents/
- Holden, M. (2026). "Guardrail Coding." https://www.fuzzycomputer.com/posts/guardrail-coding
- Efimenko, A. (2026). "I Analyzed Dozens of AI Agent Rules Files. Most Are Making Your Agent Worse." DEV Community. https://dev.to/alexefimenko/i-analyzed-a-lot-of-ai-agent-rules-files-most-are-making-your-agent-worse-2fl
- Context Patterns. "Negative Constraints: Context Engineering Pattern." https://contextpatterns.com/patterns/negative-constraints/
- paddo.dev. "Your AGENTS.md is a Liability." https://paddo.dev/blog/your-agents-md-is-a-liability/
Suggested Title
Tell Your Coding Agent What Not to Do
(Alternate: Guardrails Beat Guidance)
Word Count
1,328
Fact-Check Notes
- The Zhang et al. paper's exact claim is "7-14 percentage points" improvement for rules over no rules. This is from the abstract. I have not verified the specific number from the full paper tables, as the PDF was not parseable. The abstract is the source for this figure.
- The "random rules help as much as expert-curated ones" claim is directly from the abstract: "random rules help as much as expert-curated ones." I characterized this as "negligible" difference. The paper may have specific statistical significance data that I could not access from the PDF. A careful editor should verify whether the difference was statistically insignificant or just small.
- The "individual rules are mostly harmful in isolation yet collectively helpful" claim is from the abstract. I used this directly. The exact mechanism for this collective effect (context priming vs. instruction content) is the paper's theoretical contribution via PBRS.
- The IFScale finding of "68% at 500 instructions" is from the paddo.dev analysis of Distyl AI's work, which I used as a secondary source. The primary paper is arXiv:2507.11538.
- The ETH Zurich/Gloaguen numbers (-3% for LLM-generated rules, +4% for human-written) are from the Efimenko DEV Community article, a secondary source. The primary paper is arXiv:2602.11988.
- I described the PBRS analysis as coming from the Zhang et al. paper. This is confirmed by the abstract phrase "a pattern we analyze through the lens of potential-based reward shaping."
- The claim that "no degradation up to 50 rules" is from the AgentPatterns.ai summary. I did not find this specific number in the abstract. It should be verified against the full paper if possible.