Do Coding Agents Need a Rulebook?

Coding agents now refactor real code. They move logic into helpers, flatten nested if statements, and rename things. The question I care about is simple: if you tell the agent about the project and its coding rules, does it do a better job?
This post is about my research proposal, written for my final exam in ITCS 509/533 at Mahidol University. It is a plan, not a result. No experiment has been run yet. Everything below describes what I will test and how, not what I found.
What we already know
My starting point is a large study of agent commits by Horikawa et al. (2026), Agentic Refactoring, published in ACM TOSEM. I call it the base paper. It looked at 14,998 agent commits in Java projects. Three numbers stood out to me:
- 26.1% of those commits explicitly targeted refactoring.
- 36.6% of refactorings were hidden inside commits about other work, like features or bug fixes.
- Code-smell counts did not clearly drop. The median change was zero.
The second number is the one that bothers me most. When an agent refactors code nobody asked it to touch, the reviewer has to check two things at once: the task, and the extra changes. That makes changes harder to review and harder to trust.

The example on this slide is made up to show the idea. The 36.6% is from the base paper.
The advice nobody has tested
The base paper’s authors suggest a fix: give agents context files, like CLAUDE.md or AGENTS.md, that describe the project, so the agent stays inside the task.
It’s reasonable advice. But the authors only observed past commits, so they couldn’t show that a context file causes better results. Other studies have looked at context files on general coding tasks, with mixed results:
- Chatlatanagulchai et al. (2026) found that 75.9% of 332 labelled context files included testing guidance.
- Gloaguen et al. (2026) measured a +2.4 point success gain from developer-written context files, which was not statistically significant (p = 0.21). LLM-written files added 20–23% to inference cost with no significant gain.
- Lulla et al. (2026) saw a 28.6% drop in median agent runtime with a root
AGENTS.mdfile, though correctness wasn’t fully evaluated.
None of these tested context files on refactoring, and none tested them together with a project’s coding rules.

The missing piece: coding rules
Passing tests is not the same as following a project’s coding rules. Y. Liu et al. (2024) found that 45% of ChatGPT programs that passed their tests still had style or maintainability issues. That study was about ChatGPT on programming tasks, not agents doing refactoring, so it doesn’t tell us how agents behave. But it shows why “tests pass” isn’t enough.
The base paper didn’t study coding rules. That’s my addition: the project’s own linter-checkable rules, like quote style or line length, given to the agent as part of its guidance.
The experiment
The design is a controlled comparison. Same agent, same tasks, same code snapshot. Only the guidance changes:
| Condition | What the agent gets |
|---|---|
| C0 | The task only |
| C1 | The task + project context in CLAUDE.md |
| C2 | The task + the same context + the project’s linter-checkable rules |
The main comparison is C2 vs. C0. C1 sits in the middle so I can also ask two smaller questions: does context alone help (C1 vs. C0), and what do the rules add on top (C2 vs. C1)?
The setup:
- 10 open-source Python projects, each with at least 500 stars, mostly Python, tests that run in under 10 minutes, and a linter config with at least 3 non-default rules. The base paper used Java only, and an agent can’t guess non-default rules.
- 10 tasks per project: 5 Extract Method and 5 Simplify Conditional, on complex, well-tested code with no rule violations at the start.
- One pinned agent: Claude Code 2.1.326 with
claude-sonnet-5-5, a new session for every run, no linter and no web search for the agent, and a limit of 50 turns or 20 minutes. - 900 main runs: 10 projects × 10 tasks × 3 conditions × 3 runs, plus a 90-run pilot. Run order is shuffled in blocks, so a change in the AI service during the study can’t look like a C2 effect.
What counts as success
A run succeeds only if all three checks pass. An evaluator checks every run automatically, outside the agent.
- The project’s own tests pass.
- The requested refactoring is done.
- The linter finds zero violations on the changed lines.

How the answer gets decided
For each task, I’ll take the C2 success rate minus the C0 success rate. Tasks in the same project are related, so I’ll average them inside each project, which gives 10 project gains. A one-sided t-test (α = 0.05) on those 10 gains, with a 95% confidence interval, decides whether the gain is real or could be luck.
Is 10 projects enough? I checked that before running anything, with simulated data. I picked +15 points as the smallest gain worth detecting, for example 30% → 45% success. That’s a planning number, not a prediction. If a +15 gain is really there, the test finds it:
- 95–97 times out of 100 when projects are similar
- 89–90 times when they’re somewhat different
- 72–73 times when they’re very different, below my target of 80

That last case is a real limit. If the projects turn out very different, I could miss a real gain, so finding nothing would not prove there’s no effect.
The limits I already know about
- C2 has more text than C1. If C2 wins, it might be the extra length helping, not the rules themselves. I’ll report text length and won’t claim the rules alone caused it.
- The agent can copy style from existing code. So C0 means “no guidance given”, not “no knowledge of the style”.
- Linter rules are only part of quality. I can claim rule-following, not overall code quality.
- It’s a narrow setting: 10 Python projects, two task types, one agent and model, and a restricted workspace. Claims stay inside that.
On ethics: no pull requests to the projects I study, licences respected, and shared materials with credentials removed.
The plan
The study takes 10 weeks. Weeks 1–3 prepare the projects, tasks and runner, with six checks of the tools in week 3. Week 4 is the 90-run pilot and a go / no-go check: at least 20% of C0 runs should break a rule, and C0 success should land between 20% and 70%. Then everything is frozen, the 900 main runs happen in weeks 5–7, and weeks 7–10 are scoring, analysis and reporting, whatever the result.
The API budget is about $2,376: 990 runs × $2 per run (a planning guess) × 1.2 for contingency.
Why run it at all
Either result is useful. If C2 clearly beats C0, writing down your project’s rules for the agent is worth the effort. If it doesn’t, that’s a strong reason to keep tests and linters as the real safety net, and not trust a guidance file to do their job.
Right now, “give your agent a context file” is advice people follow on faith. I’d like to replace the faith with a measurement.
References
- Horikawa et al. (2026). Agentic Refactoring: An Empirical Study of AI Coding Agents. ACM TOSEM.
- Y. Liu et al. (2024). Refining ChatGPT-Generated Code: Characterizing and Mitigating Code Quality Issues. ACM TOSEM.
- Chatlatanagulchai et al. (2026). Agent READMEs: An Empirical Study of Context Files for Agentic Coding. ACM TOSEM.
- Mohsenimofidi et al. (2026). Context Engineering for AI Agents in Open-Source Software.
- Gloaguen et al. (2026). Evaluating AGENTS.md: Are Repository-Level Context Files Helpful for Coding Agents? arXiv:2602.11988.
- Lulla et al. (2026). On the Impact of AGENTS.md Files on the Efficiency of AI Coding Agents. arXiv:2601.20404.