← Prompt libraryRewrite It Clean
Skill · Code Review · #refactoring #clean-code
rewrite-it-clean
Step back after iterating and reimplement the whole thing as the clean solution you would design knowing what you know now. Use when code works but has accreted patches and is ready for a clean-room rewrite.
Once the code works but has accreted patches, quick fixes, and dead ends, do a deliberate clean-room rewrite.
- Stop patching. Name what the code actually needs to do now — the real requirements, not the ones you started with.
- List what you learned the hard way: edge cases, wrong abstractions, constraints that only surfaced mid-build.
- Design the solution you would write on day one knowing all of that. Sketch it before typing.
- Reimplement from that design. Delete the old accretion; don't graft the new idea onto it.
- Carry forward only what earns its place — proven edge-case handling, real requirements. Drop scaffolding, dead code, and abstractions nothing uses.
- Diff behavior against the old version: run the tests and exercise the key paths, checking the rewrite handles every case the patches did.
- Keep it only if it is genuinely simpler and clearer. If it is just different, throw it away and keep the working code.
This is one of dozens of free prompts in the AIStorageDepot library. Sign up free to save them, version them, and pull them straight into Claude, Cursor, or VS Code over MCP.