Blog

Context Engineering vs Prompt Engineering: Claude Code Guide

Markdown

What context engineering is and how it differs from prompt engineering. The Anthropic canon, 7 mistakes, and a minimal setup for Claude Code.

Read full article

Key points

Context engineering is the discipline of configuring everything that enters Claude’s context window before your message: the system prompt, tools, history, memory files, and data from tools. In 2026, it has replaced prompt engineering as the key skill—that’s what Anthropic says. This guide covers the canon from primary sources, 7 common mistakes that burn tokens, and a practical 7-step setup for Claude Code.

Information about working with Ailoot is available in the documentation.

What Is Context Engineering—in One Line?

Key points

Context engineering is the discipline of curating everything that enters an AI agent’s context window at each step: the system prompt, tools, history, memory files, and data from external sources. Prompt engineering answered the question “How do you write a prompt?” Context engineering answers the question “What does the AI know when you write a prompt?”

Anthropic established the term in an engineering blog post on September 29, 2025:

Context engineering is the set of strategies for selecting and maintaining the optimal set of tokens (information) during LLM inference, including everything that goes in besides the prompts themselves.
— Anthropic Applied AI team, https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents

The same article offers the most important phrase for changing perspective:

Working with language models is becoming less about finding the right words and phrases in prompts and more about answering a broader question: 'what context configuration is most likely to produce the desired model behavior?'
— Anthropic Applied AI team, https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents

The main idea: context is not the message you write. Context is the entire set of information the AI sees before your message—the system prompt, tool descriptions, conversation history, memory files, and data loaded through MCP. The prompt is the final step. Context engineering is the architecture of everything fed into the window.

Why Did Prompt Engineering Become Outdated in 2026?

Key points

Prompt engineering was born when models worked with a single prompt—one turn, one task. AI agents in 2026 run in long sessions with tools, memory, subagents, and data retrieved on the fly through tools. In this architecture, wording a single prompt is no longer the main skill; curating all the information the agent sees is.

The shift happened over the summer of 2025. On September 29, 2025, Anthropic established the discipline in an engineering blog post and provided a canon of 4 principles.

Prompt engineering has not “died.” It has become basic literacy, like knowing how to type on a keyboard. On top of it, a discipline has emerged without which AI agents break down on long tasks: context engineering.

How Does Context Engineering Differ from Prompt Engineering? 5 Differences

Key points

Prompt engineering optimizes a single prompt: you choose the wording, template, and tone. Context engineering architects the entire information environment before that prompt: the system prompt, tools, session history, memory files, and retrieval. The difference plays out on five levels: what is optimized, the time horizon, the main risk, the core skill, and the source in the project.

AspectPrompt engineeringContext engineering
What is optimizedThe wording of a single promptThe entire set of tokens: system prompt + tools + history + retrieved data
Time horizonOne turnMany turns plus transitions between sessions
Main riskThe model does not understand the promptThe model drowns in noise (context rot)
Core skillCopywriting plus understanding the modelInformation architecture and targeted retrieval
Source in the projectYour prompt templateCLAUDE.md, memory files, retrieval, subagents, compaction
Metaphor“How to write a prompt”“What the AI knows when you prompt it”

Context engineering is not “just pour in more.” It is precise dosing. Too little, and the AI lacks context and hallucinates. Too much, and the AI drowns in noise, loses its place in the middle, and costs more.

Prompt engineering handled the final step. Context engineering handles everything that came before it.

Why Doesn’t 1M Tokens Mean “Pour It All In”?

Key points

Model context windows grew in 2026: Claude Opus 4.7 and Sonnet 4.6 support 1 million tokens. This creates the illusion that you can pour the whole repository into the window. In practice, a large window does not mean a large useful memory—models begin to degrade well before the limit.

Current context limits for Claude models:

ModelContext windowAvailable on
Claude Haiku 4.5200,000 tokensall plans
Claude Sonnet 4.61,000,000 tokensPro+ with usage credits
Claude Opus 4.71,000,000 tokensPro, Max, Team, Enterprise

1M tokens is about 2,500 pages of text. It seems you could load all the project documentation, all the correspondence, and all the specifications—and let the AI figure it out. But Anthropic say plainly in their engineering blog:

You should treat context as a finite resource with diminishing returns.
— Anthropic Applied AI team, https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents

In other words, context is a finite resource with diminishing returns. Each additional token does not provide benefits linearly. The longer the window, the worse the model performs with the information in it.

The main skill in 2026 is not keeping everything open. It is switching quickly between narrow contexts, one per task.

The Biggest Mistake: Does More Context Mean a Worse Result?

Key points

The longer the context, the worse the model works with the information inside it. This phenomenon is called context rot. The lost-in-the-middle effect also comes into play: models remember the beginning and end of the context but skip the middle. The practical takeaway is that long memory files work against you.

The second effect, lost in the middle, operates in parallel.

In practice, an important rule buried in a long CLAUDE.md file can receive less attention. This is a risk to test in real tasks, not a guarantee that the model will skip a particular line.

Anthropic recommends a length limit in the CLAUDE.md documentation:

Aim to keep CLAUDE.md under 200 lines—longer files consume more context and reduce instruction adherence.
— Anthropic, https://code.claude.com/docs/en/memory

Under 200 lines is a length target in the quoted guidance, not a hard threshold at which rule-following stops. The 80-120-line range is the author's working preference from the projects described here, not a separate Anthropic requirement. Keep the instructions relevant and test whether important rules are followed; each added line competes for attention and context. For more on configuring CLAUDE.md to fit this limit, see the guide “How to Configure CLAUDE.md in 2026”.

5 Principles of Context Engineering According to Anthropic

Key points

In its September 29, 2025 engineering blog, Anthropic recorded 5 basic context strategies: finite resource, just-in-time retrieval, structured note-taking, compaction, and sub-agent architectures. This is the canon that all other authors on the topic now cite.

Principle 1. Context Is a Finite Resource

This is the basic premise, without which the other four principles do not work. Anthropic write:

The general advice for all components of context (system prompts, tools, examples, message history, etc.) is to be thoughtful about them and keep context informative but dense.
— Anthropic Applied AI team, https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents

“Tight” means “dense, without filler.” Every token in the window should materially change the model’s decision. If a line in CLAUDE.md reads “we try to write clean code,” you can delete it; it carries no signal.

Principle 2. Just-in-Time Retrieval

The AI agent pulls data through tools on the fly instead of preloading everything into the window. This is the architecture of Claude Code: instead of a vector database or index, the agent uses glob and grep, as a live engineer searches code manually.

When to use it: you do not know in advance which passages the task will require.

Principle 3. Structured Note-Taking

The agent writes notes to external storage and loads them as needed. In Claude Code, this is implemented through the memory tool. Anthropic describe it in their cookbook as follows:

Memory is structured notes: the agent writes to persistent external storage to track progress across tasks and sessions without keeping everything in active context.
— Anthropic Cookbook, https://platform.claude.com/cookbook/tool-use-context-engineering-context-engineering-tools

When to use it: long sessions, transitions between sessions, and accumulating project knowledge.

Principle 4. Compaction

Compressing message history into a summary as the limit approaches. In Claude Code, this is the /compact command, plus automatic compaction when the window reaches about 80%. Anthropic write:

Compaction compresses the entire window when it becomes too large.
— Anthropic Cookbook, https://platform.claude.com/cookbook/tool-use-context-engineering-context-engineering-tools

When to use it: long analytical conversations where the chat history has become dead weight and fills the window instead of helping.

Principle 5. Sub-Agent Architectures

Specialized subagents work in parallel in their own context windows and return compressed summaries to the lead agent. Anthropic write:

Subagents aid compression: they work in parallel with their own context windows while investigating different aspects of a question at the same time.
— Anthropic Engineering, https://www.anthropic.com/engineering/multi-agent-research-system

Figures from their own internal test: a lead Claude Opus 4 agent plus Claude Sonnet 4 subagents deliver +90.2% quality compared with a single Claude Opus 4 on research tasks. The cost: about 15× more tokens. The takeaway: this is justified where the outcome is valuable.

For more on configuring subagents in Claude Code, see the guide “Subagents for Claude Code”.

7 Mistakes That Burn Tokens and Break Claude Code

Key points

Seven common anti-patterns described using project examples. Each either burns tokens without benefit or causes hallucinations due to context rot. Below each one is how context engineering addresses it.

#Anti-patternWhat happensHow to fix it
1Pasted the entire README plus 5 code files into one promptThe window fills up by 50% in one turn, then quickly hits the limitMemory tool for long-term facts plus just-in-time retrieval—let Claude read files itself through read_file/glob
2CLAUDE.md with 500 linesLong instructions can reduce adherence, especially when important rules are buried in the middle80-120 lines, imperatives, sections for commands and style. Put the most important things at the beginning and end
3I don’t run /compact in long sessionsA session reaches 180k tokens, Claude forgets the first messages, and you repeat the context by handRun /compact manually or use auto-compaction by trigger. A sign of stress is the context usage indicator in desktop Claude
4One Claude for everythingOne agent plans, searches, codes, reviews, and tests—the window grows exponentiallySubagents: each has its own context, and the lead agent gathers summaries. Anthropic report +90.2% quality on research tasks
5Memory files grow from tool resultsThe agent rereads the same file 5 times, filling 96% of context with tool-call resultsTool-result clearing: keep 4-6 recent results and clear the rest. The fact that a call happened is preserved
6Pasted the entire repository into the examples/ folderThe AI searches for a pattern among 200 examples and gets lost3-7 canonical patterns in examples/, each for a specific type of task
7A 200-line Markdown list as a “feature plan”A long unstructured list can make task tracking harder; there is no universal failure point at line 50HTML artifact or numbered plan in a separate file

Anthropic’s Cookbook describes a specific measurement for mistake #5: in its baseline session, the first document in context (about C. elegans) was technically in the window, but buried under 335k tokens. Technically available. In practice, the model did not recall it. With the memory tool, the situation is fixed this way: the notes file aging_model_organisms_comparison.md weighs about 3000 tokens instead of reloading the original corpus.

A household analogy: the context window is a desk. If there are 200 documents on it, you will not find the one you need even if it is there. Context engineering is the discipline of “keeping only what you need on the desk now, putting the rest in the archive, and loading it on request.”

How Can You Put Together a Working Setup in One Evening?

Key points

A minimal working context engineering setup in Claude Code has 7 elements: CLAUDE.md, examples, PRP documents, memory tool, /compact, subagents, and just-in-time retrieval through tools. The basic framework takes 30-40 minutes to set up; full configuration with examples and verified prompts takes one evening. You can refine it as you go.

The seven steps in order:

  1. CLAUDE.md with 80-120 lines. At the project root. Use imperatives, not descriptions. In its official documentation, Anthropic recommends the Specificity principle: rules should be concrete and unambiguous, not general principles. In practice, “never use inline mocks in tests” works better than “we try to write clean code.” For a detailed template, see the guide “How to Configure CLAUDE.md”.

  2. An examples/ folder with 3-7 verified patterns. One example for each common pattern: an API call, writing a test, a migration, error handling. When Claude sees a pattern in examples/, it reproduces it exactly. Without examples, it guesses as it goes.

  3. PRP documents for major features. PRP = Product Requirements Prompt. One file per feature: context plus plan plus validation plus examples.

  4. A memory tool for long-term facts across sessions. In Anthropic’s Cookbook, Claude’s memory tool is implemented as a structured note store. When the agent returns to a task in a new session, it reads the notes first instead of rereading the entire corpus.

  5. /compact plus auto-compaction at 80% of the limit. Do not wait for the window to reach its ceiling. Turn on auto-compaction in settings or run /compact yourself when it feels like the session is going in circles.

  6. Subagents for research / review / planning. Each subagent has its own context and narrow prompt. Lead-Claude receives only the summary, not the raw material. See “Subagents for Claude Code” and “Skills for Claude Code” for more details (Skills are a way to package narrow expertise into a skill that Claude applies automatically).

  7. Just-in-time retrieval instead of preloading. Do not pour the entire repository into the window. Let Claude search through glob and grep itself. This is the architecture of Claude Code itself.

Additional practical rules from the project experience described:

  • One task, one window. When you finish, close it and open a new one. Do not accumulate history across several consecutive tasks.
  • Template for the first command in a new window. Use the same text each time: “Read, in order, CLAUDE.md and the task area. Confirm in one line. Do not start the task; wait for the next message.” In the described workflow, this template is stored in a snippet editor under a single hotkey.
  • When the context window is >60% full, switch to a new one. An interim technique: ask Claude, “write a prompt so the neighboring chat can continue your task without losing the meaning,” copy it, and open a new window.
  • Every AI mistake is a reason to add a rule. Do not write rules in memory files by hand. Tell Claude “that’s wrong because...” at the moment of the mistake, and it will format the rule into a file according to the “Rule → Why → How” convention.

What’s Next: How Will the Context Engineering Discipline Develop?

Key points

In 2026, context engineering is moving from text-based Markdown files to more structured formats. The Dreaming feature has appeared, in which an agent reexamines past sessions overnight. Next come HTML artifacts, persistent memory, and multi-agent orchestration across the entire product team.

One direction in which the discipline is moving right now:

Dreaming—overnight reconsideration of sessions. At Code w/ Claude SF on May 6, 2026, Anthropic showed a feature in which an agent reexamines past sessions overnight and updates its own notes. Structured memory files now grow not only when you write them, but also when the agent draws conclusions from accumulated experience.

One trend is clear: context engineering is becoming a full discipline for architecting information for AI agents, rather than just “how to write CLAUDE.md.” Prompt engineering was one of the first levels of this discipline. Context engineering is the next.

The minimum worth putting together on the first evening: configure CLAUDE.md to 80-120 lines (guide here), create a folder with a structure for business knowledge, learn to use /compact, and stop burning through limits.

Next, add subagents (guide) and Skills to move specialized expertise out of the shared context and into dedicated skills.

Sources

Get to know Ailoot.

More details

Questions about Context Engineering vs Prompt Engineering: Claude Code Guide

Is 200 lines a hard limit for CLAUDE.md?

No. The quoted guidance recommends staying under 200 lines to conserve context and improve adherence. The author's 80-120-line range is a practical preference; verify the important rules on real tasks rather than treating a line count as a guarantee.

What should move out of the initial context?

Move detailed examples, long tool results, and task-specific reference material into separate files. Keep concise rules and pointers in CLAUDE.md, then retrieve the relevant passages when the task needs them.

All articles