CodingUpdated 2026-10-24
Code Refactor Prompt
Get a step-by-step refactor plan with behavior-preserving verification.
#重构#代码质量#工程#测试Claude CodeCursorAider
Prompt
Refactor the code below.
Language/framework: {{language/framework}}
Constraints: {{constraints, e.g. no API changes, no new dependencies}}
Code:
```
{{code}}
```
Requirements:
1. Describe current behavior and risks first.
2. Give three to five refactor steps, each leaving the code runnable.
3. For each step, explain what changed, why and how to verify.
4. Do not change the public API or external behavior.
5. End with the full refactored code and test suggestions.Variables to replace
{{语言/框架}}{{约束}}{{代码}}
Example output
Step 1: split the 120-line handler into parsing, business call and response assembly without behavior changes.
How to use it
State what must not change; otherwise the model happily changes your API.
Recommended tools
Related prompts
CodingFeatured
Code Review Prompt
Have the model review code by severity and return actionable fixes.
Claude CodeCursorGitHub Copilot
Coding
Unit Test Generation Prompt
Generate runnable tests with edge cases, not just the happy path.
Claude CodeCursorAider
Coding
SQL Query Prompt
Turn a schema and a business question into readable, verifiable SQL.
DeepSeekClaude CodeCursor