← Prompt library
CodingFree→ Claude / ChatGPT / Cursor

Safe Refactoring Plan

Break a risky refactor into small, reversible, test-protected steps.

What you get: An ordered list of small refactor steps with tests and rollback points.

input
output — Claude / ChatGPT / Cursor
I want to refactor {{target}} in a {{language}} codebase to achieve {{goal}}. Constraints: {{constraints}} (e.g. no downtime, public API must not change).

Code and context:
{{code}}

Create a refactoring plan where every step is small enough to merge on its own, keeps the system working, and has a way to verify it. For each step give: the change, the test or check that protects it (write characterization tests first if coverage is poor), the risk, and how to roll it back. Use patterns like parallel run, strangler, feature flag or expand-then-contract where appropriate. Identify the first step that delivers value fastest, and list what NOT to touch in this refactor.