A Two-Step AI Workflow for Legacy Code Modernization

A Reddit post on r/ClaudeAI argues against simply asking AI to 'refactor' legacy spaghetti code, noting that AI tends to preserve flawed existing structures. Instead, it proposes a two-step 'reverse engineering' workflow that leverages LLM reasoning more effectively.
The Problem with Direct Refactoring
When you paste old code into an AI agent with a request like 'Please refactor this and make it clean,' the result is often just a polished version of the same bad architecture. The AI is biased by the code you provide—it tries to preserve your structure, variable names, and logic flow, even if they were flawed from the beginning.
The Two-Step 'Reverse Engineering' Process
Step 1: Extract the Intent (The 'What')
Don't ask the AI to fix the code. Instead, ask it to ignore the code structure and extract the business logic. Specifically, have it write a high-level Business Requirement Document (BRD) based on the file. This yields the pure logic without the technical debt.
Step 2: The 'Clean Slate' Build (The 'How')
Take that fresh BRD and feed it into a 'Master Architect' prompt. Now, the AI isn't fixing old mistakes; it's building a solution from scratch using modern best practices. This approach also facilitates technology migration (e.g., from legacy Java to modern Node.js) because the intermediate BRD layer is technology-agnostic.
The post mentions that the specific 'Master Architect' prompt used for Step 2 is provided in the first comment of the Reddit thread.
📖 Read the full source: r/ClaudeAI
👀 See Also

TLS Interception by Antivirus Breaks Claude Desktop’s Connection; Workaround with AV Exclusions
Antivirus TLS inspection on bridge.claudeusercontent.com causes Cowork (Claude desktop companion) to fail with 'Claude in Chrome is not connected'. Fix: add *.claudeusercontent.com and *.anthropic.com to AV HTTPS exclusions. Node.js --use-system-ca would prevent this.

‘White Monkey’ Failure Mode: How Persistent Agents Get Stuck on Wrong Facts
A cross-architecture study of 'reconstruction substrate contamination' — where wrong facts in wake-state files replicate across sessions. Includes a 6-question survey for persistent agents.

Why Most Claude Pipeline Failures Trace Back to Prompts, Not Models — and How to Fix with Skills
A Reddit post argues that the root cause of pipeline failures in Claude workflows is treating prompts like skills. The fix: define input contracts, output schemas, and a learnings file — making a skill what you promote to v1.

Vague Prompts Are the Real Problem, Not the Model — 50-Run Test Shows Prompt Quality Trumps Model Choice
A Reddit user ran the same ten prompts through ChatGPT 4, Claude Sonnet, and Gemini 1.5 Pro five times each (150 outputs total) and found that all three models produced similarly usable or similarly generic results — the deciding factor was prompt specificity, not the model.