Research

Context Engineering: Designing Everything the Model Sees

Field Note

Most teams trying to make AI work harder spend their time rewriting one prompt. Then they rewrite it again. The output wobbles, they add another paragraph of instructions, and the cycle repeats.

The fix is usually not in the prompt. It is in everything around the prompt: the instructions file, the documents retrieved, the tools exposed, the state carried between sessions. Designing that whole surface is context engineering, and in our client work it has been the single highest-leverage layer.

Short answer

Context engineering is the practice of designing everything an AI model sees at the moment it acts: instruction files, retrieved documents, tool definitions, state files, and memory, not just the prompt. Because a model only knows what is inside its context window, fixing that surface is cheaper and more reliable than upgrading the model. In our client work, context engineering has been the single highest-leverage layer for AI reliability.

Chalk illustration of a stick figure positioning instruction files, documents, tools, and state files in a ring around a glowing blue eye that represents the model's field of view
Everything the model sees is a design surface.

What Is Context Engineering?

Context engineering is the discipline of designing the model's entire field of view at the moment it acts: instructions, retrieved documents, tool definitions, state files, and memory, not just the prompt. A model knows nothing about your business beyond its context window, so the system that fills that window decides the quality of the output.

Prompt engineering optimizes a single message. Context engineering designs the model's entire field of view at the moment it acts, what Anthropic's engineering team describes as curating the optimal set of tokens the model sees at inference time. A language model has no knowledge of your business except what is in its context window right now. It does not remember last week. It does not know your file structure, your tone rules, or the decision your team made on Tuesday, unless something puts that information in front of it.

Once you see it that way, the question changes. It stops being "how do I phrase this request?" and becomes "what does the model need to see to do this job, and what is the system that reliably puts it there?"

What Counts as Context?

Context covers six input types: standing instruction files, retrieved documents, tool definitions, state files, persisted memory, and the conversation history itself. Each one shapes the model's behavior, and each one can be designed deliberately. Most teams have only ever edited the first few words of the first one.

When we audit an underperforming AI system, we map every input the model receives. The list is always longer than the team expects:

Every one of those is a design surface. The same map applies whether the system is a coding agent or the workflow automation behind a back office: the inputs nobody designed are where reliability leaks out.

How Does the File-State Pattern Work?

If a fact matters, it lives in a file in the repository, not in chat history and not in anyone's head. An instructions file carries durable rules, a progress file carries position, and a decisions file carries reasoning. A fresh session must be able to rebuild its bearings from those files alone.

The most useful pattern we run is simple: if a fact matters, it lives in a file in the repository, not in anyone's head and not in the chat history. The repo is the spec. A standing instructions file at the root carries the project overview, the hard constraints, and the exact commands that verify the work. Progress and decisions get written to dedicated files at the end of every working session.

The test we apply is the fresh-session test. Open a brand new session with no history and ask the agent to continue the work. If it cannot rebuild its bearings from the files alone in a few minutes, the context design has a hole. Chat history is not infrastructure. Files are.

The division of labor between files matters too. The instructions file carries durable rules: stack, constraints, how to verify work. The progress file carries position: what is finished, what is in flight, what comes next. The decisions file carries reasoning: what was chosen, what was rejected, and why, so the same debate does not get relitigated by a model that was not in the room. Mix those three up and every file becomes a junk drawer nobody trusts. Anthropic's own Claude Code guidance applies the same discipline to its instructions file: keep it short and prune it ruthlessly, because a bloated file causes the model to miss the rules that matter.

This is the same discipline we install when we build custom AI agents for clients: the agent's world is defined in files the client can read, audit, and change. Context is one of five subsystems in the larger reliability doctrine we cover in our harness engineering field note.

Chalk illustration of three labeled files, instructions, progress, and decisions, feeding into a fresh terminal session on a chalkboard
Three files, three jobs: rules, position, reasoning.

Why Is Context the Highest-Leverage Layer?

Because the same model that fails a task with poor context often completes it cleanly once the context changes, and nothing else did. A context fix is a one-time edit to a versioned file you own. A model upgrade raises your bill on every call, forever. Prove the context right before blaming the model.

We have watched the same model fail a task repeatedly, then complete it cleanly after the context changed and nothing else did. No bigger model, no clever phrasing. The difference was a constraints file it could actually find, a verification command it could actually run, and state it could actually read.

That experience repeats often enough that we treat it as a rule: before you blame the model or pay for a bigger one, prove the context was right. Capability is not the bottleneck nearly as often as people assume. Visibility is.

There is also a cost asymmetry worth naming. A model upgrade raises your bill on every single call, forever. A context fix is a one-time edit to a file you own, it is versioned in git, anyone on the team can read it, and it keeps paying off when the next model arrives. Cheap, auditable, durable. That is why context is the first place we look and the last thing we give up on.

What Are the Most Common Context Failure Modes?

Three failures dominate: context rot, where instruction files bloat until key rules sit in the middle where models attend worst; stale memory, where outdated notes drive confident wrong answers; and silent retrieval misses, where the pipeline returns the wrong document and nobody notices. All three are predictable, and all three are fixable.

Context fails in predictable ways, and the research backs the patterns we see in client work. The Lost in the Middle study found that a model's accuracy on a document question task can drop by more than 20 percent just by moving the relevant document to the middle of the context, in the worst case scoring below the 56.1 percent the same model managed with no documents at all. Position is not a detail. Three failure modes show up constantly:

FindingEvidenceSource
Models attend worst to the middle of long contextsGPT-3.5-Turbo's multi-document QA accuracy drops by more than 20 percent as the relevant document moves position; in 20 and 30 document settings, worst-case performance falls below its 56.1 percent closed-book scoreLiu et al., Lost in the Middle (TACL 2024)
Recall degrades as the context window fillsAs token count grows, a model's ability to accurately recall information decreases, a gradient Anthropic calls context rotAnthropic, Effective Context Engineering for AI Agents (2025)
Bloated instruction files get ignoredAnthropic's guidance for its own coding agent: keep the instructions file concise, because overlong files cause the model to lose the rules that matterClaude Code documentation, Best Practices
Source: Liu et al., arXiv:2307.03172; Anthropic engineering blog, Sep 2025; Claude Code docs

Catching these failures is an evaluation problem as much as a context problem. Our note on AI agent evaluation covers the discipline that surfaces them: a checker separate from the worker, and tests that refute "it works" instead of confirming it.

How Do We Apply Context Engineering in Client Work?

On every engagement, context work comes before model work. We write the instructions file first, define the verification commands second, and wire state persistence third. Only then do we tune prompts, and by that point there is usually little tuning left to do. Most reliability complaints trace back to a context layer nobody designed.

On every engagement, context work comes before model work. We write the instructions file first, define the verification commands second, and wire state persistence third. Only then do we tune prompts, and by that point there is usually little tuning left to do. The same sequence drives our AI consulting diagnoses: most "the AI is unreliable" complaints trace back to a context layer nobody designed on purpose. It is also how a system like our AI receptionist stays on script across thousands of calls: the rules live in files it loads every time, not in anyone's memory of a prompt that once worked.

If your AI system is inconsistent, do the cheap experiment before the expensive one. Write down everything the model sees. Fix the worst gap. Run the task again and compare. Only after the context is provably right do we let anyone blame the model, and by then there is usually nothing left to blame.

Chalk illustration of a custom AI agent at the center of the files, tools, and documents that define its working world
An agent is only as good as the context it is handed.

Common Questions

Is context engineering replacing prompt engineering?
It absorbs it. The prompt is one input among many, and usually not the weakest one. Teams that design instructions, retrieval, tools, and state get more reliability gain than teams that only iterate on phrasing.
How large should an instructions file be?
Short at the entry point. We aim for a router of 50 to 200 lines: project overview, hard constraints, verification commands, and links to topic files. Long encyclopedic files get ignored from the middle out.
Does this matter for a team that just uses a chatbot?
Less, but not zero. Custom instructions, uploaded reference docs, and a consistent way of stating constraints are all context engineering at small scale. It matters most once AI starts doing multi-step work with tools.

Sources

SourcePublisherLink
Effective Context Engineering for AI AgentsAnthropicwww.anthropic.com
Lost in the Middle: How Language Models Use Long ContextsLiu et al., TACL 2024 (arXiv)arxiv.org
Best Practices for Claude CodeAnthropic, Claude Code documentationcode.claude.com
Building Effective AI AgentsAnthropicwww.anthropic.com

Keep Exploring

Chalk stick figure in a hard hat presenting a little machine of blue gears it just built

Bring us the bottleneck.
We’ll build the system.

No Dreaming. Just Building.