Skip to content

AI-Generated Code Is Creating a Technical Debt Crisis

AI coding tools are creating invisible technical debt. After auditing 6 codebases, here are the patterns I found and the framework to assess your own AI debt.

9 min read
Illustrative densely layered but believable mechanical assembly containing repeated shortcut brackets and a few improvised joins, photographed beside the orderly original design study in teal metal and pale wood.
On this page

Here's an unpopular opinion: AI coding assistants are the biggest source of technical debt in modern software development. Not because the code is bad. Because it's invisible debt.

I've audited 6 codebases in the last year where teams used Copilot or Claude heavily. Every single one had a pattern I now call "AI debt accumulation." The code worked. The tests passed. And the architecture was slowly rotting from the inside.

The Numbers Nobody Wants to Hear

I tracked metrics across these 6 codebases over 6-12 month periods. Here's what I found:

Metric Before AI Adoption 6 Months After 12 Months After
Avg. file size (lines) 142 203 267
Cyclomatic complexity (avg) 4.2 6.8 8.1
Duplicate code ratio 3.1% 8.7% 14.2%
Unused imports per file 0.3 1.8 2.4
Time to onboard new dev 2 weeks 3 weeks 5 weeks

Missing repository context can lead an assistant to generate a utility that already exists elsewhere. Repository-aware tools can retrieve context, so the result depends on what the assistant can find and uses. After 12 months, one team had 47 different implementations of date formatting scattered across their codebase.

Why AI Debt Is Worse Than Regular Debt

Traditional technical debt has a paper trail. Someone cut a corner, left a TODO comment, or made a conscious trade-off documented in a PR description. You can find it and fix it.

Generated code can look clean while conflicting with the codebase’s architecture. Formatting, names and comments need review alongside the project’s actual conventions and the context supplied to the assistant.[1]

Pattern 1: The Abstraction Mismatch

AI tools generate code based on training data. That training data includes millions of different architectural patterns. So when you ask AI to add a feature, it might use the repository pattern while your codebase uses direct data access. Or it creates a service layer when you've been using simple functions.

typescript
// Your codebase does this everywhere:
const users = await prisma.user.findMany({
  where: { teamId },
  include: { profile: true },
});

// AI generates this:
class UserRepository {
  private prisma: PrismaClient;

  constructor(prisma: PrismaClient) {
    this.prisma = prisma;
  }

  async findByTeam(teamId: string): Promise<User[]> {
    return this.prisma.user.findMany({
      where: { teamId },
      include: { profile: true },
    });
  }
}

// Technically fine. Architecturally wrong for this codebase.

Both approaches work. But now you have two patterns. Next month, a new developer sees both and doesn't know which to follow. They ask AI to help, and it picks whichever pattern was more common in its training data.

Pattern 2: The Dependency Creep

I tracked npm installs across one team for 3 months. Before AI adoption, they added about 2 new dependencies per month. After, it jumped to 9 per month.

The worst example: the AI suggested date-fns for a date operation in a codebase that already used dayjs. Nobody caught it in review because both are popular libraries. Three months later, the bundle included both, adding 47KB of redundant code.

Pattern 3: The Error Handling Inconsistency

This one's subtle and dangerous. AI generates different error handling patterns depending on the prompt context:

typescript
// In one file, AI generated:
try {
  const result = await fetchData();
  return result;
} catch (error) {
  console.error("Failed to fetch:", error);
  return null;
}

// In another file, for similar logic:
const result = await fetchData().catch(() => undefined);
if (!result) throw new ApiError("FETCH_FAILED", 500);

// In a third file:
const [error, result] = await to(fetchData());
if (error) return { success: false, error: error.message };

Three different error handling strategies in the same codebase. Each works individually. Together, they make the system unpredictable. When something fails in production, debugging is a guessing game because you don't know which pattern was used where.

The "I Was Wrong" Moment

For the first few months of using AI assistants, I thought the solution was better prompting. Give the AI more context, more constraints, more examples. I was wrong.

Prompting helps when it supplies the context a change needs. Make architecture decisions and planned migrations available through the assistant’s supported instruction files and repository context, then verify that the generated code follows them.

The solution isn't better AI. It's better systems around AI.

The AI Debt Assessment Matrix

AI debt assessmentPattern consistencyDependency overlapCode duplicationError handlingTest qualityNaming conventions
Figure 1. The assessment groups six dimensions to inspect when reviewing AI-related debt.

Use this proposed triage matrix to evaluate your codebase for AI debt. The score bands are author-selected review prompts, with no calibration study supplied here:

Dimension Score 1 (Critical) Score 2 (Concerning) Score 3 (Healthy)
Pattern consistency 3+ patterns for same concern 2 patterns 1 consistent pattern
Dependency overlap Multiple libs for same purpose Occasional duplication Clean dependency tree
Code duplication > 10% duplicate ratio 5-10% < 5%
Error handling Inconsistent across files Mostly consistent Single pattern enforced
Test quality Tests mirror implementation Tests cover happy path Tests cover contracts
Naming conventions Mixed styles Mostly consistent Enforced by linting

Score yourself: Add up your scores across all 6 dimensions.

  • 6-9: You have an AI debt crisis. Stop generating and start consolidating.
  • 10-14: You're accumulating debt. Implement guardrails now.
  • 15-18: You're managing it well. Keep monitoring.

How to Stop the Bleeding

Remediation sequenceAudit your codeDocument patternsEnforce patternsWeekly check-ins
Figure 2. The article proposes an audit, documented conventions, automated checks and regular review.

Step 1: Audit Your AI-Generated Code

Run a duplication analysis. I use jscpd with a low threshold:[2]

bash
npx jscpd ./src --min-lines 5 --min-tokens 50 --reporters json

You'll find duplicate code you didn't know existed. In one audit, this found 312 duplicate code blocks across a 50K-line codebase.

Step 2: Document Your Patterns

Create an ARCHITECTURE.md file that AI tools can reference. Include:[3]

  • Error handling pattern (with example)
  • Data access pattern (with example)
  • Approved dependencies list
  • Naming conventions

Step 3: Enforce Patterns in CI

Custom ESLint rules beat code review for pattern enforcement. Here's why: reviewers miss pattern violations because the code "looks right." Linters don't have that bias.[4]

Step 4: Weekly Debt Check-ins

Add a 15-minute slot to your weekly standup. Review the duplication report and pattern conformance metrics. Make AI debt visible to the whole team.

The Path Forward

AI code generation isn't going away. The teams that thrive will be the ones that treat AI output like they treat any other external input: with validation, transformation, and quality checks.

The irony is that fixing AI debt requires the same discipline that prevented traditional debt: consistent patterns, automated enforcement, and a culture that values long-term maintainability over short-term velocity.

Start with the assessment matrix, investigate the lowest-scoring areas and track the maintenance work they create. Revisit those observations after remediation to judge whether the changes helped.

Frequently asked questions

How can a team identify AI technical debt?

Compare repeated logic, dependency overlap, error handling and naming conventions across the codebase. Use the article’s matrix to organise a review, then investigate the concrete modules behind each weak area.

Does a low assessment score prove AI caused the debt?

The matrix is a proposed triage aid. Its thresholds do not establish causation or isolate AI from existing architecture, team practices and delivery pressures, so inspect the history of each issue before attributing it.

Where should the first remediation effort go?

Start with repeated code and conflicting patterns that cause maintenance work. Record the intended approach in the architecture documentation and add automated checks for rules that can be expressed precisely.

Can better prompts solve the whole problem?

Prompts can supply relevant context and conventions. The article also recommends duplication analysis, automated enforcement and regular review so the team can detect mismatches that remain in generated changes.

Sources

  1. [1]Application card: GitHub Copilot inline suggestions · GitHub Docs
  2. [2]jscpd v4 (TypeScript engine) · jscpd maintainers
  3. [3]Custom instructions for GitHub Copilot · GitHub Docs
  4. [4]Custom Rules · ESLint

Checked against these sources on

Related Articles