Refactor Early and Often
Treat your codebase like your house: give it a deep clean with a single-prompt, AI-driven refactoring! I use the most advanced model (Opus 4.5) to iteratively refactor, clean, consolidate, simplify, and harden my code, maintaining a solid foundation. It's well worth the cost for the best quality.
The last few posts have been about keeping best practices up to date by using specialized agents (domain-specific keepers of best practices). But how do you take advantage of all those best practices?
Single Prompt Code Review
AI for refactoring!
I do this frequently and especially after I make significant changes. I want to build on the cleanest codebase I can, so it is well worth it (to me) to spend some tokens on making sure my house is in order.
Speaking of “my house,” I get the same feeling from refactoring that I do from cleaning my house. And every time I do it, I choose the deep clean option.
First, I toggle over to the most advanced model I have access to. As of this writing, that is Opus 4.5.
With my agents/ knowledge nice and tidy, I then let the refactor begin with a single prompt for my deep clean.
Agent Prompt
I would like to perform a deep review of the entire project to help ensure best practices and product robustness in order to maintain a solid foundation moving forward. Please review the project and identify opportunities to refactor, clean, consolidate, simplify, and harden the codebase, following the guidelines in replit.md and the files in the agents/ folder, as well as any supplemental best practices you have access to. I would like you to perform an iterative refactoring using these insights to achieve a magnificent codebase aligned with the objectives of this project.
I then sit back and watch the magic happen. When the review is complete, I manually QA to make sure nothing is broken, then merge my branch into the remote GitHub main branch. Then I pull a new branch and prepare for the next round of fun.
The Cost of Quality
Full disclosure, I actually keep my everyday model on Anthropic’s Opus 4.5, which costs about 50-100% more than Sonnet, but it is well worth it to me to get the best code I can as I develop.