Skip to main content

Command Palette

Search for a command to run...

Stop Writing Code AI Agents Can't Read

Why messy architecture and weak typing are the absolute fastest ways to break your automated development workflows.

Updated
11 min read
Stop Writing Code AI Agents Can't Read
S
I'm Ahmer, a full-stack developer and Software Engineering student passionate about building real-world web solutions. I explore web development, AI, and software design — and share what I learn through tutorials, dev logs, and personal projects. Currently growing my skills, one commit and one concept at a time.

okay so this is gonna sound ironic. maybe even a little embarrassing.

Most of us — and yes, I'm including myself here — use AI tools to write code every single day. GitHub Copilot, Cursor, Claude, whatever. We let the AI generate entire functions for us. We prompt it to refactor our components, debug our APIs, write our tests.

And yet, somehow, the code we feed back into those same AI agents is a mess that confuses them completely.

I noticed this in one of my own projects a few months back. I was building a full-stack app — Node/Express on the backend, React on the frontend — and I asked Cursor to help me trace a bug through three files. The AI just... gave up halfway. It kept referencing variables that didn't exist, confused one function's output with another's, and confidently wrote code that broke things even worse.

At first I blamed the model. Then I looked at my code.


The Problem Nobody's Talking About

We've spent years writing code for ourselves. Or for teammates who will hop on a call if something's unclear. Or for future-us who will eventually remember what we meant.

But AI agents don't have that luxury. They don't ask questions mid-read (well, the good ones try, but there's limits). They parse your code with a context window — a fixed amount of tokens they can "see" at once — and they try to infer everything from that snapshot.

If your code is ambiguous to a human reading it cold, it's invisible to an AI agent trying to reason about it.

As of early 2026, models like Claude Sonnet and GPT-4o have context windows of 200k-450k tokens. That sounds like a lot. But a production codebase? Hundreds of files. Thousands of dependencies. Layers of abstraction. No AI agent sees all of it at once.

So when you ask Cursor to fix a bug that spans four files, it's reasoning under partial information. Your naming, your structure, your comments — all of that becomes the difference between the agent understanding your intent or hallucinating its way through your codebase.


What "AI-Readable" Actually Means

Before I get into the specifics, let me be clear: I'm not saying you should write code for AI. That's backwards. Good code is good code. What I'm saying is that the things which make code readable to a tired human at 2am are the exact same things that make code readable to an AI agent working with limited context.

AI-readable code is just... good code. We forgot how to write it.


The Sins We're All Guilty Of

1. Variable Names That Mean Nothing

This one's embarrassing because we all know better.

// this is what my code actually looked like last year
const d = await fetchData(u);
const r = process(d);
return r.f.map(x => x.v * x.m);

What is d? What's u? What's f? What the hell is v * m?

I know what it means. I wrote it. But if I paste this into an AI agent and ask it to add error handling, it has to guess what everything represents. And it will guess wrong. Or rather — it will guess confidently and write broken code.

Compare that to:

const userData = await fetchUserProfile(userId);
const processedUser = normalizeUserData(userData);
return processedUser.friends.map(friend => friend.views * friend.multiplier);

Now an AI agent can reason about this. It knows normalizeUserData probably returns something predictable. It knows friends is an array. It can infer what .views and .multiplier are about. Error handling writes itself almost.

2. Functions Doing Way Too Much

I had a function called handleSubmit in a React component. It was 180 lines long. It validated form data, made an API call, updated three different state variables, dispatched a Redux action, logged to analytics, and conditionally redirected the user.

When I asked Claude to help me add loading state to it, the response was almost hilariously wrong. It added setLoading(true) in four different places because it literally couldn't track the flow.

The fix:

// before: one 180-line monster
async function handleSubmit(e) { ... }

// after: broken down properly
async function handleSubmit(e) {
  e.preventDefault();
  
  const validationError = validateFormData(formState);
  if (validationError) return setError(validationError);

  setLoading(true);
  
  try {
    const result = await submitUserForm(formState);
    trackFormSubmission(result.userId);
    redirectToOnboarding(result.userId);
  } catch (err) {
    setError(err.message);
  } finally {
    setLoading(false);
  }
}

Now every sub-function has a single job. An AI agent can understand, modify, or extend any one of them without needing to understand the rest of the 180-line mess.

3. Magic Numbers Everywhere

# what does 86400 mean here?
if time_diff > 86400:
    send_reminder_email(user)

I've seen this in so many codebases. Including ones I wrote. The AI has no idea that 86400 is seconds in a day. It might assume it's a timeout value, a database ID limit, a file size — anything.

SECONDS_IN_A_DAY = 86400

if time_since_last_login > SECONDS_IN_A_DAY:
    send_reminder_email(user)

Now it's obvious. To a human. To an AI. To you when you come back in three months.

4. Missing or Useless Comments

Two kinds of bad comments:

// no comments at all (bad)
async function sync(items, flag) {
  if (flag) return items.filter(i => i.s === 'a');
  return await bulkUpdate(items);
}
// completely useless comments (somehow worse)
// this function syncs items
async function sync(items, flag) {
  // filter items if flag is true
  if (flag) return items.filter(i => i.s === 'a');
  // otherwise update
  return await bulkUpdate(items);
}

Neither of these help an AI agent understand why this logic exists, what edge cases it handles, or what flag represents.

/**
 * Syncs inventory items with the database.
 * 
 * @param {Array} items - Array of product objects from the frontend
 * @param {boolean} dryRun - If true, returns filtered items without persisting (used in preview mode)
 * @returns {Array|Promise} - Filtered items (dry run) or DB update result
 * 
 * Note: items with status 'a' (archived) are excluded from live syncs
 */
async function syncInventoryItems(items, dryRun = false) {
  if (dryRun) return items.filter(item => item.status === 'archived');
  return await bulkUpdateInventory(items);
}

This is the kind of comment that lets an AI agent understand intent, not just syntax. Big difference.

5. Inconsistent Patterns Across Files

This is a subtle one but it absolutely kills AI agents.

In one file you do:

const { data, error } = await supabase.from('users').select('*');

In another:

const response = await api.get('/users');
const users = response.data.users;

In another:

fetchUsers().then(setUsers).catch(console.error);

Three different async patterns. Three different error handling approaches. Three different ways to store the result. When an AI agent is trying to understand your app's data flow, this inconsistency forces it to treat every file as a fresh puzzle with no assumptions it can carry over.

Pick a pattern. Use it everywhere. Your team will thank you. The AI will thank you. Future-you will thank you.


A Real Scenario: Debugging with Claude

Let me tell you what happened to a classmate of mine (we're both studying Software Engineering and he was working on his semester project).

He had a Node.js backend, pretty standard REST API. Something was wrong with his authentication middleware. He pasted the auth file into Claude and asked what was wrong.

Claude responded with something like:

"It looks like your verifyToken function is using req.headers.authorization, but your middleware in the routes file may be expecting the token in a different format..."

Except the routes file wasn't pasted. Claude was inferring from the auth file that there was probably a routes file doing something with the token. It was making educated guesses — and sometimes they were right, sometimes totally off.

When my classmate cleaned up his auth file — better naming, clearer structure, a comment explaining the expected header format — and pasted it again, Claude immediately identified the actual bug: he was calling next() before the token was fully validated.

Same model. Same Claude version. Different code quality. Totally different result.


The 2026 Context: Why This Matters More Than Ever

According to the Stack Overflow Developer Survey 2025, around 76% of developers were already using or planning to use AI tools in their development process. By 2026, that number's almost certainly higher — adoption isn't slowing down.

GitHub Copilot crossed 1.8 million paid subscribers as of mid-2024, and Cursor reportedly onboarded over a million active users within months of gaining traction. These tools are deeply embedded in how we code now.

But here's the thing: these tools are also getting more agentic. They're not just autocompleting lines anymore. They're:

  • Running multi-step tasks across your codebase

  • Writing and executing tests automatically

  • Making PRs, reviewing diffs, suggesting refactors

  • Debugging by reading logs and tracing through files

The more autonomous these agents become, the more your code quality becomes a dependency of their success. You are, in a real sense, writing code that AI will read, execute, and modify — not just suggest.

If your code is unreadable, your AI agent is flying blind.


Quick Wins: What You Can Start Doing Today

Here's the stuff that actually moved the needle for me:

On naming:

  • Functions should be verbs: getUserById, validateEmailFormat, sendWelcomeEmail

  • Booleans should be questions: isLoggedIn, hasPermission, shouldRedirect

  • Arrays should be plural nouns: userIds, selectedProducts, pendingOrders

On functions:

  • One function, one job. Seriously. Name it after what it does. If the name needs "and" in it, split it.

  • Aim for functions under 30 lines. Not a hard rule but a good gut-check.

On comments:

  • Comment the why, not the what. The what is visible in the code. The why usually isn't.

  • Use JSDoc or Python docstrings. Not because tooling needs them (though it helps), but because it forces you to explain the function in a single sentence.

On structure:

  • Keep related code close together. An AI agent given one file should be able to understand its purpose without needing three others.

  • Export types/interfaces alongside the functions that use them.

On consistency:

  • Write a simple conventions doc for yourself (or your team). Even three rules are better than none.

  • When you pick an async pattern, stick to it. When you pick a naming convention, stick to it.


The Downside: Don't Overdo It

I'll be honest — there's a risk of going too far with this.

  • Over-commenting creates noise. If every line has a comment, nothing stands out.

  • Excessive abstraction can make code harder to follow, not easier. Splitting a 30-line function into ten 3-line functions sometimes just creates a maze.

  • Obsessing over naming can lead to ridiculously long variable names that break line length and readability.

Balance is real. The goal isn't to make your code perfect for AI — it's to make your code good. Good code happens to work well with AI agents because good code has clear intent, single responsibility, and honest documentation.

Don't write for the AI. Write clearly. Those end up being the same thing.


One Last Thing

There's a quote I keep coming back to from Martin Fowler:

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand."

He wrote that in 1999. But in 2026, I'd add a corollary:

Good programmers write code that humans and AI agents can understand — because the tools that help you ship are only as useful as the code they can reason about.

Your codebase is your context. Make it readable.


References & Sources


Find me across the web:

Comments (11)

Join the discussion
R

Really like the line “your codebase is your context.”

One place I’d extend this: AI-readable code helps the agent understand the repo, but agents also need readable execution environments.

That’s where MCP gets interesting. A clean codebase tells the agent what the app is trying to do. An MCP server can tell it what the outside system actually does: available tools, expected inputs, state transitions, webhook outcomes, logs, and failed runs.

For API integrations, this is a big shift. Instead of an agent only reading code + docs and guessing, it can use MCP to run the workflow before editing the code.

So the stack becomes:

code clarity → repo context
MCP → execution context
agent → better changes

We’re exploring this with FetchSandbox MCP for API workflows: giving agents a stateful sandbox they can execute against before touching app code.

https://fetchsandbox.com/mcp

S

Thankyou, (*Dont self promote here and no links )

S
Srashti11h ago

Great piece, Ahmer. It’s highly ironic that as we move toward highly autonomous AI agents, the solution isn't fancier prompt engineering ,it’s just going back to the basics of solid, clean code. The point about code consistency across files is huge; humans can context-switch between an API fetch and a Supabase query easily, but it completely breaks an AI's mental model of the codebase.

S

Thankyou Srashti! Clean code is the ultimate prompt.

S

Excellent points. We’ve focused so much on what AI can do for us that we forgot we need to build a stable foundation for it to work on. It’s a two-way street.

S

It’s definitely a two-way street. We expect the AI to behave like a senior engineer, but we often hand it instructions like a confused intern. Building that clean, stable foundation pays off immediately in the quality of code it spits back at us. Thanks for reading!

M
M. Sahil23h ago

Interesting take. If AI readability becomes a standard metric, I wonder if we’ll see linters in the future specifically designed to score code based on 'LLM comprehension probability' before it's pushed to a repo.

S

That is a brilliant idea, Sahil. Honestly, an eslint-plugin-llm-friendly doesn't sound too far off! Imagine a pre-commit hook shouting at you because your variable naming lowers the model's confidence score by 20%. I’d absolutely use that tool.

M
M. Sahil23h ago

This is the real evolution of the 'Developer' role. We are transitioning from raw code writers to context managers and system architects. If you can't provide clear context through your code structure, you can't leverage AI effectively.

S

"Context managers and system architects"—man, you hit the nail on the head. The heavy lifting isn't the typing anymore; it's defining boundaries, data structures, and architecture so the AI can navigate the codebase without getting lost. Whoever manages context best wins.

F
Faiq23h ago

We spent years learning how to prompt the AI, only to realize our actual codebase was the worst prompt of all.

S

Haha, right?! We spent all that time mastering "system prompts" and "few-shot engineering," completely ignoring the fact that our messy folder structure was sabotaging the agent from the jump. The codebase is the prompt.

F
Faiq23h ago

It turns out the best way to prompt an AI is actually just to write readable code in the first place. Who would've thought? 🤯

S

The ultimate irony! Clean code principles from 20 years ago are suddenly the hottest prompt engineering hack. Clean Code isn't just for human sanity anymore; it's literally fuel for the models.

V

My AI agent when it looks at my legacy codebase: 'I can confidently say I have no idea what is going on here, but here is some code that will make it worse.' Great article, needed this wake-up call!

S

😂 This made me laugh out loud because it is painfully accurate. AI will gladly hallucinate a terrible solution on top of a messy foundation just to please us. Glad the article resonated, Vijay!

V

So you're saying my 200-line handleSubmit function isn't 'complex engineering,' it's just an AI-confusing monster? Fair point, refactoring now...

S

Haha, we've all been there! RIP to the 200-line handleSubmit. Breaking it down into micro-functions is going to make your AI feel like it just upgraded its brain. Happy refactoring!

K

I feel personally attacked by that const d = await fetchData(u) snippet. 😂 Glad to know I'm not the only one writing hieroglyphics when I think no one is looking!

S

Shhh, it's a safe space here! We’ve all written those "hieroglyphics" during a late-night coding session thinking, “I’ll fix this variable name tomorrow.” Only now, the AI reads it and completely panics. 😂

AI vs Reality

Part 1 of 4

AI can write code, but it doesn't have to maintain it. This series is a raw, no-sugarcoat look at where autonomous agents fail, where "vibe coding" hits a wall, and why engineering discipline is the only thing standing between your project and a production disaster. I'm testing the limits of AI in the real world—and documenting every crash along the way.

Up next

Fable 5 Pwned: Inside the First Mythos-Class Leak

How Anthropic’s "bulletproof" safety layer collapsed in 24 hours, exposing a 120k-character system prompt and a covert performance-sabotage controversy.