How does AI-generated code create technical debt?#
AI-generated code creates debt because an assistant writes code that works locally, while the person merging it often doesn't fully understand how it fits the wider system.
An assistant answers the prompt in front of it. It doesn't know about the helper your team wrote last quarter, the error-handling convention in your payments module, or the reason a library was banned. Each suggestion can be correct on its own. Merged hundreds of times, the suggestions leave a codebase that is harder to change.
The cost of debt is already high before AI is involved. In McKinsey's survey of 50 CIOs, 10 to 20 percent of the technology budget meant for new products went to resolving tech-debt issues. The same CIOs put tech debt at 20 to 40 percent of the value of their whole technology estate. AI doesn't create a new kind of problem. It raises the rate at which this one builds up.
Which kinds of debt does AI-written code add most often?#
AI-written code most often adds five kinds of debt: duplication, inconsistent patterns, untested paths, unchecked dependencies and code that nobody on the team owns.
The duplication trend has the strongest data behind it. GitClear's 2026 analysis found that across 2023–2026, within-commit copy/paste rose 41%, code block duplication 81% and error-masking constructs 47%. Over the same period, moved (refactored) code fell from 21% of changed lines in 2022 to 3.8% so far in 2026.
Security and supply-chain debt build up too. Veracode tested more than 100 LLMs on 80 coding tasks and found that the generated code introduced security vulnerabilities in 45 percent of cases. A USENIX 2025 study of 576,000 code samples found that 19.7% of the packages LLMs recommended did not exist. Attackers can register those made-up names and publish malicious code under them.
| Debt type | How it shows up | Signal to track |
|---|---|---|
| Duplication | The same logic pasted into several files, then fixed in only one | Clone rate per module |
| Inconsistent patterns | Three ways to handle errors, auth or retries in one service | Lint and architecture-rule violations |
| Untested paths | Happy path covered, edge cases and failure branches not | Coverage on changed lines, not overall |
| Unchecked dependencies | New packages nobody reviewed, some abandoned or nonexistent | New dependencies per month, unmaintained count |
| Unowned code | Merged code no current engineer can explain | Files with no active reviewer, rework within two weeks |
Why do faster AI coding cycles make debt pile up quicker?#
Debt piles up faster because AI raises the volume of code written, while the capacity to review, test and integrate it stays roughly where it was.
DORA's 2025 research describes this pattern. AI adoption now shows a positive link with delivery throughput, but it still has a negative relationship with software delivery stability. DORA also found that 30% of developers report little to no trust in AI-generated code. Often that code gets merged anyway, because the backlog keeps moving.
Three things make it worse:
- Larger changes. An assistant can produce a 600-line diff in minutes, and reviewers skim large diffs.
- Less refactoring. Pasting new code is quicker than finding and reusing existing code, which matches the GitClear trend above.
- Thinner understanding. When nobody wrote the code line by line, nobody has a mental model of it, and every later change costs more.
How can you measure technical debt in an AI-assisted codebase?#
Measure debt per module rather than for the whole codebase, and weight each module by how often it changes. Debt in code nobody touches costs very little.
McKinsey found the same concentration at enterprise scale. One company expected heavy debt across more than 50 legacy applications. When it measured, just 20 asset types drove the majority of the tech debt. Code works the same way: a handful of hotspots carry most of the cost.
A workable measurement setup:
- Tag AI-assisted changes. Use a commit trailer or PR label so you can compare AI-assisted and human-written changes on the same signals.
- Track five signals per module: clone rate, two-week churn (code rewritten soon after merge), coverage on changed lines, new dependencies, and error-masking patterns such as empty catch blocks.
- Add change frequency. Commits per module per month, taken from version control.
- Plot debt against change frequency and work on the top-right corner first.
- Review monthly. Trends matter more than any one month's numbers.
For more on reading these signals in pairs, see our guide to measuring AI code quality.
Which review gates stop new AI debt from merging?#
Three enforced gates stop most new debt: automated tests, security and dependency checks, and a senior engineer's review. Each gate needs debt-specific rules added.
Add these debt checks to the gates you already run:
- Tests: require coverage on changed lines, including failure branches, so a passing overall percentage can't hide untested new code.
- Duplication: fail or flag a diff that adds a clone above a set size, and point to the existing function it copies.
- Dependencies: check that every new package exists, is maintained and is on an approved list before it merges.
- Patterns: encode team conventions (error handling, logging, auth) as lint or architecture rules so the assistant's style can't drift from them.
- Review: cap PR size, and require the author to explain the change in their own words. If they can't, it isn't ready.
At Calidad, every release passes three gates: tests, security checks and a senior engineer's review, whether a person or an AI wrote the change. Our Quality Engineering service builds those gates and the release evidence behind them. The pre-merge mechanics are covered in how to verify AI-generated code before production. This post focuses on the debt that is already in your codebase.
How do you pay down existing AI debt without stopping delivery?#
Pay it down inside normal delivery. Fix the hotspot you're already changing, pin its behaviour with tests first, and ship each refactor as a small change that passes the same gates as feature work.
A dedicated "debt sprint" rarely survives the next deadline. These steps hold up better:
- Fix debt where you're working. When a feature touches a top-right hotspot, the ticket includes consolidating its duplicates.
- Write characterization tests first. Pin down current behaviour before changing structure. AI is useful for drafting these tests, but an engineer reviews them.
- Use AI to remove debt too. Assistants are good at consolidating clones and updating call sites when the change runs through the gates.
- Keep refactors small and reversible. Use one concern per PR, and put feature flags around any behaviour change.
- Reserve capacity, but don't rely on it alone. McKinsey warns that carving out 15 to 20 percent of IT's budget for tech debt is insufficient without targeting the debt that matters.
Track each debt item through a clear lifecycle so that items get finished instead of sitting in a backlog.
Who should own AI code debt: the pod, the platform team or the reviewer?#
The pod that ships the code owns the debt it creates. The platform team owns the shared gates and standards. The reviewer owns the merge decision, but not the backlog.
Splitting ownership this way avoids two common failures. If reviewers own debt, review becomes the bottleneck. If a central team owns it, product teams keep adding debt that someone else has to clean up.
- Pod: owns the debt items in its modules, schedules them and reports the trend.
- Platform team: maintains clone detection, dependency checks, lint rules and dashboards so every team measures the same way.
- Reviewer: blocks changes that add debt beyond the agreed thresholds and logs debt that is accepted on purpose.
Calidad pods are accountable for what they ship. In our Dedicated Teams, a delivery lead checks shared rules for code review, tests, AI tool use and definition of done every sprint.
When does AI debt justify a modernization project?#
AI debt justifies modernization when it is structural rather than local. That means the hotspots are core modules, tests can't be added without rewriting, and change failures keep rising despite refactoring.
Modernization doesn't have to mean a big-bang rewrite. Our Platform Modernization work replaces legacy components step by step while the business keeps running, using the same incremental approach described above. That includes a façade in front of the old system, migration one route at a time, and a rollback plan for every step.
Conclusion#
Technical debt from AI-generated code is the old problem arriving faster. To keep it under control:
- Measure it per module.
- Weight it by how often each module changes.
- Block new debt with gates on tests, duplication, dependencies and review.
- Pay down the hotspots inside normal delivery.
- Escalate to modernization only when the debt is structural.
If you want to see this applied to your codebase, our engagements start with a paid pilot: one pod, one outcome, with success criteria agreed up front.
Frequently asked questions
Is AI-generated code always worse than human-written code?
No. The debt comes from volume and how little review it gets, not from AI as such. GitClear's data shows duplication rising and refactoring falling as AI authorship grows, but teams that enforce tests, dependency checks and senior review can keep quality steady. The fix is the process around the code, not a ban on assistants.
How do we know which code in our repository was written by AI?
Most teams can't tell after the fact, so start tagging now with a commit trailer or PR label for AI-assisted changes. After a few months you can compare churn, duplication and defect rates between tagged and untagged changes. Code that is already merged is better judged by its signals than by who wrote it.
Can AI tools help pay down the technical debt they create?
Yes. Assistants work well for consolidating duplicate code, updating call sites and drafting characterization tests. Treat their refactors like any other change: small PRs, behaviour pinned by tests first, and the same security and review gates before merge.
How much sprint capacity should go to AI technical debt?
There's no universal figure, and McKinsey notes that setting aside a fixed budget share isn't enough without targeting. It works better to tie paydown to the hotspots each feature already touches, then watch whether clone rate, churn and change failures in those modules trend down. If they don't, increase the effort for those modules specifically.
Does a hallucinated package count as technical debt or a security issue?
Both. A dependency that doesn't exist, or that nobody vetted, is a supply-chain risk on the day it merges and a maintenance burden afterwards. Check every new package for existence, maintenance status and approval before merge, and review your dependency inventory regularly for abandoned packages.
- AI code quality
- technical debt
- software engineering
- code review
- refactoring
Newsletter
Get new articles by email
A short monthly round-up of what we've written on engineering pods, quality and AI. No spam.
