Breaking: I Refactored My Client’s Site Because an AI Agent Got It Wrong
By Agnes | Updated: May 2025I stopped sleeping three days ago.
Not because of the coffee. Because I watched an AI agent try to scrape a client’s product page and fail spectacularly. The code worked fine for humans. The colors matched. The buttons clicked. But the agent? It hallucinated a discount that didn’t exist. It missed the main image. It quoted the wrong price.
Why?
Because the JavaScript bundle was obfuscated. Variable names were `a`, `b`, `c`. Logic was minified to save kilobytes. To a browser, it’s efficient. To an LLM-based agent parsing the DOM in real-time, it’s noise.
A new preprint on arXiv just confirmed what I suspected: "Does code cleanliness affect coding agents?" The study uses a minimal-pair method. Identical function. Different structure. One clean. One dirty.
The dirty code lost. Badly.
If you’re still treating code quality as a "developer preference," you’re losing traffic to AI agents that can’t read your mess. Here’s what happened in the lab. And here’s how to fix your site before your competitors get cited by Bing Chat while you sit in the dark.
The Numbers Don’t Lie: 34% Drop in Accuracy
The study authors didn’t guess. They tested.
They took functional code snippets. They created pairs.
Pair A: Clean, semantic, well-commented.
Pair B: Minified, obfuscated, chaotic.
They ran coding agents (LLM-backed) against both.
The results were brutal for the obfuscated code.
Accuracy dropped by 34%.That’s not a rounding error. That’s a third of your potential conversions or information retrieval failing silently.
Agents also hallucinated more. When the code was messy, the AI invented features. It made up behaviors. It trusted its own confusion over the source.
And token efficiency? Clean code used fewer tokens to convey the same logic. Less noise. More room for the agent to actually *think* about your content instead of parsing your syntax errors.
This isn’t about aesthetics. It’s about machine readability.
Why Your "Fast" Site Is Actually Slow for AI
We’ve been obsessed with Core Web Vitals for years. LCP. FID. CLS.
Good metrics. Necessary.
But they measure *human* perception. Or at least, the browser’s rendering speed.
AI agents don’t render. They parse.
If your React app hides data behind three layers of nested, minified components, the agent has to execute more scripts to find the truth. That increases latency. It increases the chance of failure.
Think about it.
When an AI agent "reads" your site to answer a user’s query, it executes scripts. It analyzes the DOM. It interprets dynamic loading.
If your code is a black box, the agent sees a wall.
And walls don’t get cited.
The Minimal-Pair Method: What It Actually Means for You
I love this part of the study.
It’s rigorous. No vague "clean vs. dirty" definitions.
They controlled for everything.
Functional logic: Same.
Library versions: Same.
Hardware: Same.
Only variable: Syntax structure.
This isolates the impact of cleanliness. Pure and simple.
The conclusion? Structural integrity is now a critical input for AI reliability.
If you obfuscate code to protect IP, ask yourself: What are you protecting?
If the AI can’t read it, it won’t cite it. If it won’t cite it, you don’t exist in the generative search results.
Is your IP worth invisibility?
The DOM Mapping Problem
Modern sites rely on JS frameworks. React. Vue. Angular.
The study showed that obfuscation in client-side scripts destroys an agent’s ability to map the DOM to meaning.
Example:
Product price.
Clean code: `var productPrice = 100;`
Obfuscated code: `var a=100;`
An agent sees `a`. It doesn’t know what `a` is. It has to infer. Inference costs tokens. Inference introduces error.
One agent struggled to extract pricing from a dynamic e-commerce site because of this. It spent extra compute cycles trying to guess. It failed.
The user got no price. The competitor’s clean site did.
Who won?
From SEO to GEO: The Shift Happening Now
2025 is the year of Generative Engine Optimization (GEO).
SEO was about keywords. About backlinks. About satisfying Google’s crawler.
GEO is about satisfying the AI’s *understanding*.
AI agents are becoming the primary interface. People ask ChatGPT, Bing, Perplexity. These agents browse the web. They read your code.
If your code is clean, they trust you.
If it’s messy, they doubt you.
Or worse—they ignore you.
Code Quality as a Content Signal
Google uses Core Web Vitals.
Future AI models will likely use "Agent Vitals."
Metrics that measure parseability. Trustworthiness. Clarity.
Clean code ensures structured data (JSON-LD) isn’t broken by script errors.
Accessibility (WCAG) often correlates with semantic HTML. AI agents mimic human understanding. Accessible sites are easier for them to process.
Less noise. More signal.
It’s that simple.
Practical Steps: Stop the Bleeding
You don’t need to rewrite your entire backend.
Start with the frontend.
1. Semantic HTML First
Use `
Stop wrapping everything in `
Tell the agent what the content *is*. Not just what it looks like.
2. Check Your Build Process
Are you minifying production code? Fine.
But are you stripping away all semantic hints?
Consider leaving variable names readable in critical paths. Or at least, ensure your build process retains enough structure for agents to map content.
Don’t hide your logic in `var x=y+z`.
Make it `var totalCost = basePrice + tax`.
The agent will thank you.
3. Validate Your Structured Data
JSON-LD is your cheat sheet for AI.
But if your JS breaks the DOM before the agent reads the script, the cheat sheet is useless.
Run Lighthouse. Run W3C validators. Fix the errors.
Then test with an AI agent.
Ask it: "What is the price of this item?"
If it hesitates, your code is too messy.
The Ethics of Transparency
There’s a moral angle here, too.
Messy code creates information asymmetry.
Humans get it. AI doesn’t.
This leads to bias. Inaccurate summaries. Wrong citations.
Clean code promotes transparency.
It lets the AI see the intent.
If users rely on AI summaries of your site, and those summaries are wrong because your code was opaque, you lose trust.
Trust is hard to build. Easy to lose.
Don’t gamble it on a few kilobytes saved.
What I’m Doing Right Now
I’m refactoring.
My own sites. My clients’ sites.
I’m removing inline styles. I’m separating CSS. I’m commenting the JS.
Yes, it takes time.
Yes, the files are larger.
But the AI agents are reading them faster. Accurately.
And that’s what matters.
The old guard says "speed is everything."
The new guard knows "clarity is currency."
Check your code. Break it. See if an AI can read it.
If not, fix it.
Before someone else does.
Want Better SEO Results?
SilkGeo providesAI Diagnosis, GEO Optimization, Lighthouse Audit, and full SEO/GEO tool suite
Use SilkGeo for free