New research Which marketing contractors ChatGPT and Claude recommend. Who AI assistants recommendRead it
Ayant-X Get a free marketing reviewFree review (opens in a new tab)

1922 Lines That Blocked 4 AI Agents

One file ate 14% of every agent's context window before any of them had read the task description.

TL;DR: Main UI file hit 1922 lines. Every agent burned 28K tokens just reading it. We split into six files, broke three things along the way, shipped. Three months later one new file grew past 2,067 lines — larger than the original — because the lint was set to warn, not block.

At Ayant-X we build a marketing automation platform using AI agents. Three months ago its main UI file hit 1922 lines — everything in one place: pipeline, gap matrix, application state, navigation, handlers. Growing one feature at a time, nobody had said stop.

Four UI tasks stalled in the same week. Every agent that tried to work on the module burned 28,000 tokens just reading the file — 14 percent of the context window, gone before a single line about the actual task.

Your codebase architecture is now your AI's working memory. Humans skim past methods they don't need and use IDE search. AI agents read the whole file every time, every line costing tokens. What felt normal for a human reader turned out to be expensive for the reader nobody had designed for.

The math

1922 lines ≈ 28K tokens. One read = 14% of Claude Code's 200K context window. Two agents in parallel on the same module = 28% of team capacity going to one file.

Jake Nesler's analysis found AI coding agents waste about 80% of tokens just finding things. MindStudio calls the broader phenomenon context rot — output quality degrades as the window fills. Factory.ai's enterprise research confirms: even a million-token window doesn't help when attention isn't uniform. Long context does not mean reliable context.

Three things that broke during the split

First draft was 3.6× too large. Agent produced 1094 lines against a ~300 target. We threw it away, split into two mixins. The five-second question "how many lines will this be?" would have caught it.

Encoding artifacts broke the editor. Mixed UTF-8 and Windows-1252 bytes from edits across OSes. The Edit tool's string matching failed silently — diffs looked right, bytes didn't. Encoding problems surface as tooling failures agents can't diagnose without someone checking raw bytes.

Context exhaustion mid-refactor. The agent tried everything in one sitting. After reading the file, writing two modules, replacing seventeen HTML references, and rebuilding — the window was full. Handoff never got written. Commit message: "HANDOFF update after rollback — context exhaustion event."

The fix

One store per file. Component-layer code became mixins — functions returning method objects, spread into the data layer:

\`\`\`javascript window.getSemanticCoreMethods = function() { return { /* methods / }; }; window.getAuditLifecycleMethods = function() { return { / methods */ }; };

return { ...getSemanticCoreMethods(), ...getAuditLifecycleMethods(), }; \`\`\`

Six files out. Largest shrank from 1922 to 566 lines. Four blocked tasks unblocked the same day.

Three months later

The semantic mixin had grown from 281 to 1,298 lines. Trending wrong but still under threshold.

The planning store: 2,067 lines. Larger than the original monolith. A new store added after the split, growing unchecked the same way the original had.

Why: the file-size lint was set to informational. It flagged the growing files in yellow, at the bottom of every report, for three months. Nobody acted. An advisory warning became a file bigger than the one we'd built the entire refactor around.

Splits without enforcement are temporary relief. The pattern survived — nothing morphed back into a single monolith. The size discipline didn't, because a warning the agent can ignore is not a rule.

What to do

Run \`wc -l\` on your largest files. Over 1000 = meaningful context cost. Over 2000 = session-killer.

One concern = one session. Don't refactor a monolith in one sitting. One module, one commit, one handoff. Continue in a fresh window.

Estimate before generating. Ask the agent to predict line count. Five seconds, catches 3× overshoots.

Make file-size lint blocking, not informational. Our file grew back because the check warned instead of failed. A refactor without a blocking gate will grow back.

Commit after each file. Context exhaustion loses everything that hasn't been pushed.

Related: Paper Rules Don't Work for AI Agents — why informational lint doesn't hold. Quality Gates for AI Agents — the enforcement layer that grew from these lessons. We Had to Onboard a Human Into Our AI Team — merging two AI setups where these lessons applied. How our signal engine detects problems before they cost money — same detect-before-it-costs principle applied to marketing. About our team — the senior people behind the system. More from the series.

1,922 lines, six files, three months — and one already back over 2,000. The split held. The discipline didn't, until we made the build refuse to ship without it.