The Agent's Struggle Is a Signal

When an AI agent starts thrashing on a codebase — missing duplicated call sites, running out of context mid-change, making excuses about failing tests — read it as an early warning that maintainability is decaying, and refactor, instead of just fighting the agent.

What it is

As a codebase grows tangled, agents degrade on it — and that degradation is a usable instrument, not just a frustration. When an agent updates one of several duplicated call sites and silently misses the others, runs out of context trying to hold a change together, declares itself done with tests still red, or insists failures are "expected" and then contradicts itself, those are not random model failures; they are a canary in the code mine. The properties that make code hard for an agent — duplication, poor cohesion, things that should change together living far apart, complexity that forces too much context to be loaded at once — are the same properties that make it hard for humans. So instead of treating the agent's difficulty as a reason to fight it or to blame the model, treat it as an early-warning signal that code quality is sliding, and act on it: have the agent review the code, name the maintainability problems, and plan a refactor; review that plan and steer it; and if the agent cannot clean the code well enough on its own, do the structural refactor with a proper refactoring tool. The move reframes an annoyance as feedback. An agent that suddenly needs three tries where it used to need one is telling you something about the code, and the cheap response is to listen.

When to reach for it

When NOT to

Exemplars

Related