Legacy context
_When I started working with AI agents, there was some buzz around building context for them. I even had a line in my AGENTS.md saying "document every architecture change in the relevant /docs folder".
Not only did I delete that line, I also deleted the entire docs folder from our codebase. Here's why.
The short version:
If you can't stand behind why you're adding a fact to an agent's context, and that fact can be learned by reading the code, don't add it.
The question isn't whether to give agents context. It's which context: curated by a human and not repeating the code, or generated and redundant.
Context can save tokens, if it's the right context
Most context gets added on an intuition: if I tell the agent how the system works, it won't have to spend tokens figuring it out. The research on this looks contradictory at first.
Lulla et al. ran a paired experiment on 124 real pull requests. With an AGENTS.md, agents finished with 28.64% lower median runtime and 16.58% fewer output tokens, and completed about as many tasks.
An ETH Zurich study found the opposite. Context files tended to lower task success compared to no context at all, and raised inference cost by over 20%. LLM-generated files hurt the most, while developer-written ones slightly helped. The extra cost didn't come from agents ignoring the files. It came from agents following them: more exploration, more testing, more reasoning to satisfy requirements the task didn't need.
Both are right. Context saves tokens when a human wrote it and it doesn't repeat what the code says. It costs tokens when it's generated, redundant, or full of requirements the task doesn't need. It's the same reason Addy Osmani argues to stop using /init to generate AGENTS.md.
Complete context turns into legacy context
My docs instruction aimed at completeness: every architecture change, written down. Nobody keeps that up by hand, so you hand it to agents, and the docs get regenerated as the code changes.
Two things follow.
Slop is unavoidable. Generated context drifts from the truth. And because agents believe what's in their context, drift isn't harmless. Duncan Davidson describes an agent that kept an obsolete data-layer pattern in a new feature, because an ADR still marked it as required. The code had moved on. The doc hadn't, and the agent trusted the doc.
Relevancy is lost. You end up with a lot of context that you:
- can't verify,
- don't know how to associate with your next task,
- are afraid to delete, because you don't know how it affects the agents.
I call this legacy context, because it behaves like legacy code: it's there, nobody fully trusts it, and nobody dares to remove it.
Three circles
Good context sits where three circles overlap:
- Completeness: the agent has everything it needs.
- Correctness: what it has is accurate.
- Relevancy: what it has matters for the task.
* Good for this task. You don't know whether the next task has the context it needs.
Chasing completeness with generated docs erodes the other two. Drew Breunig names four ways contexts fail, and legacy context sets up all four:
- Context poisoning is the correctness failure. An error enters the context and gets referenced again and again.
- Context distraction is what the pile does. The context grows so long that you enter what Matt Pocock calls the "dumb zone": the agent gets sloppier, more forgetful, and makes more mistakes.
- Context confusion is the relevancy failure. Superfluous information gets used to produce a low-quality response.
- Context clash is the doc saying one thing and the code another, with both in the context.
I'd add a fifth, missing context, which is the completeness failure. What's in the context gets more attention than what isn't. The missing piece might be exactly the one that covers an edge case in your next task.
What earns a place
The burden of proof is on the addition, and the facts that pass are the ones the code can't reveal.
ADRs (Architecture Decision Records). The code shows what was built. It doesn't show why, or what was considered and ruled out. An agent that knows you already tried event sourcing and backed out of it won't suggest it again. ADRs can go stale too, as the example above shows. The difference is that an ADR records a decision, so keeping it honest is a single step: mark it superseded when the decision changes. I'd also add one line to AGENTS.md, so the agent doesn't treat an old decision as a spec for today's code:
ADRs record why decisions were made; the code shows current behavior.
A GLOSSARY.md. This one doesn't explain the code at all. It's rooted in Domain-Driven Design and what Eric Evans calls a ubiquitous language: a common, rigorous language between developers and users, based on the domain model in the software. The glossary writes that language down, so agents speak it too. When a ticket says "workspace" and the code says Tenant, the glossary bridges the two, and the agent goes and reads the code itself. That's progressive disclosure: a small entry point instead of everything loaded up front.
You don't need a full process to start. Matt Pocock's /domain-modeling skill builds and sharpens the glossary as you design, but a plain list of your domain terms, each with a one-line definition, is enough.
Once you have more than one kind of context, you might also want a standard facts model, so everyone, humans and agents, knows where each fact belongs. For example:
AGENTS.md: hard rules that every session needs.RUNBOOK.md: troubleshooting and runbooks..agents/skills: repeated procedures.- ADRs: why decisions were made.
GLOSSARY.md: the ubiquitous language.
What about docs for humans?
A common objection: the docs are for humans, not agents. I'd argue a cheap model serves humans better. Ask it how a flow works, even one you've never seen the code for, and you get what the docs would have told you, faster, and with no docs to keep up to date.
If you want to go further, there are skills built for learning concepts. Matt Pocock's /teach teaches a topic in short lessons across sessions, and Dex Horthy's /show-me explains it visually, with compact diagrams and code sketches.
How I'd start instead
- Start with only what the code can't tell. Let the agent read the code for the rest.
- Watch where it struggles. When it does, ask whether the missing piece is something the code could have told it. If it is, fix the code, not the context. Make the code structure speak your domain model and reduce cyclomatic complexity, and the agent gets its answers more efficiently by reading.
- If the code can't tell it, write it down, but only if you understand it and can stand behind it. If you can't, don't add the statement.
- Prefer progressive disclosure over loading everything up front. A glossary is a good first step.
Anything you add that you can't understand or stand behind will end up as legacy context.
There's a lot more to write about here: context graphs, how to build effective skills, how to actually measure whether context helps, and how to keep it up to date. I'll leave those for another time.
PS: some of these references are about a year old, and models and harnesses are improving fast. I don't think that changes the principles. If anything, models are getting stronger and more efficient, so adding context probably matters less for getting the task right.
That's about correctness, not cost. Less context might cost more tokens. But with AI, I think reliability matters more in most cases. I'd rather hand agents fewer tasks and know they're reliable than have agents sprawling with no control over their efficiency.
References
- Jai Lal Lulla et al., On the Impact of AGENTS.md Files on the Efficiency of AI Coding Agents, 2026.
- Thibaud Gloaguen et al. (ETH Zurich), Evaluating AGENTS.md: Are Repository-Level Context Files Helpful for Coding Agents?, 2026.
- Addy Osmani, Stop Using /init for AGENTS.md.
- Duncan Davidson, Coding agents love decision records, O'Reilly Radar.
- Matt Pocock, Smart zone, AI Coding Dictionary, AI Hero.
- Matt Pocock, The /domain-modeling Skill, AI Hero.
- Eric Evans, Domain-Driven Design: Tackling Complexity in the Heart of Software, Addison-Wesley, 2003.
- Martin Fowler, Ubiquitous Language.
- Matt Pocock, The /teach Skill, AI Hero.
- Dex Horthy, show-me: a coding agent skill for compact visual representations, HumanLayer, 2026.
- Drew Breunig, How Long Contexts Fail, 2025.