B
Best AI Utility
Diretório de Ferramentas de IA
Back to Guides
Coding
Advanced
9 min read
Updated 2026-09-20

Letting Claude Clean a Codebase I Was Ashamed Of

A weekend project with twelve copies of the same function. I handed it over and watched it not break things.

The project worked, which is the only nice thing I can say about it. Twelve files, and at least four of them contained a slightly different copy of the same date formatter. I was embarrassed to show it to anyone, so I showed it to Claude instead.

The instinct is to say 'clean this up.' That's how you lose a weekend to a deleted function something depended on. I did the opposite: I asked it to list every duplicated block and rank them by how dangerous merging would be, and I read that list before touching anything.

Then I made it propose, not do. Each refactor came as a diff with the call sites it found, and I approved one at a time. The model is good at spotting the duplicate; it is not good at knowing which copy the rest of the system secretly relies on. That part is still your job.

The thing that actually saved me was tests, and I didn't have any. So step one was 'write the smallest test that proves the formatter behaves,' then refactor behind it. Without that net, I'd have been guessing. With it, three of the four duplicates collapsed cleanly and the fourth turned out to be load-bearing in a way I'd forgotten.

It didn't make the code beautiful. It made it something I could open in front of another person. For a project I'd been hiding, that was the entire point of the exercise.

More guides

Explore more