⚡ TL;DR
AI-generated code gets fragile fast: GitClear measured an 8x rise in duplicated blocks in 2024. Five engineering habits, with code, restore maintainability.
AI-Generated Code Is Fragile: Engineering Habits That Fix It
Ask any team that adopted AI coding assistants at full speed, and you’ll hear the same story: output exploded, quality quietly sank. Evan Merz named the pattern in AI Usage Generates a Fragile Codebase (Evan Merz, November 2026), and GitClear’s research backs the anecdote with numbers. This post is the practices piece: five habits, one example, one checklist.
- Duplicated code blocks rose roughly 8x during 2024, and copy-pasted lines overtook refactored lines for the first time in GitClear’s dataset (GitClear, 2025).
- A November 2026 r/ClaudeCode thread describes a team a year into a 100% AI-generated-code mandate; the poster’s verdict: nobody understands the code anymore (Reddit r/ClaudeCode, November 2026).
- Two PHP engine bugs weaponized with AI tooling in one week showed the security cost of fast, confident code production (IEEE Spectrum, November 2026).
- Five habits counter it: verification gates, ownership boundaries, a consolidation cadence, a review protocol, and invariant-capturing docs. Each is a schedule decision, not a model upgrade.
Contents
- What Does “Fragile” Mean in an AI-Generated Codebase?
- Why Do Verification Gates Come First?
- Who Owns Architecture, and Who Owns Implementation Slices?
- How Often Should You Run Consolidation Passes?
- What Should You Actually Read When Reviewing Agent Output?
- How Do You Keep the Codebase Explainable?
- What Does Fragile vs. Hardened Code Look Like?
- Where Does Security Fit In?
- What Goes on the Habits Checklist?
- FAQ
- The Verdict
What Does “Fragile” Mean in an AI-Generated Codebase?
Fragile doesn’t mean broken on arrival; assistant output passes the happy path on the first try. Fragile means the code collapses under change: duplicated logic drifts apart, an error path nobody exercised fails silently, a convenient dependency becomes your maintenance problem.
The mechanism is structural. An assistant answers the prompt in front of it. It doesn’t carry your architecture in its head or remember the helper it wrote last Tuesday. Every request gets solved in isolation, and the codebase absorbs the leftovers. That’s Merz’s diagnosis: the problem isn’t one wrong line, it’s answers that never connect (Evan Merz, November 2026).
GitClear’s AI code research, built on hundreds of millions of changed lines, quantifies it. During 2024, duplicated code blocks rose roughly 8x, and copy-pasted lines overtook moved (refactored) lines for the first time in the dataset’s history (GitClear, 2025). The 2026 edition, The Maintainability Gap, extends the series: volume climbs while maintainability markers sag, making AI code quality in 2026 a measurable gap (GitClear, 2026). The r/ClaudeCode thread shows the end state: a year of 100% AI-generated code left a codebase its own team can’t explain (Reddit r/ClaudeCode, November 2026). Managing AI code debt starts with accepting the volume itself is the problem.
Why Do Verification Gates Come First?
Tests are the contract. An agent is the fastest code producer you’ll ever work with and the least reliable self-critic; the only feedback it can’t charm past is a failing test.
The gate has three parts:
- Behavior first. Require a test capturing the behavior you asked for before accepting an agent’s change; the agent writes the failing test first, then the code.
- Speed matters. Keep the suite fast enough to run per change; a forty-minute suite gets skipped exactly when you need it most.
- Green is the gate. Merging requires the suite to pass, not the diff to “look right”.
One caveat: the human owns the assertions encoding business intent. An agent validating its own homework produces tests that pass because they encode the same misunderstanding as the code. That’s how a mandate yields a green build nobody understands.
Who Owns Architecture, and Who Owns Implementation Slices?
The boundary that works: the human owns the shape, the agent owns the slices.
Human decisions: module boundaries, the data model, public interfaces, and which dependencies enter the repo. These choices compound; get one wrong and every slice inherits the damage.
Agent decisions: the implementation inside a boundary. Function bodies, boilerplate, fixtures, the volume where assistants shine.
Two rules keep it honest. No new dependency enters the repo without a human yes; agents reach for what appears most in training data, not what fits your maintenance posture. And the approver owns the result: “the agent wrote it” is not a defense anyone accepts in an incident review, so it’s not one in a pull request.
How Often Should You Run Consolidation Passes?
Agents add code. They almost never merge it. Duplication is the dominant measured signature of assistant-era code (GitClear, 2025) and cheapest to fix while young, so scheduled consolidation is the best deal in managing AI code debt.
The habit: put consolidation on the calendar. A scheduled pass with one job, merging near-duplicate logic into a single tested helper, beats a vague plan to clean up “when things calm down”; things never calm down. A fresh agent pass can list reimplemented functions; the merge stays human work, since picking the canonical copy is an architecture call. Pick a fixed slice of each sprint; the exact percentage matters less than the cadence.
What Should You Actually Read When Reviewing Agent Output?
Reading every generated line equally is a trap: scrutiny burns out on boilerplate and misses structural decisions. The AI code review process that holds up reads three things first:
- Seams. New imports, new modules, changed public interfaces. Dependency edges show what the change couples you to; unrequested dependencies appear there first.
- Error paths. What happens when the input is invalid, the network times out, the discount code expires? Agents handle happy paths first and improvise the rest.
- Intent match. Does the diff do what the task asked, or did it quietly broaden scope and “fix” things nobody flagged? Scope drift is common and cheap to catch early.
Then run it. Reviewing code that was never executed is how “works on my machine” becomes a team trait. Turn the protocol into AI coding standards the team can point to.
How Do You Keep the Codebase Explainable?
The r/ClaudeCode complaint, “nobody understands our code”, is as much a documentation failure as a code failure. Agent output ships without the reasoning that produced it. If humans don’t capture it, the codebase becomes explainable to no one and every future change gets riskier.
The habit: docs capture invariants, not descriptions. One paragraph per non-obvious decision records the constraint, the choice, and the rejected alternative. Architecture decision records work fine and take minutes. Require one whenever a change touches a public interface. The payoff doubles: the next human can explain the system, the next agent inherits real context instead of guessing, the cheapest upgrade for code review of AI output.
What Does Fragile vs. Hardened Code Look Like?
The fragile version. An assistant wrote this, it worked first try, and it shipped:
export function getTotal(items: any[]) {
let total = 0;
for (const it of items) {
total += it.price * it.qty;
}
return total;
}
// Same assistant, one month later; the loop is copied and already drifting
export function getDiscountedTotal(items: any[], code: string) {
let total = 0;
for (const it of items) {
total += it.price * it.qty;
}
try {
total = total - total * (discountFor(code) / 100);
} catch (e) {
// ignore bad codes
}
return total;
}Three fragility signatures: untyped inputs, a duplicated money-math loop, a swallowed error that quietly charges full price when the discount code is bad. The happy path works; everything else is improvised.
The hardened version:
export type LineItem = { readonly price: number; readonly qty: number };
export class InvalidDiscountError extends Error {
constructor(public readonly code: string) {
super(`Unknown discount code: ${code}`);
}
}
export function subtotal(items: readonly LineItem[]): number {
return items.reduce((sum, it) => sum + it.price * it.qty, 0);
}
export function totalWithDiscount(items: readonly LineItem[], code: string): number {
const base = subtotal(items);
const discount = discountFor(code); // throws InvalidDiscountError
return base * (1 - discount / 100);
}Same feature. One implementation of the money math, a typed contract at the boundary, an error that announces itself instead of vanishing. The consolidation pass makes that merge happen; the verification gate proves it didn’t change behavior. That’s the loop.
Where Does Security Fit In?
Fragile and insecure overlap. AI tooling accelerates attackers too: the php2shell episode in October 2026 saw two PHP engine bugs found and weaponized with AI assistance in about a week (IEEE Spectrum, November 2026). Assistants reach for convenient, dangerous constructs; shell-execution sinks are the classic example.
Two pointers from this site: my audit routine for finding RCE patterns in AI-generated PHP covers the grep battery and pre-deploy checklist, and the series on why prompt injection is the new SQL injection covers reviewed code that talks to models. One rule for agent-generated code: output touching shell commands, eval, serialization, or auth gets audited like untrusted input every time.
What Goes on the Habits Checklist?
Six rows, printable at a glance; they cost almost nothing to start.
| Habit | What it looks like in the repo | The failure it prevents |
|---|---|---|
| Verification gate | Behavior-capturing tests before code; green CI is the merge gate | Confident output that breaks behavior nobody tested |
| Ownership boundary | Human owns interfaces, data model, and dependencies; agent owns slices | Architecture drift and dependency sprawl |
| Consolidation cadence | Scheduled pass that merges near-duplicates into one tested helper | The 8x duplication signature (GitClear, 2025) |
| Review protocol | Read seams, error paths, and intent first; run the change | Review that sees syntax and misses structure |
| Invariant docs | One paragraph per non-obvious decision: constraint, choice, rejected alternative | A codebase nobody can explain |
| Security overlay | Shell, eval, serialization, and auth changes audited like untrusted input | Convenient-but-dangerous constructs reaching main |
FAQ
Does using AI for coding automatically make a codebase fragile?
No. The fragility comes from volume without a maintenance loop, not from the model. GitClear tracks duplication rising with adoption; teams that pair adoption with gates, boundaries, and consolidation keep quality.
Can a smarter model fix duplication and churn?
Not alone. A better model improves each answer, but no model holds your architecture accountable across months. Models operate on prompts; habits operate on the repository. You need both; only one is schedulable.
How do I review agent output without doubling my workload?
Read seams first: imports, interfaces, dependency edges. Then error paths, then intent match against the task. Run the suite and the change; you’re checking where agent output most often goes wrong.
What is the single best habit to start with?
Verification gates. Tests as the merge contract protect every other habit and give the consolidation cadence a safety net. Without them, refactoring agent-added code is guesswork.
Do these habits slow down AI-assisted delivery?
They add small fixed overhead per change and remove unplanned rework later. The r/ClaudeCode thread shows the endpoint of skipping them: code nobody understands is slow to change, however fast it shipped.
The Verdict
- The fragility pattern is measured, not vibes: duplicated blocks up roughly 8x in 2024, copy-paste overtaking refactoring, and a 100% AI mandate that ended with nobody understanding the codebase.
- Adopt verification gates first; review seams, error paths, and intent before approving, and run the change. Tests are the only feedback an agent can’t charm.
- Split ownership explicitly. Humans own architecture and interfaces; agents own slices; the approver owns the result.
- Schedule consolidation. Duplication is the dominant signature of agent-era code and cheapest to fix; a cadence beats an aspiration.
- Capture invariants in docs while the reasoning is fresh; an unexplainable codebase is a liability in review and in security, as php2shell made plain.

Written by Mihir Pipermitwala
Senior Full Stack Consultant & Mobile Engineering Specialist building user-focused applications in healthcare with Flutter, Dart and React Native. I write about what I actually build and test — every tutorial here comes from real project work.
More about Mihir →