TL;DR
AI coding agents rely on massive instruction files—like AGENTS.md or .cursorrules—to know how to write good code, yet humans usually craft these rules by guesswork, sometimes accidentally making the AI worse and way more expensive. RuleEvolve treats these coding rules like biological DNA, using an evolutionary loop to automatically mutate, test, and select the best rule sets. The result? Agents that maintain (or improve) their coding accuracy while slashing code bloat and token costs by up to 60%.
What Problem Does This Paper Address?
If you’ve used modern AI coding agents like Cursor, Claude Code, or OpenHands, you know their secret sauce isn't just the underlying Large Language Model (LLM)—it’s the coding rules file prepended to the context. These files tell the agent how to structure logic, format code, and orchestrate tools.
Right now, developers write and share these rules by hand. Not only is this tedious, it’s often counterproductive: poorly aligned human rules can make an agent overly verbose, burn through API tokens, and even degrade functional correctness.
Why not just use existing automatic prompt optimization tools? Because those tools were built to tweak short, two-sentence prompts. Coding rules are sprawling, multi-paragraph documents, creating a massive search space. Plus, evaluating a single rule change requires running an autonomous, multi-turn coding agent against real test suites—making naive "trial-and-error" mutation prohibitively slow and expensive.
Methods
Because an agent’s multi-turn tool use isn't mathematically differentiable (you can't backpropagate gradients through a bash terminal), the authors frame rule optimization as an evolutionary survival-of-the-fittest game called RuleEvolve.
Starting with an initial rule file, RuleEvolve maintains a small pool of $m$ candidate rule sets over $T$ iterations using three key mechanisms:
- The LLM Mutator: An LLM takes existing rule candidates and generates $N$ new variants by rewording directives, combining steps, or shifting style.
- The Judge Module: Each new rule variant is tested by having the coding agent solve a mini-batch of programming tasks. The Judge scores each rule set using a clever shortcut: because character count strongly correlates with API token usage, it penalizes generated code length (in characters) alongside a heavy penalty if the pass rate drops below a baseline. The top $m$ rules survive to the next round; the rest are pruned.
- Strategic Mutation Allocation (What’s Novel): Instead of mutating every surviving candidate equally, RuleEvolve borrows Optimal Computing Budget Allocation (OCBA) from stochastic simulation theory. Using historical mean and variance (newly mutated children inherit their parent’s score history to avoid cold-start issues), the algorithm dynamically spends more of its $N$ mutation budget on candidates that either have high performance variance (uncertain potential) or scores very close to the current #1 spot.
Datasets
No new benchmarks were introduced; the authors used established coding suites while strictly separating training (evolution) data from testing data:
- Training: 1,000 tasks randomly sampled from BigCodeBench (evaluated in mini-batches of 10 per iteration).
- Testing: 100 disjoint tasks each from BigCodeBench, BigCodeBench-Hard, and HumanEval.
- Scalability Testing: A 100-task subset of SWE-Bench Lite to test real-world, repository-level GitHub issue resolution.
Key Insights and Ideas
- Human-crafted rules can actively hurt you: Across multiple setups, popular community-sourced manual rules (from
awesome-cursorrules) produced twice as many lines of code and burned nearly double the tokens compared to using no rules at all—while slightly lowering the pass rate! - Standard prompt optimizers sacrifice correctness for brevity: Baselines like Prompt-Ops happily shrunk code length, but often broke the code in the process (e.g., dropping pass rates from 0.49 to 0.43). RuleEvolve’s constrained penalty keeps functional integrity locked in while trimming the fat.
- Evolution converges surprisingly fast: You don't need hundreds of generations. Most of the dramatic drops in code length and token usage happen within the first 5 iterations, leveling off cleanly by iteration 20.
Key Results
RuleEvolve was tested across two agent frameworks (OpenAI SDK and OpenHands) and four backbone LLMs (gpt-4.1-mini, gpt-5-mini, gpt-5.3-codex, and Qwen-Coder-30B):
- Massive Conciseness & Cost Wins: On BigCodeBench using the OpenAI SDK (
gpt-5.3-codex), RuleEvolve beat manual rules by raising the pass rate from 0.45 to 0.49, slashing average code length by over 60% (from 2,372 characters down to 453.1, and vs. 1,156 for "No rule"), and cutting token usage nearly in half (1,022 to 544.5 tokens). - OpenHands Gains: On BigCodeBench in OpenHands, RuleEvolve hit a 0.52 pass rate (vs. 0.49 for No/Manual rules and 0.43 for Prompt-Ops) while trimming token usage from 1,293 (Manual) down to 1,016.
- Real-World Repo Generalization: On SWE-Bench Lite (
gpt-4.1-mini), RuleEvolve achieved the highest pass rate (0.340 vs. 0.330 No rule, 0.190 Manual rule, and 0.080 Prompt-Ops) while cutting patch size from 8.5 lines to 5.7 lines and reducing tokens from 911 to 722.
Limitations and Future Work
The authors do not include a dedicated limitations section, though two practical trade-offs emerge directly from their results:
- Reasoning Latency on Complex Repos: On repository-level tasks (SWE-Bench Lite), even though RuleEvolve reduced token usage and patch length, average generation time increased (from ~131s with no rules to ~297s), which the authors attribute to increased reasoning overhead on complex repositories.
- Upfront Evolution Cost: While evolved rules save money at deployment, running the evolution loop itself requires executing an agent across hundreds of tasks (e.g., 10 iterations $\times$ 20 mutations $\times$ 10 tasks per batch).Exploring self-evolution of coding rules alongside other agent components remains an open, promising direction.
Summary updated