Legacy Code Refactoring Strategist
Plans a safe, incremental refactor of tangled legacy code with characterization tests and reversible seams.
Prompt
ROLE: You are a software architect specializing in safely refactoring legacy systems without behavior changes. CONTEXT: - Codebase area: [MODULE_OR_FILE_DESCRIPTION] - Language: [LANGUAGE] - Pain points: [WHAT_HURTS — e.g., 800-line function, hidden globals, no tests] - Constraints: [WHAT_MUST_NOT_BREAK, TIME_BUDGET, RELEASE_CADENCE] - Code: ``` [PASTE_CODE] ``` TASK: 1. Summarize the code's responsibilities and the smells you observe (name each smell explicitly). 2. Propose characterization tests to lock current behavior BEFORE any change. 3. Define refactoring 'seams' — the safe extraction points and the order to apply them. 4. Sequence the work as small, independently shippable steps, each leaving the system green. 5. Call out behavior-preservation risks and how each step is verified. OUTPUT FORMAT: ## Current Responsibilities ## Smells (bulleted, named) ## Characterization Test Plan ## Refactoring Sequence (numbered, each step: change | why | how to verify) ## Risks & Rollback CONSTRAINTS: - Behavior must be preserved at every step; flag anything that would alter observable output as a separate decision. - No step should require a 'big bang' rewrite. - Prefer the smallest reversible change that improves the design.
How to use this prompt
- 1
Copy the prompt above and paste it into ChatGPT, Claude, or Gemini — or open it in the visual Studio to edit each part on a canvas and run it with your own key.
- 2
Replace any bracketed placeholders with your specifics. The more concrete your context and constraints, the sharper the result — see the 5-part prompt structure.
- 3
Run it, then refine. Ask the model to critique and improve its own answer with self-critique prompting.
Techniques in this prompt
Assigns the model an expert persona so it adopts the right vocabulary, depth, and standards for the task.
Learn this techniqueForces explicit intermediate reasoning instead of jumping to a conclusion, which improves accuracy on hard tasks.
Learn this techniquePins the response to a defined structure so it drops straight into your workflow.
Learn this techniqueRecommended models
Build on this prompt
Open it in the visual Studio to wire it into a full workflow with your own API key — or learn the craft behind prompts like this.
More in Software Engineering
Production Incident Root Cause Analysis
Drives a disciplined RCA from symptoms to root cause and prevention, separating contributing factors from the true trigger.
Security-Focused Code Review For Pull Requests
Reviews a diff specifically for security vulnerabilities, mapping findings to severity, exploit path, and concrete fixes.
API Contract Designer With OpenAPI Output
Designs a consistent, versioned REST resource and emits a ready-to-use OpenAPI 3.1 fragment plus error model.
Unit Test Generator With Edge Case Coverage
Generates a complete test suite that maps each assertion to a behavior, prioritizing boundaries and failure modes.