Code Refactoring
Explicitly stating that external behavior must be preserved prevents breaking changes. Requiring a change log with rationale makes the refactoring reviewable and educational.
Refactor the following {{language}} code to improve {{refactoring_goal}}.\n\nOriginal code:\n{{original_code}}\n\nConstraints:\n- Maintain the exact same external behavior (inputs and outputs must not change)\n- Do not add new dependencies unless absolutely necessary\n- Follow {{style_guide}} conventions\n\nProvide:\n1. The refactored code\n2. A bullet list of every change made and why\n3. Before/after comparison of any metrics that changed (lines of code, cyclomatic complexity, number of parameters)\n4. Any risks or trade-offs introduced by the refactoring
Variables to customize
Why this prompt works
Explicitly stating that external behavior must be preserved prevents breaking changes. Requiring a change log with rationale makes the refactoring reviewable and educational.
Save this prompt to your library
Organize, version, and access your best prompts across ChatGPT, Claude, and Cursor.
Related prompts
Get thorough code reviews with actionable feedback tailored to your language, framework, and standards.
Context-Aware Code CompletionProviding the surrounding code and project context lets the model match existing patterns exactly. The constraint against modifying existing code prevents unwanted side effects.
Inline Code SuggestionConstraining suggestions to match existing style and scope produces insertions that feel native to the codebase. The 'no explanation' rule mimics real inline completion behavior.
Code ExplanationThe audience level parameter adjusts complexity automatically. Requiring a usage example ensures the explanation is practical, not just theoretical.