Back to Prompt Library
Coding
refactoringclean codecode qualitymaintenancebest practices

Code Refactoring Assistant

Cleaner, more maintainable code with a documented change log explaining every refactoring decision.

Prompt Template

Refactor the following [LANGUAGE] code to improve readability, maintainability, and performance without changing its external behavior. Code to refactor: [CODE_BLOCK]. Apply these specific improvements: (1) eliminate duplicate logic using appropriate abstractions, (2) replace magic numbers and strings with named constants, (3) break functions longer than [MAX_FUNCTION_LINES] lines into smaller, single-responsibility functions, (4) rename variables and functions to clearly express intent, (5) add inline comments only where the "why" is non-obvious. Output the refactored code first, then provide a bulleted summary of every change made and the reason for each change. If you identify any bugs or edge cases in the original code, flag them separately under a "Potential Issues" heading but do not fix them unless instructed.

How to use this prompt

  1. Copy the prompt template using the button above.
  2. Paste it into your preferred AI assistant (ChatGPT, Claude, Gemini, etc.).
  3. Replace all bracketed placeholders like [TOPIC] with your specific details.
  4. Send the prompt and refine the output as needed.
Advertisement