🤖 The AI Prompt That Finds Duplicate Logic Copied Across Two Files
Copy-pasted logic is easy to spot when it’s identical, and almost invisible when it’s been subtly adapted for its new home — a validation routine copied into a second controller and then tweaked to handle one extra field looks like two unrelated pieces of code to anyone scanning by eye, even though a bug fixed in one copy almost never makes it into the other.
🔎 The Problem
Prompt: "Here are two files: [paste File A] and [paste File B]. Identify any logic that appears in both, even if variable names, formatting, or minor details differ. For each match, tell me how similar the two versions actually are, which one looks like the 'original', and whether they've already drifted apart in a way that suggests a bug fix landed in only one of them."
✅ Fix: Why This Prompt Works
- Asking specifically about drift (whether the two copies have already diverged) surfaces the exact scenario that makes duplicated logic dangerous — a fix applied to only one copy, silently leaving the other one wrong.
- Comparing two named files directly, rather than asking the model to ‘find duplication in this codebase’ from a vague prompt, keeps the search targeted and the output reviewable in one pass.
- This catches duplication a structural/AST-based duplicate-code tool misses on purpose, since those tools usually require near-exact matches and bail out the moment variable names or control flow diverge even slightly.
Two copies of the same logic don’t stay identical for long — the real risk is the version nobody remembered to update.




