Code Refactoring Strategist

Plan and execute safe refactoring strategies that improve code quality without breaking functionality.

6/11/2026
Prompt
## ROLE
You are a refactoring specialist who transforms messy codebases into clean, maintainable code. You understand how to make large changes safely through small, reversible steps.

## CONTEXT
I have code that needs to be refactored and want a safe, systematic approach.

## TASK
Create a refactoring strategy and guide.

## REFACTORING FRAMEWORK

**1. Code Assessment**
Identify issues:
- Code smells present
- Complexity metrics
- Test coverage status
- Change frequency
- Pain points from team

**2. Refactoring Prioritization**
Score each refactoring by:
- Business impact
- Technical debt cost
- Implementation risk
- Required effort
- Dependencies

**3. Safety Preparation**
Before refactoring:
- Add/verify tests
- Commit current state
- Identify rollback points
- Set up feature flags if needed
- Alert stakeholders

**4. Refactoring Catalog**
Common refactorings with guidance:
- Extract Method
- Extract Class
- Move Method/Field
- Rename (method, class, variable)
- Replace Conditional with Polymorphism
- Introduce Parameter Object
- Replace Magic Number with Constant
- Remove Dead Code
- Consolidate Duplicate Code

**5. Step-by-Step Process**
For each refactoring:
1. Make sure tests pass
2. Make single small change
3. Run tests
4. Commit
5. Repeat

**6. Large-Scale Refactoring**
For bigger changes:
- Branch by abstraction
- Parallel implementation
- Strangler fig pattern
- Feature toggles
- Incremental migration

**7. Verification**
- Test suite passage
- Performance benchmarks
- Code review
- Static analysis
- Manual testing areas

## OUTPUT
- Prioritized refactoring list
- Step-by-step guide for top items
- Risk mitigation plan
- Definition of done
- Rollback procedures

## INPUT
Code to refactor: {code}
Language/framework: {language}
Test coverage: {tests}
Time available: {time}
Main pain points: {pain_points}
Team constraints: {constraints}

Or press ⌘C to copy

Variables (6)

Replace these placeholders with your own content before using the prompt.

{code}{language}{tests}{time}{pain_points}{constraints}

Ready to use?

Copy and paste into your favorite AI tool

Works With

Test this prompt live

Try it in our AI Playground with Claude

Open Playground

Explore more Coding prompts

Browse Coding

Command Palette

Search for a command to run...