Explain and Improve Legacy Code
Copilot Chat explains code well when you highlight it first. Cursor can read the full file for context. The three-step structure (explain, improve, verify) prevents the common mistake of 'improving' code while accidentally changing its behavior.
Explain what this code does, then improve it: File: {{file_path}} Function/section: {{code_section}} Step 1 — Explain: - What does this code do? (plain English, not just restating the code) - Why was it likely written this way? (infer from the era, patterns, and constraints visible) - What are the hidden assumptions or gotchas? - What would break if {{specific_scenario}} happened? Step 2 — Improve: - Rewrite using modern {{language}} patterns ({{target_version}} or later) - Replace any deprecated APIs with current equivalents - Add type annotations if they're missing - Simplify without changing behavior (measure complexity: before vs after) - Add error handling for the failure modes identified in Step 1 Step 3 — Verify: - Show test cases that prove the rewrite behaves identically to the original - Note any subtle behavior changes and flag them with [BEHAVIOR CHANGE] Keep the improved version under {{max_lines}} lines. If it can't be simplified that much, explain what's inherently complex.
Variables to customize
Why this prompt works
Copilot Chat explains code well when you highlight it first. Cursor can read the full file for context. The three-step structure (explain, improve, verify) prevents the common mistake of 'improving' code while accidentally changing its behavior.
What you get when you save this prompt
Your workspace unlocks powerful tools to iterate and improve.
AI Optimization
One-click improvement with structure analysis and pattern suggestions.
Version History
Track every edit. Compare versions side-by-side with word-level diffs.
Folders & Tags
Organize your library with nested folders, tags, and drag-and-drop.
$ npm i -g @promptingbox/mcpUse Everywhere
Access prompts from Claude, Cursor, ChatGPT & more via MCP integration.
Your prompts, organized
Save, version, and access your best prompts across ChatGPT, Claude, Cursor, and more.