Key takeaways

  • Context engineering manages everything a model sees on each turn: instructions, tools, retrieved data, history, tool results and memory.
  • Anthropic says recall drops as the context grows, so the goal is the smallest set of high-signal tokens, not the fullest window.
  • Anthropic and OpenAI now offer compaction in their APIs, and Anthropic's context editing clears old tool results at 100,000 input tokens by default.

Context engineering is the work of deciding what goes into an AI model's context window at each step: the instructions, the tools, the documents, the conversation history and the results of earlier tool calls. Prompt engineering is writing one good prompt. Context engineering is managing everything the model sees, turn after turn, which is what an AI agent needs when it runs for hours.

A model only knows what is in front of it. An agent that has read dozens of files and made a few mistakes carries all of that into its next decision unless something takes it out. Context engineering is that something.

Where the term came from

The phrase spread in mid-2025, as agents began running long tasks. LangChain's post on context engineering for agents, published July 2, 2025, quotes Andrej Karpathy calling it the "delicate art and science of filling the context window with just the right information for the next step." It also borrows his picture of a language model as an operating system, with the model as the CPU and the context window as the RAM.

Anthropic followed on September 29, 2025 with Effective context engineering for AI agents. It defines the job as curating the set of tokens a model sees during inference, everything besides the prompt included. The goal, in its words, is "the smallest possible set of high-signal tokens" that makes the result you want most likely.

Context engineering vs prompt engineering

Anthropic calls context engineering the next step after prompt engineering, not a replacement. The system prompt still matters. It is now one input among many.

Prompt engineering Context engineering
What it shapes The instructions, mostly the system prompt Everything in the window: instructions, tools, examples, retrieved data, history, tool results, memory
When it happens Once, when you write the prompt Every turn
Typical setting A single question and answer An agent calling tools in a loop
Main question How should I word this? What should the model see now, and what should it stop seeing?

Why bigger windows don't solve it

Claude Haiku 5.5 and Claude Fable 5.2, launched on October 7 and November 9, 2026, read up to 1 million tokens each, according to Anthropic's release notes. Filling that space still costs two things.

The first is accuracy. Anthropic says that as the tokens in the window grow, the model's ability to recall information from them falls. This is context rot. In a transformer every token attends to every other one, so the relationships grow with the square of the length, and models see fewer very long sequences in training. The decline is gradual, but it starts well before the window is full.

The second is money. Manus, which builds a general-purpose agent, wrote in a July 18, 2025 post that its agent reads about 100 tokens for every one it writes. At the Claude Sonnet prices it quoted, cached input cost $0.30 per million tokens and uncached input $3. So Manus keeps the start of its prompt stable, which keeps the cache working.

How it is done

LangChain sorts the techniques into four moves: write information outside the window (a scratchpad, a to-do file, memory), select what to pull back in (retrieval, choosing which tools to show), compress what is there (summaries, trimming old tool output) and isolate work in separate windows (sub-agents, sandboxes).

Anthropic's post adds practical rules:

  • System prompts should sit at the right altitude: neither brittle if-then rules nor vague advice. Start minimal on the best model you have and add instructions only for failures you see.
  • Tools should return compact results and overlap as little as possible. If an engineer can't tell which tool fits, the agent can't either.
  • Just-in-time retrieval keeps light references, such as file paths or links, and opens them when needed. Claude Code loads its CLAUDE.md files up front and uses commands like head and tail to look at large files without loading them in full.

For tasks that outgrow one window, Anthropic names three techniques:

  1. Compaction: summarize the conversation near the limit and continue from the summary. Clearing old tool results is the lightest form.
  2. Structured note-taking: the agent writes notes to a file, such as a NOTES.md, and reads them back later.
  3. Sub-agents: a lead agent hands work to sub-agents with clean windows, and each returns a summary, often 1,000 to 2,000 tokens.

Compaction is now an API feature

What started as advice is now a parameter. Anthropic's compaction docs describe a server-side feature in which Claude summarizes older turns and the summary replaces them. It comes in two forms, both in beta as of November 27, 2026: on demand, when the application asks, or at a token threshold the developer sets.

Anthropic's context editing beta clears content by rule instead. By default it starts at 100,000 input tokens, keeps the 3 most recent tool results and replaces older ones with placeholders. The docs warn that each clear invalidates the prompt cache from that point, the same cost Manus describes.

OpenAI's compaction guide offers the same choice in the Responses API: automatic compaction past a compact_threshold, or a separate /responses/compact call. Its compaction item is encrypted and opaque, so people can't read what it kept. Coding tools expose the idea as commands, such as /summarize in Cursor and /compact in Codex.

Memory across sessions

Compaction works inside one session. Memory carries knowledge to the next. Anthropic's November 6, 2026 post, The components of agent memory, splits it into transcripts, the agent's notes, structured pages built from them, and a small layer injected into every new session. It also describes Claude dreaming, an offline pass in which Claude rereads its logs and rewrites its notes.

On Anthropic's own CL-Bench database task, Claude Opus 5.5's mean reward rose from 0.655 to 0.838 with memory. The post adds a warning that fits the theme: the injected layer costs tokens every session, so it must stay small.

What the research says

The paper Agentic Context Engineering (ACE), from researchers at Stanford, SambaNova and UC Berkeley, treats the context as a playbook that improves with use. A generator attempts tasks, a reflector pulls lessons from the results, and a curator merges them in as small itemized updates instead of rewriting everything.

The authors say rewriting causes "context collapse," where details wear away over repeated summaries. They report gains of 10.6% on agent benchmarks and 8.6% on finance tasks, and say ACE matched the top production agent on the AppWorld leaderboard while running on the open-weight DeepSeek-V3.1. The code is on GitHub. The paper notes the method depends on a reflector good enough to find real lessons.

The common thread across these sources is restraint. A million-token window is a bigger desk, and the agent still works better when the desk is clear.

Frequently asked questions

What is the difference between context engineering and prompt engineering?

Prompt engineering is writing and organizing the instructions, mostly the system prompt, once. Context engineering decides on every turn what the model sees, including tools, retrieved documents, history and tool results, and Anthropic describes it as the next step after prompt engineering.

Who coined the term context engineering?

The term spread in mid-2025. LangChain's July 2, 2025 post quotes Andrej Karpathy describing it as filling the context window with just the right information for the next step, and Anthropic published its own guide on September 29, 2025.

What is agentic context engineering?

Agentic Context Engineering (ACE) is a 2025 paper from Stanford, SambaNova and UC Berkeley researchers. It treats the context as a playbook that a generator, a reflector and a curator update in small steps, and reports gains of 10.6% on agent benchmarks and 8.6% on finance tasks.

Does a bigger context window make context engineering unnecessary?

No. Anthropic says a model's recall declines as the context grows, and long contexts also cost more and run slower, so even 1 million token models need the window managed.

Sources

  1. Effective context engineering for AI agentsAnthropic
  2. Context engineering for agentsLangChain
  3. Agentic Context Engineering: Evolving Contexts for Self-Improving Language ModelsarXiv
  4. ACE code repositoryGitHub
  5. Context Engineering for AI Agents: Lessons from Building ManusManus
  6. Compaction overviewAnthropic
  7. Context editingAnthropic
  8. Compaction guideOpenAI
  9. The components of agent memoryAnthropic
  10. Claude Developer Platform release notesAnthropic

Add ClaudeGPT Si as a preferred source on Google