Smell #11: Copy-Paste Loops
Copy-Paste Loops: Repeatedly copying and merging AI-generated patterns or utility functions without checking if similar logic already exists in the codebase.
Symptoms
- You have three different "Email Validation" regexes in three different files.
- You have duplicate "Date Formatting" utilities scattered throughout the project.
- You are copying code from a chat window and pasting it into multiple places yourself.
- The AI keeps suggesting the same boilerplate logic for every new feature.
Self-Assessment
If you find yourself saying "I've seen this code before" while browsing your repo, you have Copy-Paste Loops.
Example
File 1 (Auth): const isValid = (e) => /^\S+@\S+$/.test(e);
File 2 (Profile): function checkEmail(email) { return email.includes('@'); }
File 3 (Admin): const emailRegex = /^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,}$/i;
The Result: Duplication Debt. If you need to change the validation rule, you have to find and fix it in three different places (and you'll probably miss one).
Debt Impact
This smell contributes to:
| Debt Category | Impact | |---------------|--------| | 🏗️ ARCH | Maintenance effort scales linearly with duplication. | | 🧠 KNOW | No "Single Source of Truth" exists for business logic. |
How to Fix
- Deduplicate: Identify common logic and move it to a shared
utils/orhooks/directory. - Standardize Prompts: Use a shared prompt that references existing utility modules.
- Refactor Sprints: Dedicate time specifically to killing duplicate code.
How to Prevent
- The "Search First" Rule: Before prompting for a utility, search the repository for key terms.
- Reference existing code: Explicitly tell the AI: "Use the patterns found in /src/utils/math.js."
- Maintain a Component Library: Document your shared patterns so both humans and AI can find them.
Related Smells
- Smell #9: Style Drift — Each copy drifts slightly from the original.
- Smell #3: Context Flood — Not seeing existing code leads to copying.
Book Reference
- Chapter 2: Chat Until It Works — how fast iteration leads to copying.
- Chapter 9: Team Chaos — how teams duplicate each other's AI work.