Why Does My AI Coding Agent Keep Writing Outdated Code?

2026-11-29

You ask your coding agent for a simple popup that closes when you click outside it. It hands back forty lines of JavaScript: a fixed div, a dark overlay, a click listener on the page, a scroll lock, a keyboard trap. The browser can do almost all of that with one HTML tag. One.

Why does AI write outdated code? An AI model learns from a frozen snapshot of old code, and old ways of doing things outnumber the modern ones in that snapshot. It also cannot see which versions your project uses. The fix is to hand it three things: your versions, current docs, and a check that fails when old code slips in.

That gap costs you twice. You ship more code than you need, and you spend review time fixing things the model should have known. Below is where the gap comes from, and a setup that closes it in about ten minutes.

A model only knows code up to its cutoff

Mind map of why AI writes outdated code: frozen training snapshot, old patterns outnumber new ones, agent guesses your versions, fixes are a rules file, a docs tool and a failing deprecation check

A model only knows what was in the text it was trained on, and that text stops at a fixed point.

Start with the base fact. An AI model is a program that predicts the next word (or the next piece of code) based on patterns it saw during training. Training means feeding it a huge pile of public text and code once, then freezing what it learned.

That freeze point is called the knowledge cutoff (the last date the training text covers). Model makers publish it; Anthropic, for example, lists a “reliable knowledge cutoff” for every Claude model. Anything a library changed after that point, the model has never seen. Not once.

Training snapshot flow: years of public code feed a training run that makes a frozen model; library changes after the cutoff are never seen

Old patterns outnumber new ones in the training text

Old patterns appear far more often in the training text, and the model leans toward whatever it saw most.

Here is the step most people miss. A deprecated function (one the library authors still support but plan to remove) usually lived for years before its replacement arrived. In that time it piled up in tutorials, forum answers, blog posts and millions of public repos.

A rename or a better browser feature does not delete any of that old text. It stays online. So even when the modern version is inside the model’s snapshot, the old one may outnumber it many times over.

Old patterns in tutorials, forum answers and public repos outnumber the modern pattern in a few docs pages, so the model picks the one it saw most

Because the model predicts the most likely next code, “most likely” often means “most repeated”, not “most current”. That is why your popup came back as forty lines of hand-built overlay. Chrome’s own developer team found the same habit in its testing: agents “frequently hand-roll” overlays instead of using the HTML features built for them.

The agent guesses your versions

Unless you tell it, the agent guesses your versions, and it guesses the ones it saw most.

Your project’s exact versions live in files like package.json, requirements.txt or a lock file. Many agents do not open those files before they start writing. So the model falls back to the version that dominated its training text.

There is a second trap inside your own code. Agents copy the style of the files around them, so if older parts of your project still call an old function, the agent repeats that call in fresh code. Old code breeds more old code. Fast.

The agent does not read package.json or requirements.txt, copies the style of older files, and relies on the training snapshot

So the problem has three roots: a frozen snapshot, old patterns that outnumber new ones, and no view of your versions. Each fix below targets one root. Three roots, three fixes.

What outdated code looks like when it runs

Often it runs fine and prints a warning nobody reads, which is exactly why it survives.

Here is a real example you can repeat in two minutes. Python’s datetime.utcnow() is a function that years of tutorials use to get the current time in UTC (the world’s standard reference clock). Python marked it deprecated in version 3.12 and points to datetime.now(UTC) instead.

I wrote a two-line script with the old call that prints which timezone the result carries, and ran it on Python 3.13. Then I ran it again with one extra flag that turns deprecation warnings into hard errors.

$ python3 old.py
old.py:2: DeprecationWarning: datetime.datetime.utcnow() is deprecated and
scheduled for removal in a future version. Use timezone-aware objects to
represent datetimes in UTC: datetime.datetime.now(datetime.UTC).
timezone: None
exit 0

$ python3 -W error::DeprecationWarning old.py
DeprecationWarning: datetime.datetime.utcnow() is deprecated ...
exit 1

$ python3 -W error::DeprecationWarning new.py
timezone: UTC
exit 0

Look at the first run. The script exited with success, so a quick glance says “works”. But the time it made carries no timezone at all, a classic source of off-by-hours bugs.

The second run failed loudly with exit code 1. The fixed version passed the same strict check and knows it is UTC. One flag. That is the difference between old code hiding and old code getting caught.

Three layers that stop deprecated APIs

Give the agent your versions, give it current docs, and add a check that fails on deprecated calls.

Each layer covers a gap the others leave open. You do not need all three on day one. Together they cover the three roots from earlier.

Three layers: agent knows your versions, reads current docs, and passes a deprecation check, otherwise it loops back to writing

Layer 1: Tell the agent your versions in a rules file

A rules file is the cheapest fix, because the agent loads it at the start of every session.

A rules file is a plain text file in your project that the agent loads automatically. Claude Code reads CLAUDE.md, and AGENTS.md is an open format many coding agents share, described by its makers as “a simple, open format for guiding coding agents”.

Put three short things in it: your main versions, the renames that bite you, and one instruction. For example:

## Versions
- Python 3.13, Django 5.x, React 19
- Check package.json or requirements.txt before using any library API.

## Do not use
- datetime.utcnow() -> use datetime.now(UTC)

## Rule
- If you are unsure whether an API is current, look it up before writing it.

The catch is upkeep. The list is only as fresh as the last time you edited it, so keep it short. Let the next two layers do the heavy lifting.

Layer 2: Let the agent read current docs while it works

A docs tool replaces the model’s memory with the library’s real, current documentation at the moment it writes.

First, one prerequisite. MCP (Model Context Protocol, a standard plug that lets an AI agent call outside tools) lets your agent fetch information it was never trained on. Each connected server also adds tokens to every session, as this MCP token cost test shows. A docs server is one such tool: the agent asks it “how do I do X in library Y” and gets the matching page back.

Context7 is a popular open source example under the MIT license. It “pulls up-to-date, version-specific documentation and code examples straight from the source” and feeds them to your agent. Its parsing and crawling backend is private. A free API key raises the rate limit (how many lookups you can make in a given time).

Sequence: you ask the agent for a date picker, the agent asks the docs tool for current docs, and writes code from those docs

For web front-end work, Google Chrome publishes Modern Web Guidance. It is an Apache-2.0 skill pack (a bundle of instructions an agent loads on demand) with over 200 short guides on modern HTML, CSS and browser APIs.

I opened its package and read the guide for exactly our popup. It tells the agent to use a <dialog> opened with showModal(), plus the closedby="any" attribute for click-outside closing. It also warns that this attribute is not supported in every browser. So it is a bonus on top of a working close button, never the only way out.

That is the popup from the opening, done the platform way. Five lines:

<dialog id="feedback" closedby="any" aria-labelledby="t">
  <h2 id="t">Feedback</h2>
  <button commandfor="feedback" command="close">Close</button>
</dialog>
<button onclick="document.getElementById('feedback').showModal()">Open</button>

We already tested Modern Web Guidance in depth, including what its scanner catches and misses, in Is Modern Web Guidance Worth It?.

Layer 3: Make deprecated code fail your checks

Docs make old code less likely; a failing check makes it impossible to merge without someone noticing.

This is the Python flag from earlier, made permanent. If you use pytest (Python’s most common test runner), add this to pytest.ini so any warning during tests becomes a failure:

[pytest]
filterwarnings =
    error

For TypeScript, the typescript-eslint rule @typescript-eslint/no-deprecated “reports on any references to code marked as @deprecated“. It needs type information to run. That makes it a little slower than basic lint rules.

The agent code goes through tests and lint in CI: a deprecated call fails the build, clean code passes

Know the limit. These checks only catch functions the library authors marked as deprecated. A function that was removed outright, or a hand-built overlay when a native tag exists, will not trigger them. That is why Layer 2 still matters.

Check browser support with Baseline

Look it up on Baseline, which tells you in one label whether every major browser supports a feature.

Agents sometimes overcorrect and use a feature so fresh that some browsers lack it. Baseline is a shared label for browser support. “Newly available” means Chrome, Edge, Firefox and Safari all support it; “Widely available” means 30 months have passed since then, so most sites can use it without worrying.

The <dialog> element itself is Baseline Widely available, so the core of our popup is safe everywhere. Good news. Add one line to your rules file, “prefer Baseline Widely available features and give fallbacks for anything newer”, and the agent gets both halves right: modern, but not too fresh.

Set up the rules file and the failing check first

Start with the rules file and the failing check; add a docs tool when you work across many libraries.

FixRough setup timeWhat it catchesWeak spot
Rules file (CLAUDE.md / AGENTS.md)5 minutesYour known renames and versionsGoes stale unless you edit it
Docs tool (MCP, skill pack)10 minutesAnything the current docs coverAgent must actually call it
Failing check (pytest, typescript-eslint)5 minutesCalls marked deprecatedMisses removed APIs and hand-built code

If you only do one thing, add the strict warning check. It turns a silent problem into a visible one. Then the next time you ask for that popup, a stale answer has three chances to get caught before it reaches your users.

Leave a comment