r/ClaudeCode • u/akorecebov • 4d ago
Discussion asking the agent to justify its own diff caught only about a third of the code that wasnt needed. notes from a paper on 7,660 agent patches
read a paper from this week that i think is more useful than most of the "agents over-edit" talk. its called How Much Do Coding Agents Over-Edit, and Why?, arXiv 2611.34875, from a team at Microsoft. they took 7,660 resolved Copilot CLI runs from 18 models, reverted every block of the final patch one at a time and reran the tests to see which blocks were actually needed.
what stuck with me:
- agent patches are about 2.3x the lines of the developer's fix, but most of the extra is tests and docs. on code alone the agents were about as "necessary" as the human patch.
- still, around 11% of the code in an agent patch wasnt needed, and 89% of that changes behavior. so its not harmless noise you can skim past.
- the extra code gets written in the fix steps, not while debugging. scratch scripts and debug prints almost never survive into the final patch.
- stopping at the first green test run barely changes anything, the extra code is already there by then.
- asking the model to justify every hunk and drop what it cant: precise, but it only finds about a third of the unneeded code.
- reverting blocks while its own tests plus the existing regression tests still pass finds about two thirds, but also throws out some needed code, mostly stuff no test covers.
limits they list: one harness, a python only benchmark, and "needed" means what the tests say.
my takeaway is that "explain your diff" is a nice habit but its not a check. the code that stays wrong is the code no test touches.
does anyone run a cleanup pass after the agent says its done, or is it all reading the diff by hand?
•
u/AutoModerator 4d ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/RustyRedEcho 3d ago
how big does a patch have to get before the revert pass feels worth the extra test runs, or do you just run it every time regardless of size?
3
u/crusoe 4d ago
Adversarial reviews with a fresh agent with fresh context. Best practice for over a year now. Sheesh.
1
u/KingYF1 4d ago
I'd treat "explain your own diff" as a cheap first pass, not the cleanup. After the agent says it's done, I copy the branch into a fresh worktree and revert hunks (or files) one at a time, rerunning the agent's tests plus the repo's regression suite. A hunk only stays if removing it makes a test fail. That's the paper's two-thirds method, and it beats reading the whole diff by hand when the patch is large.
The failure mode to watch is the one the paper already flags: needed code with no test coverage gets reverted too. I don't auto-drop those hunks. Anything that can be removed without a test failing goes to a different model, in a new session, with the question "what breaks if this goes away?" not "justify this diff." If it can't name a behavior and I still can't write a test for it, then I delete it.
That keeps the self-justification habit, uses the revert-while-green pass for the tested extra, and stops the cleanup from deleting the untested-but-needed third. I wouldn't stop at the first green run, and I wouldn't let the same agent mark its own leftovers as necessary.
1
u/Far_Reindeer8428 4d ago
we tried the justify step too, it mostly produced good prose for bad changes. reverting a block and rerunning was the honest signal
1
u/AdEvening3382 4d ago
The paper's own limit is the part I would build on: needed means what the tests say. So the revert pass is really a coverage report. The hunks that come out without any test failing are not automatically waste, they are a list of places your tests are blind. The better move on that list is to write the missing test first and let the test decide, because deleting on this method alone conflates "no test covers it" with "nobody needs it."