Context engineering is the practice of deciding what information an AI model sees at each step of its work, so that it has what it needs and as little as possible of what it does not. Anthropic defines it as "the set of strategies for curating and maintaining the optimal set of tokens (information) during LLM inference."
For a single chat question, that mostly means writing a good prompt. For an AI agent that works through dozens of steps, reading files and running commands, it means managing a growing pile of instructions, tool results and history. This guide explains the idea, why it matters, and how it shows up in tools like Claude Code, Codex and Cursor.
What does context engineering mean?
Every time a language model responds, it reads its "context": all the text it has been given for that turn. In an agent, that context includes far more than your message:
- The system prompt and project rules (such as
CLAUDE.mdorAGENTS.md) - Descriptions of the tools the agent can call
- Files it has read and the output of commands it has run
- The conversation so far
- Any notes or memory loaded from earlier sessions
Claude Code's documentation lists exactly this. In How Claude Code works, the context window "holds your conversation history, file contents, command outputs, CLAUDE.md, auto memory, loaded skills, and system instructions."
Context engineering is the discipline of shaping that whole set. Anthropic's engineering post Effective context engineering for AI agents (29 September 2025) is a primary source on it.
How is context engineering different from prompt engineering?
Anthropic's post frames them as stages of the same craft: "we view context engineering as the natural progression of prompt engineering."
| Prompt engineering | Context engineering | |
|---|---|---|
| Anthropic's definition | "methods for writing and organizing LLM instructions for optimal outcomes" | "strategies for curating and maintaining the optimal set of tokens (information) during LLM inference, including all the other information that may land there outside of the prompts" |
| Main question | How should I word this? | What should the model see right now? |
| Typical scope | One request or a system prompt | Many turns of an agent loop |
| Examples | Clear instructions, examples, output format | Tool design, file retrieval, summaries, notes, subagents |
Prompt engineering does not go away. A clear system prompt is still part of good context. It just stops being the whole job once the model is taking actions and pulling in information on its own.
Why does more context not mean better results?
It is tempting to give an agent everything: the whole codebase, every doc, the full chat history. Anthropic's post explains why that backfires.
It describes a phenomenon called context rot: "as the number of tokens in the context window increases, the model's ability to accurately recall information from that context decreases." The post adds that this "characteristic emerges across all models," though some degrade more gently than others.
The post compares this to human working memory: LLMs have an "attention budget" that they draw on when parsing large volumes of context, and "Every new token introduced depletes this budget by some amount." Its conclusion is that context "must be treated as a finite resource with diminishing marginal returns."
Claude Code's best practices say the same thing in practical terms: "Claude's context window fills up fast, and performance degrades as it fills." When it gets full, Claude "may start 'forgetting' earlier instructions or making more mistakes."
So the guiding principle, in Anthropic's words, is "finding the smallest possible set of high-signal tokens that maximize the likelihood of some desired outcome."
What are the main context engineering techniques?
Anthropic's post walks through each part of an agent's context. Here are the techniques, with the coding-agent features that put them into practice.
Write system prompts at the right altitude
Instructions should be clear and direct, at what the post calls "the right altitude," which it describes as "the Goldilocks zone between two common failure modes": brittle, hard-coded rules on one side and vague guidance that assumes shared knowledge on the other. In coding agents, this is your project file. Keep CLAUDE.md or AGENTS.md short and specific.
Keep the tool set small and clear
Tools should be "self-contained, robust to error, and extremely clear with respect to their intended use." The post warns that if a human engineer "can't definitively say which tool should be used in a given situation, an AI agent can't be expected to do better." Claude Code applies a version of this to MCP: tool definitions are "deferred by default and loaded on demand via tool search," so only names use context until a tool is needed. See Claude Code MCP.
Use a few good examples, not a rulebook
Instead of a "laundry list of edge cases," the post recommends "a set of diverse, canonical examples that effectively portray the expected behavior of the agent."
Load information just in time
Rather than loading everything up front, agents can keep lightweight references (file paths, links) and fetch the details when needed. The post uses Claude Code as its example of a hybrid approach: "CLAUDE.md files are naively dropped into context up front, while primitives like glob and grep allow it to navigate its environment and retrieve files just-in-time." Agent Skills follow the same idea: Claude Code sees skill descriptions at session start, but "the full content only loads when a skill is used."
Compact long sessions
The post defines compaction as "taking a conversation nearing the context window limit, summarizing its contents," then continuing in a fresh window with the summary. Claude Code does this automatically: it "clears older tool outputs first, then summarizes the conversation if needed." You can steer it with /compact plus a focus, for example /compact focus on the API changes. Our Claude Code context window guide covers the details.
Keep notes outside the context window
"Structured note-taking, or agentic memory, is a technique where the agent regularly writes notes persisted to memory outside of the context window." The post's examples are Claude Code creating a to-do list or a custom agent maintaining a NOTES.md file. Claude Code's auto memory is a built-in version; see Claude Code memory.
Hand focused work to subagents
"Specialized sub-agents can handle focused tasks with clean context windows," and each returns "a condensed, distilled summary of its work." In Claude Code, each subagent "runs in its own context window," so its file reads stay out of your main conversation.
How do you practice context engineering in Claude Code, Codex and Cursor?
You do not need to build an agent to use these ideas. In daily work with a coding agent:
- Keep the project file lean. Put lasting rules in
CLAUDE.mdorAGENTS.md; OpenAI's docs say "Codex reads AGENTS.md files before doing any work." Cursor uses rules for the same job. - Point to sources instead of pasting them. Name the file or folder and let the agent read it.
- Check what is using space. In Claude Code, run
/context. - Start fresh between unrelated tasks rather than carrying a long, mixed history.
- Move repeatable procedures into skills so they load only when relevant.
read src/auth and summarize how sessions work in 10 lines.
then plan the change before editing anything.
A prompt like this asks for a short summary that stays in context, instead of leaving thousands of lines of raw file content behind.
Where should reusable context live?
Good context engineering pushes instructions out of the chat and into files you can reuse: project rules, skills and saved prompts. Kipt stores prompts and Agent Skills as Markdown in a private GitHub repo you own and can install every skill into Claude Code or Codex with npx skills add https://github.com/<you>/<repo>.git --all -g. To turn a single prompt into a SKILL.md, try the free SKILL.md generator.
What should you read next?
New to agents? Start with what is an AI coding agent. For the workflow that puts context engineering into practice, see agentic coding. And because every file and web page an agent reads becomes part of its context, read prompt injection in coding agents to see how untrusted content can turn context into an attack.