On this page8 sections
Context engineering is the practice of deciding what an AI model sees at each step of a task. That means the instructions, examples, tool definitions, documents, conversation history and memory that fill its context window before it answers. Prompt engineering asks how to word a request. Context engineering asks what the model needs in front of it, and what it should never see.
It matters because agents now work through dozens of steps. Every file they open and every tool result they get lands in the same window, and models get less reliable as that window fills. The fix is rarely a cleverer prompt. It is a tidier desk.
- The context window is everything a model reads before it answers. Treat it as a budget, not a storage bin.
- More is not better. Models get less reliable as input grows, a pattern called context rot.
- Six things compete for the space: instructions, examples, tools, retrieved documents, history and memory.
- Four techniques keep it lean: retrieve just in time, compact old history, hand side quests to subagents, and keep notes in files.
- Most agent failures trace back to too much, stale or conflicting context, not to wording.
What is context engineering?
Context engineering is the craft of filling that window on purpose. Anthropic’s applied AI team describes it as curating and maintaining the right set of tokens while a model works, including everything that lands there besides the prompt itself.
Their target is worth memorizing: find “the smallest possible set of high-signal tokens” that gets you the result you want. Everything else is noise, and you pay for noise in accuracy, time and money.
New to tokens? Start with tokens and context windows, explained without math.
Context engineering vs prompt engineering
Prompt engineering is not dead. It is now one part of a bigger job.
| Prompt engineering | Context engineering | |
|---|---|---|
| The question | How should I word this request? | What should the model see at this step? |
| Scope | One message or system prompt | Everything in the window, across many turns |
| Matters most for | Single answers and one-off tasks | Agents, long tasks, anything with tools |
| Typical fix | Rephrase it or add an example | Cut noise, fetch the right file, summarize history |
| Failure looks like | A vague or off-target answer | An agent that drifts, forgets rules or repeats mistakes |
A chatbot answering one question lives or dies by the prompt. An agent fixing a bug over forty steps lives or dies by what piles up along the way. Our prompt engineering guide covers the wording side.
Why a bigger context window is not the answer
Context windows have grown fast. As of September 2026, Anthropic’s current Claude models accept up to one million tokens, which its docs put at roughly 555,000 words. That is several novels. It is tempting to pour everything in.
The research says not to. Chroma tested 18 models in 2025. Performance “grows increasingly unreliable as input length grows,” the researchers wrote. They also found that models answered better from a short, focused prompt than from a full conversation history, even with their thinking modes turned on.
Position matters too. A 2023 study, “Lost in the Middle,” found that models use information best when it sits at the start or the end of a long input, and worst when it is buried in the middle.
Anthropic’s engineers call this an attention budget. Every token you add draws it down a little. Long inputs also cost more and take longer to process, so a lean window is faster and cheaper as well as sharper.
What goes into the context window
Six kinds of content compete for the same space. Each one should earn its place.
| Ingredient | What it is | Keep it lean by |
|---|---|---|
| Instructions | The system prompt and project files such as AGENTS.md | Stating each rule once, clearly, with the reason |
| Examples | Sample inputs with ideal outputs | Using two or three varied ones, not twenty |
| Tools | Tool descriptions and every result they return | Enabling only what the task needs and trimming big outputs |
| Retrieved documents | Files, search results, database rows | Fetching the relevant part, not the whole archive |
| Conversation history | Every earlier turn, including the agent’s own actions | Summarizing old turns and dropping raw logs |
| Memory | Notes and preferences kept between sessions | Saving decisions and facts, not transcripts |
Instructions deserve the most care, because the model rereads them on every step. Anthropic advises writing them at the “right altitude”: specific enough to guide behavior, but not a brittle list of if-then rules. For coding agents, they usually live in a project file, and our AGENTS.md guide shows what belongs in one.
Tools are easy to overlook. In most setups, every tool description sits in the window whether the model uses it or not. One verbose result, such as a full test log, can crowd out everything else.
Four techniques that keep context lean
Retrieve just in time
Instead of loading everything up front, keep lightweight pointers such as file paths, links and saved queries. The agent opens what it needs when it needs it, the way you use a search box instead of memorizing a library. RAG explained covers the retrieval side in depth. That search usually runs on embeddings, the numbers a retrieval system compares to find the closest match.
Compact the history
When a long session nears its limit, summarize it and continue from the summary. Keep decisions, open bugs and next steps. Drop tool output that has already done its job. Some agents do this for you, and you can always do it by hand:
Summarize this session so a new session can continue without the history. Include: 1. The goal, in one sentence. 2. Decisions we made, and why. 3. What is done, with file names. 4. What is broken or unfinished, with exact error messages. 5. The next three steps. Leave out raw logs, abandoned dead ends and anything already fixed.
Hand side quests to subagents
A subagent is a helper that gets its own clean context window for one job, such as searching a large codebase. It explores freely, then returns a short summary to the main agent instead of every file it read. Anthropic says these summaries are often 1,000 to 2,000 tokens. The main agent’s window stays clear for the real work.
Keep notes in files
Have the agent keep a progress file, such as a to-do list or a NOTES.md, and reread it before each new step. Notes survive compaction and fresh sessions, so the agent does not rediscover the same facts twice.
Why agents drift: five common context failures
When an agent starts ignoring rules or repeating mistakes, the cause is usually one of these.
Context rot. The session is simply too long. The agent forgets early instructions, and a fixed bug comes back. Compact, or restart with a summary.
Distractors. Content that looks relevant but is not, such as an old copy of a file or a similar function. Chroma found that even a single distractor lowered accuracy. Retrieve narrowly.
Conflicting instructions. The system prompt says one thing, a project file another, and your latest message a third. Keep one source of truth, and delete the old rule when you add a new one.
Stale instructions. The rules file still says
npm testafter the team moved to another test runner. The agent follows the file, confidently.Poisoned context. A wrong fact or a made-up result early in the session gets treated as true and built on. Correct it explicitly, or restart clean.
A context engineering checklist
FAQ
Is context engineering just prompt engineering with a new name?
Partly. Prompt engineering is one piece of it. Context engineering covers everything else the model sees, such as tool results, documents and history, and it matters most for agents that work over many steps.
If a model can read a million tokens, why bother?
Because capacity is not attention. Chroma’s research found models get less reliable as input grows, and long inputs cost more and run slower. A focused window beats a full one.
What is context rot?
Context rot is the drop in accuracy as a model’s context fills up: the more it holds, the less reliably the model recalls and uses any one part of it. Compaction, subagents and fresh sessions are the usual fixes.
How do I apply this in a coding agent?
Keep a short project instructions file, and start a new session for each unrelated task. Ask the agent to write its progress to a file, summarize long sessions, and turn off tools you are not using.
- Context engineering decides what the model sees at each step.
- Treat the window as a budget: every token should earn its place.
- A bigger window does not cure context rot. Focus does.
- Retrieve just in time, compact history, use subagents and keep notes.
- Keep instruction files short, current and free of contradictions.
Next, see how agent skills load know-how only when it is needed, or brief every coding agent at once with an AGENTS.md file.
- Effective context engineering for AI agents, Anthropic, September 2025
- Context rot: how increasing input tokens impacts LLM performance, Chroma, July 2025
- Lost in the middle: how language models use long contexts, Liu et al. (TACL), July 2023
- Models overview, Anthropic, September 2026




