npx @bryceo/me

Why can't AI refactor my code?

December 17, 2025

Why is it that AI really struggles to refactor my code? AI has been great a generating new code, especially in green-field projects, but for existing code it has been a headache to use it for refactors.

A simple example I ran into this week was trying to use AI to address some ESlint errors I had. I was merging one mono-repo into another and I needed to run lint to address some final issues. The primary issues that came up were from the @typescript-eslint/member-ordering rule. I had 62 files that needed to be addressed. I thought this would be a pretty straight forward task for AI to tackle. It had clear boundaries, and could even run my lint task to see the exact files that needed addressing. I opened up gemini-cli with gemini-2.5-pro and gave it the following prompt

I need you to run 'yarn lint' and check the failures for @typescript-eslint/member-ordering and fix them. Make sure to move the jsdoc above each member as well. Only fix the member-ordering issues, nothing else. In each instance, make sure the interface or type object is sorted alphabetically from A-Z. When you think you have fixed all instances, run 'yarn lint' again to verify no failures for @typescript-eslint/member-ordering exist.

Now, maybe the prompt isn't perfect and maybe I needed to tweak it to make the AI do a better job, I fully accept that. However, I think it's a pretty straight forward task, and I would trust any Junior Developer to be able to easily do this task.

The agent ended up running for 30 minutes and was confident it has resolved all the issues. I ran yarn lint to verify... I now had sorting issues in 84 files...

Not only did AI not fix any of the existing issues, it also opened 22 other files and created new issues.