Back to Library
Code ReviewIntermediate
Structure Refactoring Requests
Good refactoring prompts specify goals (readability, performance, testability), preserve behavior explicitly, and constrain scope.
refactoringreadabilitytestability
The Strategy
Without explicit goals and constraints, refactoring requests produce rewrites that change behavior or introduce new patterns. Anchoring to specific goals keeps Claude focused.
prompt.txt
<task>
Refactor the following function. Preserve all existing behavior.
</task>
<goals>
1. Improve readability—extract complex conditions into named variables
2. Improve testability—avoid hidden side effects
3. Reduce nesting depth to max 2 levels
</goals>
<do_not>
- Do not change the function signature
- Do not add new dependencies
- Do not change error handling behavior
</do_not>
<code>
[Paste code here]
</code>You might also need
Code ReviewBeginner
Ask Claude to Find Bugs (Not Just Review)
Separate your code review asks. Instead of a vague 'review this', ask specifically for security vulnerabilities, logical errors, or race conditions.
securitycode-reviewbugs
View snippet
PromptingBeginner
Use Negative Constraints
Tell Claude what NOT to do. "Do not add comments", "Do not use any external libraries" — negative constraints are just as powerful as positive ones.
constraintsguardrailsfocused-output
View snippet