Skip to main content
VePrompts
claude-opus-4 Coding & Development

While optimized for claude-opus-4, this prompt is compatible with most major AI models.

Refactor Legacy Code

Modernize old code while preserving functionality — improve structure, naming, and performance.

Share

Prompt Health: 100%

Length
Structure
Variables
Est. 221 tokens
# Refactor Legacy Code **Best model:** Claude 4 Opus **Category:** Coding & Development **Tags:** refactoring, legacy code, maintenance, clean code ## Description Modernize old code while preserving functionality — improve structure, naming, and performance. ## Prompt Refactor this legacy code. Goals: 1. IMPROVE READABILITY: Better naming, smaller functions, clear flow. 2. REDUCE COMPLEXITY: Extract methods, remove nesting, simplify conditionals. 3. MODERNIZE: Use current language features and patterns. 4. ADD TYPES: If TypeScript or typed language, add proper types. 5. ADD TESTS: Suggest 3-5 unit tests for the refactored code. 6. DOCUMENT: Add docstrings/comments explaining 'why' not 'what'. Preserve all existing functionality. Do not change behavior unless there's a bug. Show before/after comparison. CODE: [CODE] LANGUAGE: [LANGUAGE] FRAMEWORK: [FRAMEWORK]

Private Notes

Insert Into Your AI

Edit the prompt above then feed it directly to your favorite AI model

Clicking opens the AI in a new tab. Content is also copied to clipboard for backup.

Explore Related Resources