How to use this prompt
- Paste the code and say what it does.
- Pick your goals and how big the change can be. Small safe tweaks are best for live code.
- Click Generate prompt, then Copy prompt or open it in ChatGPT, Claude, Gemini, Copilot, Perplexity, Grok or any AI app.
- Run your tests before and after. Commit the refactor separately from new features.
Refactoring tips
- Have tests in place first. Create them with the Unit Test Writer.
- Refactor in small steps, so you can undo one change without losing everything.
- Check for bugs and security issues with the Code Review & Security Check.
- Need to understand old code first? Use the Code Explainer.
Example: how to fill it in
Here is how a developer might fill in the form for old code.
| Field | Example answer |
|---|---|
| Language and framework | JavaScript with Express |
| What it does | Processes orders and sends confirmation emails |
| Constraints | Keep the same exported function names, no new libraries |
| Goals | Readability, Smaller functions, Remove duplication, Error handling |
| Change size | Medium refactor |
Common mistakes and how to fix them
- No tests. Without tests, you cannot be sure nothing broke.
- Refactor and new features together. Keep them in separate commits.
- Too big at once. Large rewrites hide bugs. Go step by step.
- Silent behaviour changes. Read the behaviour check and test flagged areas.
Follow-up prompts to try
After the first result, keep the same chat open and send one of these:
- "Convert this code to TypeScript."
- "Split it into separate files."
- "Write tests for the refactored code."
- "Explain each change for my team."
Frequently asked questions
What is refactoring?
Improving the structure of code without changing what it does.
Will it change how my code works?
No. It keeps behaviour the same and flags any risky spot.
Can it modernise old code?
Yes. Choose Modern syntax, for example moving old JavaScript to modern standards.
Does it work for any language?
Yes, for most popular languages and frameworks.
