Explainer

What is context engineering? How it differs from prompt engineering, and where the practice stands in October 2026

What is context engineering? It's the work of deciding what goes into an AI model's context window at each step: instructions, files, tool results, memory and history. What Anthropic, OpenAI and LangChain say it is, why long contexts degrade, and how compaction, retrieval, memory and tool-result clearing work, as of October 2026.

A glass context window with old tool results shrunk to dashed placeholders and the three newest tool results kept as lit cards, on coral

In 20 seconds

  1. Context engineering is the work of choosing what goes into a model's context window at each step of a task. Anthropic defines it as 'the set of strategies for curating and maintaining the optimal set of tokens' during inference and calls it 'the natural progression of prompt engineering.'
  2. It exists because longer context isn't free. Chroma's July 2025 study of 18 models found performance 'grows increasingly unreliable as input length grows,' and Anthropic's API docs say response quality degrades as a conversation grows.
  3. The main techniques are retrieval, external memory, compaction, tool-result clearing and subagents. On October 24, 2026, Drew Breunig argued that the core skill is now knowing when to be deterministic and when to be probabilistic.
On this page

What is context engineering? It's the work of deciding what an AI model sees at each step of a task: the instructions, files, tool definitions, search results, memory and conversation history that fill its context window. The term spread among AI agent builders in 2025, when LangChain (in July) and Anthropic (in September) published guides to it, and it still shapes how coding agents like Claude Code manage long sessions. On October 24, 2026, Drew Breunig, whose O'Reilly book The Context Engineering Handbook is due out soon, published "The State of Context Engineering," a write-up of a conference talk that argues the field is now moving from hand-built prompts into the software around the model. If you've ever seen Claude Code compact a conversation while you were away, you've seen context engineering at work.

This explainer is based on Anthropic's engineering post "Effective context engineering for AI agents" (September 29, 2025), Anthropic's Claude API docs on context editing and compaction, the Claude Code docs on the context window, LangChain's July 2, 2025 post on context engineering for agents, OpenAI's September 9, 2025 cookbook on session memory, Chroma's July 14, 2025 "Context Rot" report, and Breunig's October 24, 2026 post, checked October 27, 2026.

The short version

  • Definition: Anthropic calls context engineering "the set of strategies for curating and maintaining the optimal set of tokens" during inference. LangChain calls it "the art and science of filling the context window with just the right information at each step."
  • Versus prompt engineering: prompt engineering is writing the instructions; context engineering manages everything else that reaches the model too, across many turns.
  • Why it matters: models get less reliable as context grows. Chroma calls this "context rot"; Anthropic describes an "attention budget."
  • The toolkit: retrieval when needed, external memory, compaction (summarizing history), clearing old tool results, and subagents with clean windows.
  • Where it's heading: Breunig argues the work is moving into the "harness," the code around the model, and that the core skill is knowing when to be deterministic and when to be probabilistic.

What is context engineering, in plain terms?

A language model only knows what's in its weights and what's in its context window for the current request. Everything an agent "remembers" from earlier in a task has to be sent again as tokens: the system prompt, your project instructions, the list of tools, every file it read and every result a tool returned. Context engineering is deciding what goes into that window, what stays out, and what gets summarized or moved elsewhere.

Anthropic's Applied AI team put it this way in September 2025: the goal is "the smallest possible set of high-signal tokens" that makes the desired outcome more likely. LangChain's July 2025 post quoted Andrej Karpathy describing it as the "delicate art and science of filling the context window with just the right information for the next step." OpenAI's cookbook on session memory doesn't define the term, but frames the same problem: "If too much is carried forward, the model risks distraction, inefficiency, or outright failure."

In a coding agent, the window fills up fast. Claude Code's docs list what loads before you type anything: CLAUDE.md, auto memory, MCP tool names and skill descriptions. Then every file read adds to it. Tool definitions from MCP servers are part of that load, so connected servers take up part of the window before any of their tools is used. What you put in a CLAUDE.md file is context engineering too, as our guide to writing CLAUDE.md and AGENTS.md covers.

How is context engineering different from prompt engineering?

Prompt engineering is about wording: the instructions and examples for a single call. Anthropic calls context engineering "the natural progression of prompt engineering," because an agent works over many turns and most of its context isn't a prompt anyone wrote. It's tool output, retrieved documents and its own earlier messages.

Breunig's post sketches the progression as three terms: prompt engineering (2023) chose words and examples for one call; context engineering (2025) assembled the window dynamically; and what he calls harness engineering (2026) moves more of that work into the scaffolding code. His point is that the goal hasn't changed, only where the work happens. These are his labels; there's no standard definition of "harness engineering."

What is context rot?

Context rot is the drop in reliability as a model's input gets longer. Chroma's researchers coined the term in July 2025 after evaluating 18 models, including GPT-4.1, Claude 4, Gemini 2.5 and Qwen3, on extensions of the needle-in-a-haystack test, the LongMemEval conversation benchmark and a repeated-words task. Their finding: "models do not use their context uniformly; instead, their performance grows increasingly unreliable as input length grows." Those are Chroma's results on the models of mid-2025; our long-context explainer covers what later independent benchmarks show for million-token windows.

Anthropic's engineering post describes the same effect from the builder's side. As the number of tokens increases, "the model's ability to accurately recall" information from that context decreases, and models have an "attention budget" that long inputs draw down. Its current compaction docs put it plainly: compaction "keeps the active context small, because response quality degrades as a conversation grows."

Breunig's talk lists four ways contexts fail, from his June 2025 essays:

  • Context poisoning: an error or hallucination gets into the context and keeps being referenced.
  • Context distraction: a long context pulls the model away from what it learned in training.
  • Context confusion: irrelevant material degrades the answer.
  • Context clash: new information or tools conflict with what's already there.

He cites Google's Gemini 2.5 technical report, where, once an agent playing Pokémon had a context well beyond 100,000 tokens, it began repeating actions from its history instead of making new plans. His summary: "Long contexts let you fit in more information, but they also let you fit in more errors." In 2026, he adds a newer failure he calls "context inertia," where a model fixates on one hypothesis or subtask and keeps pursuing it.

How does compaction work?

Compaction summarizes a conversation that's nearing the context limit and continues from the summary. Anthropic's 2025 post describes it as "taking a conversation nearing the context window limit, summarizing its contents" and starting a new window with that summary. The risk is what the summary leaves out. OpenAI's cookbook lists "Summarization loss & bias" and warns that "If a bad fact enters the summary, it can poison future behavior."

The Claude Code docs, checked October 27, say Claude Code "compacts automatically as you approach the limit, so a full context window doesn't end your session." Some things come back from disk after compaction, such as the project-root CLAUDE.md, auto memory and the plan written in plan mode, and Claude Code re-reads up to five recently modified files. Other things are only summarized, such as rules scoped to file paths. You can also act first:

  • /compact focus on … keeps what you choose rather than what the automatic pass guesses is important;
  • /autocompact with a token count, such as /autocompact 500k, sets how full the window gets before compaction runs;
  • /clear starts fresh between unrelated tasks;
  • /context shows a live breakdown of what's using your window.

Claude Code can also compact a session you leave idle, which can surprise people; our explainer on idle compaction covers why. Compaction reads the whole conversation, so it uses your plan's capacity too, one of the causes our story on fast Claude usage lists.

On the API side, Anthropic's docs describe server-side compaction in beta, where "Compaction replaces the older turns of a conversation with a summary that Claude writes on the server." It can run on demand or when input tokens reach a threshold you set, and Anthropic recommends it over compaction done in its SDKs.

What is tool-result clearing?

It's the lightest form of compaction: dropping old tool output that's no longer needed while keeping the conversation. Anthropic's 2025 post called it "one of the safest lightest touch forms of compaction." A search result or a file listing from 40 steps ago usually isn't worth resending on every turn.

Anthropic's API offers this as "context editing," in beta. Its clear_tool_uses_20250919 strategy clears the oldest tool results once input passes a threshold, 100,000 tokens by default, keeps the three most recent tool uses by default, and replaces cleared results with a placeholder. The trade-off is cost: clearing "invalidates cached prompt prefixes," so the docs suggest clearing enough at once to make the cache miss worthwhile. A separate strategy clears old thinking blocks.

How do memory and retrieval fit in?

Both move information out of the window and bring it back only when it's needed.

  • Retrieval, "just in time": Anthropic describes agents that "maintain lightweight identifiers," like file paths or queries, and load the data through tools at runtime instead of loading everything up front. LangChain calls this "select."
  • Memory, or note-taking: the agent "regularly writes notes persisted to memory outside of the context window," Anthropic writes, and reads them back later. Its API has a memory tool, and the context-editing docs say Claude gets an automatic warning to save important information before tool results are cleared. LangChain calls this "write."
  • Subagents, or isolation: "Specialized sub-agents can handle focused tasks with clean context windows" and return only a condensed summary, in Anthropic's words. Claude Code's docs describe the same thing: a subagent handles research "in its own separate context window, so the large file reads stay out of yours."

LangChain's fourth strategy, "compress," covers compaction and trimming. OpenAI's cookbook adds the simplest option, trimming, which keeps only the last N turns: deterministic and cheap, but it "Forgets long-range context abruptly."

Breunig's talk groups the same ideas into six tactics: context augmentation (retrieval and skills), tool loadout (exposing only relevant tools), quarantine (subagents), pruning, offloading (notes and files) and summarization. He notes that memory can also cause context clash: he turns his chatbot's memory off because it mixed his work and personal projects.

Where does context engineering stand in October 2026?

The vocabulary has settled; the techniques above appear, under different names, in Anthropic's, OpenAI's and LangChain's material and in Breunig's talk. What's changing is who does the work. In 2025, developers wrote compaction and retrieval logic themselves. In 2026, much of it is built into agents and APIs: Claude Code compacts on its own, and Anthropic's API offers server-side compaction and context editing.

Breunig sees two consequences. Models trained on specific harnesses and tools, he argues, can struggle with unfamiliar ones, a problem he calls "fighting the weights." And the new pitch is to "teach the model to drive the harness and manage its own context." His practical advice is simpler: when a coding agent misbehaves, check how big the context has grown. He writes that "around 200,000 or 300,000 is where I start looking" and that about 200,000 tokens is his warning point, even when the window allows more, and asks: "Have you tried resetting your context?"

His prediction for 2027 is that personal agents with long-lived memories and many installed skills will run into conflicting context, making "strategic forgetting" a key problem. That's his forecast, not a finding.

What's confirmed, reported and uncertain

  • Confirmed (vendor docs and posts): Anthropic's definition and techniques (September 29, 2025); Claude Code's compaction behavior, commands and what survives compaction; the API's context editing defaults (100,000-token trigger, three tool uses kept) and server-side compaction, both in beta; LangChain's four strategies (July 2, 2025); OpenAI's trimming and summarization trade-offs (September 9, 2025); Chroma's 18-model context-rot findings (July 14, 2025).
  • Attributed (Breunig, October 24, 2026): the failure modes, the six tactics, the prompt-to-context-to-harness progression, the Gemini 2.5 example, his 200,000-token warning point and the 2027 prediction.
  • Uncertain: how much context rot affects today's frontier models, which no vendor or study cited here measures for October 2026 models; and whether "harness engineering" becomes a standard term.

Read next

Comments (0)

More on AI agents

View all
Agents · NewsSK Telecom gives AI agents employee IDs and human supervisors: what its first AI governance report saysSK Telecom AI agents now get employee IDs once they pass an internal review, and agents with more autonomy must have a team leader or executive as supervisor, according to the company's first AI governance report, published October 26, 2026. What an agent's employee ID means in practice and what rules apply.·6 min read
Agents · NewsThe Week in AI #5: AI-found PHP bugs hit the wild, Anthropic's IPO numbers leak, and Meta's $825 billion in commitmentsAI news for October 19–25, 2026: PHP2Shell and OpenAI's Patch the Planet framework, Anthropic's reported $80.7 billion first-half loss, Meta's capex and commitments, OpenAI models on Google Cloud, new agent-oversight findings, Texas v. OpenAI and DeepSeek's reported $15 billion round.·7 min read
Research · AnalysisAvalon-M1: General Reasoning says its agent teams stopped reporting problems to human overseers as training went onAvalon-M1, a model General Reasoning trains to run as a team of agents with one shared reward, became less likely to report problems to human overseers as training went on, the company's October 2026 preview says. What was measured, the numbers, what it isn't, and the limits.·7 min read
Products · ExplainerAI agents in your text messages, explained: Tab, Poke and the other iMessage and SMS assistantsAI agents in your text messages are a crowded category: TechCrunch counted 24 on October 24, 2026, led by Tab, which launched in early October at a reported $300 million valuation. How they work, what they cost per their own sites, and what to check before handing one your card.·5 min read
The Week in AI · every Friday

New guides and explainers, every Friday.

The week’s biggest stories in AI and tech, what they mean, and what to read next.

Free. One email a week. Unsubscribe in one click.