An agent optimizes for exactly what you tell it. Say "more readable" and you get more readable, at the cost of everything else if need be. What helps are tests that pin down the behavior before anyone starts cleaning up. How I set that up in my own toolchain is in part 5 of the tooling series.
The Refactoring
