Lesson 1: From Prompt Engineering to Context Engineering
Learning goals:
- Restate the definitions of prompt engineering and context engineering, and say why the two are an "evolution" rather than a "replacement"
- Use the two ideas of "attention budget" and "context rot" to explain to a colleague what's wrong with "the window's big enough, so stuff everything in"
- Point to the places in the harness loop you built in this series' course "Agent Harness Fundamentals: Loops and Control" where context only grows and never shrinks
Prerequisites: You've finished this series' course "Agent Harness Fundamentals: Loops and Control" and have a working stop_reason-driven loop on hand | Next: Lesson 2 >>
A Familiar Scene: Every Turn of the Loop, the Window Gets Heavier
In this series' course "Agent Harness Fundamentals: Loops and Control," you hand-wrote a loop like this (simplified; the four control valves — max turns, budget, and the rest — are left out for now):
Back then all our attention was on control flow: how to read stop_reason, how to install the control valves. Now change the angle and stare at the messages array — it only ever gets pushed to, never trimmed. Every turn, at least two things come in: the model's reply for this turn (with its tool_use blocks), and the results the tools return. That second kind is often the bulk of it: picture a single list_files bringing back a few hundred filenames, or a log search bringing back tens of KB of raw text. From that point on they sit in the window forever, re-read from scratch on every round of reasoning.
This isn't a slip in your implementation; it's the nature of an agent. "An agent running in a loop generates more and more data that could be relevant for the next turn of inference"1, and because it holds the autonomy, it may keep going for a great many turns2. In this series' course "Prompt Engineering Basics: How to Write Effective Instructions" you learned how to write a single instruction clearly — but however well an instruction is written, it's still just one small block inside the window. What actually decides how the agent performs on turn 40 is everything that happens to be sitting in the whole window at that moment.
Two Definitions: From "Write One Good Sentence" to "Manage the Whole Window"
Formalize that observation and you get two definitions.
Prompt engineering: "Prompt engineering refers to methods for writing and organizing LLM instructions for optimal outcomes"1. The question it answers is: "How should I write and arrange this instruction for the best effect?"
Context engineering: "the set of strategies for curating and maintaining the optimal set of tokens (information) during LLM inference"1. The question it answers is: "For this round of reasoning, which tokens should be in the window, and which shouldn't?"
Notice the lift in perspective. The first is a one-time writing problem — write it once and it's set. The second is a tradeoff you have to re-answer on every turn of the loop. Anthropic explicitly frames context engineering as the natural progression of prompt engineering — "we view context engineering as the natural progression of prompt engineering"1 — so the skill you built up in this series' course "Prompt Engineering Basics: How to Write Effective Instructions" isn't wasted at all. It becomes a subset of a bigger problem: the system prompt still has to be written well, but it's only one of the many context ingredients you now have to manage.
The community has more aggressive takes. A 2026 agent-engineering roadmap asserts "Prompt engineering is dead as a standalone skill in 2026."3 Note that this is that roadmap's opinionated call, and this lesson doesn't treat it as consensus — Anthropic's phrasing is far more measured: evolution, not replacement1. That said, the one-line definition the same roadmap gives context engineering is worth keeping: "deciding what tokens are in front of the model at every step of the loop"3. And the same roadmap puts its finger on how much the harness matters: "Same model, different harness, completely different result."3 — something you should already feel in your gut from the experiments in this series' course "Agent Harness Fundamentals: Loops and Control."
Attention Budget: Every New Token Runs Up the Tab
Why is this something you have to manage? Isn't a bigger window just free rein? That brings us to the first physical fact.
"LLMs have an "attention budget" that they draw on when parsing large volumes of context"1. The catch is that this budget is finite: "Every new token introduced depletes this budget by some amount"1.
Here's an analogy. Window capacity is the floor area of a warehouse; the attention budget is the crew you send in to find the goods. Expand the warehouse tenfold and the crew doesn't grow with it — the fuller the shelves, the harder it is to dig out the one item you actually want. Slipping one more "just in case" document into the window isn't a free backup; it's a real charge against the budget, paid out to cover the cost of reading it and ruling it out.
Flip to this view and a lot of habits deserve a second look. "The window can hold it, so let's just paste in the entire API doc" — holding it is a warehouse question, reading it well is a budget question, and the two aren't the same thing.
Context Rot: A Gentle Slope, Not a Cliff
The macro consequence of a budget being drained continuously has a vivid name: context rot — "as the number of tokens in the context window increases, the model's ability to accurately recall information from that context decreases"1.
Two details that are easy to get wrong, pinned down here:
First, it's gradual, not a sudden drop. This degradation shows up as a performance slope — "These factors create a performance gradient rather than a hard cliff"1 — not a hard cliff where things suddenly stop working past some token count. So you'll never get an error; the agent just gets slowly duller. In everyday terms (this is the typical shape it takes in engineering experience, not an enumeration from the source): conventions confirmed earlier start getting forgotten, files already read get read again, bugs already fixed get reverted. Degradation with no alarm is harder to track down than an error.
Second, it's a general rule, not one model's quirk. Some models degrade more gently than others, but "some models exhibit more gentle degradation than others, this characteristic emerges across all models"1. Switching to a stronger model can postpone the problem; it can't cancel it.
Put those two together and you have this lesson's first cornerstone: "context, therefore, must be treated as a finite resource with diminishing marginal returns"1. The thousandth token you stuff into the window and the hundred-thousandth take up the same amount of room, but they're worlds apart in the value they add. The "more is safer" instinct has the direction exactly backwards — every extra bit of "insurance" you cram in dilutes the model's attention on the information that actually matters.
Back to Agents: Why This Is the Foundation, Not Icing
In a single-turn Q&A, you might not even notice context rot — the window gets used once and discarded, and the token count usually doesn't reach the danger zone. Agents turn this problem from "occasionally encountered" to "getting worse every turn": data in the loop only grows and never shrinks1, and agents may autonomously run for many turns2. Look back at the opening code — that messages array that only takes push and never gives anything back is this process made concrete.
On-the-ground engineering experience lines up completely. The official Claude Code docs state that "Claude's context window fills up fast, and performance degrades as it fills."4 They call the context window "the most important resource to manage."4 The same docs also have an observation worth copying down: "A clean session with a better prompt almost always outperforms a long session with accumulated corrections."4 — "talked longer" doesn't mean "talked better," and every correction piled up, every tangent wandered down, is still sitting in the window taking part in the next round of reasoning.
So here's an accurate position for context engineering: it's not polish you add in the tuning phase; it's the foundation of agent reliability. The four control valves in this series' course "Agent Harness Fundamentals: Loops and Control" manage "don't let the loop run away"; this course installs another set of mechanisms — "don't let the window rot." Put both sets together and your harness is actually ready to be trusted with long tasks.
This Course's Roadmap
For long-horizon tasks, Anthropic summarizes three classes of techniques — "compaction, structured note-taking, and multi-agent architectures," aimed at helping agents "maintain coherence, context, and goal-directed behavior over sequences of actions"1. This course follows that path:
- Lesson 2 dissects the window: system prompt, tool definitions, examples — how much room does each take, and how do you write them without waste.
- Lesson 3 covers just-in-time retrieval: instead of stuffing all the material in ahead of time, give the agent lightweight identifiers and let it go look things up on demand.
- Lesson 4 covers compaction and notes: when the window approaches the limit, how to summarize and restart, and how to record key information outside the window.
- Lesson 5 covers sub-agents and context isolation: send the messy exploratory work to a sub-agent with a clean window, and only pull back the distilled conclusion.
- Lesson 6 returns to your own harness and installs these mechanisms one by one.
One last reminder about proportion. Every one of these mechanisms adds complexity, and Anthropic's engineering guidance says "you should consider adding complexity only when it demonstrably improves outcomes."2 So every lesson ahead explains "when is it worth doing" before it explains "how to do it" — not every agent needs sub-agents, and not every task is worth compacting.
Recap
- Context engineering is the natural progression of prompt engineering: the first manages "which optimal token set to maintain in the window at reasoning time," the second manages "how to write and organize instructions," and the perspective lifts from one sentence to the whole window1.
- "Prompt engineering is dead as a standalone skill" is an opinionated assertion from a community roadmap3; this lesson uses the more measured phrasing — evolution, not replacement1.
- LLMs parse context using a finite attention budget, and every new token consumes some of it1 — "the window can hold it" and "the model can use it well" are two different things.
- Context rot is a gradual performance slope rather than a cliff, steeper on some models and gentler on others but the trend appears across all models1, so it doesn't error out; it just quietly makes the agent duller.
- Context is a finite resource with diminishing marginal returns1; data in the agent loop only grows and never shrinks1, which is why the official Claude Code docs call the context window "the most important resource to manage."4
- The three classes of techniques for long-horizon tasks — compaction, structured note-taking, and multi-agent architectures1 — correspond to the main threads of Lessons 4 and 5; Lesson 6 installs them into your harness. Before introducing any complexity, confirm it actually improves outcomes2.
>> Lesson 2: Anatomy of Context: System Prompt, Tools, and Examples