Glossary

What is context rot?

Context rot happens when an AI coding agent's context window fills up with contradictory instructions, error logs, and expired rules. The model loses the ability to determine which instructions are still valid, so instead of executing, it starts guessing.

How it happens

Every message in a coding session adds to the context window. At the start of a project, the context is clean—holding only your initial instructions, a clear task, and a fresh codebase. The model performs well because the signal-to-noise ratio is high.

As the session drags on, noise accumulates:

  • Error messages from failed attempts
  • Rollback instructions that contradict earlier ones ("don't touch auth.ts" after you already told it to rewrite it)
  • Unresolved debugging detours
  • Expired rules that no longer apply to the current code state

The model doesn't know which of these still matter. Because it is trained to predict the next token based on everything in context, it weighs all of it, valid and invalid together.

Why it causes hallucinations

Context rot isn't a model failure. The model is doing exactly what it was designed to do. The problem is the context itself has become unreliable. When the model hits a point where the active rules are unknown, it falls back on pattern matching. It generates code that looks right based on its training data, rather than your actual architecture. That's the hallucination: confident output that has absolutely nothing to do with what your codebase needs.

How to prevent it

Three things reduce context rot:

  1. Start fresh sessions for major shifts. Don't try to pivot a session that is already deep into a debugging spiral.
  2. Keep an architecture spec in your root directory. Tag it at the start of every Composer or Agent session. This ensures the model always has a clean source of truth to anchor against, regardless of what else accumulates.
  3. Use MCP to persist your spec across sessions. An agent that reads your architecture document directly (every session, automatically) never starts from noise.

The hallucinations don't stop because the model got smarter. They stop because you stopped asking it to guess.


Related terms

Used in