Duplicate Logic Is the Costliest Pattern in AI-Assisted Codebases
AI assistants are driving code duplication up because they can write new code faster than they can find the code you already have. GitClear’s 2026 data puts duplicated blocks up 81% since 2023, while refactoring fell off sharply. The expensive kind is duplicated business logic: each change to a rule has to land in every copy, and whichever copy you miss turns into a production defect.
Last updated November 2026
How much has AI-driven code duplication really grown?
One helpful public source is GitClear’s Write-Only Mode report, which looked at 623 million code changes through 2026. Four of its numbers matter for this topic, since together they show two trends at once: more copying and less reuse.
| Measure | Earlier | 2026 year to date |
|---|---|---|
| Duplicated blocks of five or more repeated lines, per million changed lines | 40.3 (2023) | 73.0 (up 81%) |
| Copied and pasted lines, share of changed lines | 9.4% (2022) | 15.7% |
| Moved lines, GitClear’s signal for refactoring, share of changed lines | 21% (2022) | 3.8% |
| Changes that touch code older than 12 months | 1.7% (2023) | 0.46% |
Look at the second and third rows side by side. Back in 2022, moved lines showed up more than twice as often as copied lines. By the 2026 numbers, copied lines beat moved lines by about four to one.
Two warnings before this goes on a slide. GitClear’s page doesn’t say how it tells AI-written work apart from human work, so treat these as industry trends during the years AI tools spread, not as the measured effect of a particular tool. Also, GitClear CEO Bill Harding told LeadDev in July 2026 that duplication grew less than he had expected. The trend is clear. How much of it comes from AI is not.
Why do AI assistants create so much duplicate code?
An assistant works from your prompt plus whatever context it has been handed. For the assistant, writing a fresh function is the cheapest way to get the task done. Tracking down the function your team wrote two years back and changing it without breaking anything takes more work.
Code review often lets the result through. A new helper with tests and tidy names looks like solid work, and no diff can show you the existing function that should have been called. We wrote about this gap in why AI writes code that passes review and fails at scale.
Duplicates come in three kinds. Utility helpers, like date formatters, tend to be harmless. Repeated config values lead to drift. Logic duplicates, where one business rule such as a discount, an eligibility check, or a permission test has two or more implementations, are where the real cost sits.
Why does duplicate logic cost more than other AI code problems?
We aren’t aware of any published study that ranks code problems by dollar cost, so read “most expensive” as an engineering case rather than a measured finding. The case goes like this. Most defects cost you one time: you find the bug, fix it, and move on. Duplicate logic bills you again every time that rule changes, and it does so silently, because every copy still passes its own tests.
The strongest evidence we found predates AI coding. “Do Code Clones Matter?” by Juergens and colleagues at Technische Universität München examined five systems, four of them commercial and one open source. Out of 1,427 clone groups, 724 had inconsistencies. Of those, 28% were unintentional, and 107 groups held real faults, which comes to about one clone group in 13. The authors concluded that “nearly every second unintentionally inconsistent change to a clone leads to a fault.”
That study, from 2009, looked at C#, Cobol, and Java written by humans, and we couldn’t find a matching study for AI-generated code. Still, the mechanism doesn’t care who typed the code. A developer updates one copy without knowing the others exist. AI help makes that more likely, because there are more copies and fewer people who remember writing them. For the budget side, see our breakdown of the real cost of fixing an AI-generated MVP.
Why doesn’t your clone detector catch duplicate logic?
Clone detectors search for matching text and tokens, and the costly duplicates often don’t match. Sonar’s metric definitions make clear how high the threshold is. For most languages other than Java, a block has to contain at least 100 duplicated tokens in a row across at least 10 lines. For Java, it takes at least 10 duplicated statements in a row. Indentation and string literals are the only differences it says it ignores.
According to Sonar’s documentation, the default gate also permits up to 3.0% duplication on new code, and the check doesn’t apply until a change adds 20 or more new lines. That means a six-line discount calculation, rewritten with other variable names across four services, can get through all of it uncounted. Token-based tools like jscpd and PMD CPD have the same blind spot. A low percentage tells you there are few copied blocks, not that every rule lives in a single place.
To track down logic duplicates, pair the tool with checks that look at behavior:
- Get a baseline with a clone detector, then run it again on your business logic directories with a lower minimum block size.
- Write down your domain nouns, like tax, discount, eligibility, entitlement, and refund, and search for every spot that calculates or decides each of them.
- Dig through git history for files that keep changing together even though neither imports the other.
- Go through bug-fix commits looking for fixes made to only one of several similar functions, and for bugs that returned.
- Run the same inputs through each suspected copy and compare what comes out. Each mismatch is either a bug or a requirement that was never written down.
When triaging a whole repository, we work with these thresholds: below 5% is healthy, 5% to 15% deserves a look, and over 15% is structural. These are our own rules of thumb rather than an industry standard, and we explain them in our guide to measuring technical debt in a codebase you did not write.
How do you put a dollar figure on duplicated code?
Ignore the duplication percentage and price each rule instead. A duplicated rule’s carrying cost equals the number of extra copies, multiplied by how many times a year the rule changes, multiplied by the hours it takes to change, test, and review a single copy. Multiply those hours by your loaded engineering rate to get the cost.
The figures below are examples, not benchmarks. Pull your own numbers from git history.
| Duplicated rule | Copies | Changes per year | Hours per copy | Extra hours per year |
|---|---|---|---|---|
| Date formatting helper | 4 | 1 | 0.5 | 1.5 |
| Signup validation rule | 5 | 4 | 1 | 16 |
| Pricing and discount rule | 6 | 8 | 1.5 | 60 |
A rule that seldom changes costs little to leave as is, no matter how many copies exist. Hours are also the smaller share of the bill. Miss one pricing copy and invoices go out wrong; miss one permission check and you have a security incident. So give anything that touches money, access, or regulated data far more weight than its hours suggest.
At 60 extra hours a year, a 40-hour consolidation earns back its cost in eight months. At 1.5 hours a year, it basically never does.
Which duplicates should you fix first, and which can you leave alone?
Start with rules that involve money, permissions, personal data, or compliance. Next, take rules that changed in the past six months and any copies that already disagree, since a live inconsistency is a live bug.
Leave alone small, stable helpers, test fixtures, and code that only looks similar but belongs to different owners and will probably drift apart.
Teams tend to overcorrect on that last group. Sandi Metz’s warning that “duplication is far cheaper than the wrong abstraction” still holds. One shared function with six flags can end up costing more than the copies it replaced.
If the copies disagree, merging them is not step one. Have a product or compliance owner decide which behavior is right, since consolidation will change the behavior for somebody. After that, write characterization tests, move callers to the canonical version one by one, and delete each old copy once nothing calls it.
How do you keep AI assistants from adding more duplicate code?
Banning the tools isn’t necessary. The goal is to make reuse cheaper than rewriting right where the code is being written.
- Write short, specific instructions for the assistant. Name the modules that own your domain rules, and don’t paste in a generated overview. ETH Zurich and LogicStar.ai researchers found that LLM-generated context files tended to lower task success and pushed inference cost up by more than 20%, while files written by developers gave a small gain of about 4%.
- Ask for the search as well as the code. Have PR descriptions say which existing code the author looked at and why it wasn’t a fit.
- Run a duplication check on every PR, and don’t let small changes bypass it.
- Assign each shared rule an owner who reviews any change to it.
For the bigger picture, see our pillar guide on why AI-generated code compounds technical debt faster than human code.
When is it time for an outside review?
Bring one in when no one on the team can tell you where a critical rule lives, or when the people who built it are gone. Our Rescue Audit looks at maintainability along with security, scalability, performance, test coverage, and documentation. It works from read-only repository access, costs a fixed $4,950, takes 10 business days, and the fee is credited toward remediation if we handle the fixes.
Frequently asked questions
Do AI coding assistants increase code duplication?
The industry data suggests they do. GitClear reports duplicated blocks rising 81% from 2023 to 2026, and copied lines growing from 9.4% to 15.7% of changed lines since 2022. These are trends over a period when AI use was climbing, not a controlled test of any one tool’s effect.
How much code duplication is acceptable?
By default, Sonar’s gate permits up to 3.0% on new code. Across a whole repository, our rule of thumb treats under 5% as healthy and over 15% as structural. Neither figure means much until you know whether the duplicated code is a stable helper or a business rule.
Can SonarQube detect duplicated business logic?
Only if the copies are textually similar enough. Its documented criteria require fairly large matching blocks, so short rules and rewritten versions may not be counted.
Book a Code Review
How many versions of your pricing, permissions, or eligibility rules are live in production right now? Find out before a customer does. Book a Code Review and get a list of what to fix first, ranked by risk.