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