Free mini-course · Layer 2 of 5

Context Engineering: curate what the model sees

The second layer. The model can only act on what is in its window — and attention is a budget, not a bucket. Context engineering is curating the smallest set of high-signal tokens that lets the model do the job. Eleven lessons — from the attention budget to the startup ledger, the four failure modes, the delete-first discipline, and the four-stage context pipeline.

promptscontextharnessloopsgraphs
LESSON 01

Attention is a budget

Bigger windows didn't solve memory: accuracy degrades as context grows — practitioners call it context rot. Every token you add competes with every other token for the model's attention. The discipline starts by treating context as a scarce resource: what does this task actually need to see, and what is just noise riding along?

Do this now: Take a prompt where you paste a whole document. Cut it to only the sections the question touches. Compare answers — and note the quality usually goes up, not down.
LESSON 02

Minimal viable context

Anthropic's rule: find the smallest high-signal token set that maximizes the outcome. System prompts live in a Goldilocks zone — specific enough to guide, flexible enough to generalize. Tools should be unambiguous and non-overlapping. If two instructions or two tools could both apply, the model will sometimes pick wrong; make one of them clearly the answer.

Do this now: Audit your longest system prompt. Delete every sentence that never changed an output. What's left is your real prompt.
LESSON 03

Just-in-time beats pre-loading

Instead of stuffing everything into the window up front, give the model lightweight references — file paths, IDs, links — and tools to fetch details when needed. This mirrors how people work: you don't memorize the codebase, you know where to look. Retrieval at runtime keeps the window clean and the information current.

Do this now: Rebuild one stuffed prompt as: a two-line summary + a list of fetchable references. Let the model ask for what it needs.
LESSON 04

Compaction and notes: surviving long work

Long tasks outgrow any window. Two moves keep them alive: compaction (summarize the conversation so far, keep decisions, drop dead ends) and structured note-taking (an external NOTES.md the agent updates and re-reads — memory that survives the window). What you preserve matters more than how much you cut: keep decisions and constraints, discard transcripts.

Do this now: Mid-way through a long chat, ask the model: “Write a 10-line handoff note so a fresh session could continue this work.” Start a fresh session from just that note and see what survived.
LESSON 05

Isolation: sub-agents as context firewalls

The heaviest context tool is a second context. A sub-agent explores a big problem in its own window and returns a 1–2k-token summary — the main thread gets the conclusion, not the noise. This is where context engineering hands off to graph engineering: each node in a graph is, among other things, a context boundary.

Do this now: Next research-heavy task: instead of one long chat, run the exploration in a separate conversation and paste only its summary back. Notice the main thread stays sharp.
LESSON 06

The startup ledger: your prompt is 0.5% of the window

Before you type a single character, the window is already loaded: system prompt, memory files, tool names, skill descriptions, project instructions. In Anthropic’s own session simulation that fixed overhead runs roughly 7,850 tokens — against your 45-token request. And unlike your prompt, the overhead reloads on every request for the life of the project. A bad prompt costs you one answer; a bad line of always-loaded context taxes a fraction of every answer the model will ever give you here.

Do this now: Open your tool’s context inspector (in Claude Code: /context) at session start and write down your fixed overhead before your first word. Then run it again after an hour of work. That number — not your prompt — is what this layer optimizes.
LESSON 07

Name the failure: poisoning, distraction, confusion, clash

“Too much context” is not a diagnosis. Drew Breunig catalogued four distinct failure modes: poisoning (a hallucination enters context and everything downstream builds on it), distraction (accumulated context overwhelms what the model knows from training), confusion (irrelevant tools and files influence the answer), and clash (parts of the context disagree with each other). Clash is the one you author yourself — one file says document thoroughly, another says never add comments — and you pay the reconciliation tax on every request, invisibly, because the output still looks fine.

Do this now: Have the model read every always-loaded file together and list pairs of instructions that cannot both be followed. Fix or delete every pair it finds.
LESSON 08

Delete first, measure second

Anthropic removed over 80% of Claude Code’s system prompt for the newest model generation — and measured no loss on their coding evals. Not a rewrite; a deletion, of guidance that felt load-bearing right up until it was gone. Invert your default: treat every line as guilty until proven useful. Cut whole blocks, not sentences (single lines sit below the noise floor of any eval), run a small harness — even ten prompts you care about with a rubric — and restore only if something breaks. When a rule does survive, convert it: “never Y” becomes “prefer Z; Y is a known gotcha here” — a principle that tells the model what to look at, not what to output. Keep hard rules only for destructive operations, security boundaries, and compliance.

Do this now: Cut your longest always-loaded section entirely and run your ten-prompt eval. You will be surprised how rarely you restore.
LESSON 09

Design the interface; keep the core under 200 lines

Examples now constrain more than they teach: demonstrate three ways to use a tool and you quietly cap the model at those three. Put the effort into the interface instead — a status enum of pending / in_progress / completed teaches an entire lifecycle without a single example, and when tool schemas load on demand the description becomes the discovery surface, so write it to say when the tool applies. Retrieval over tool descriptions has been shown to improve selection accuracy roughly threefold. Documents follow the same shape: an always-loaded core under 200 lines holding only the gotchas the model cannot infer by reading the repo, with everything else behind triggers — a tree, not a scroll. And put critical rules at the top of every file: truncation after compaction keeps the start.

Do this now: Move every paragraph of reference material out of your core context file into a triggered skill or path-scoped rule, leaving a one-line pointer behind. Target: under 200 lines, gotchas only.
LESSON 10

Ingest with provenance, rank with three signals

A context window is a budget, not a warehouse — and the pipeline that protects it has stages. Ingest is where most pipelines quietly fail: heterogeneous sources (threads, PDFs, rows, API responses, code) each need their own extraction, noise (nav chrome, page footers, filler) must die before it costs tokens, and every chunk keeps a provenance tag — because the first time the model cites something wrong, you need to trace where the “fact” came from. Rank refuses to trust cosine similarity alone: it blends semantic score with recency decay and source authority (a starting blend: 0.55 / 0.25 / 0.20), because a verified API schema and a two-year-old forum post can score near-identically on semantics — only authority tells the ranker which to trust. Ranking’s job is not to find everything relevant; it is to order everything by what it’s worth in tokens.

Do this now: Take one messy real source and write its ingest step: strip boilerplate, split by idea, tag every chunk with a source id. Then rank twenty chunks against one query with all three signals and compare the top five against cosine-only — note which stale-but-similar chunk fell out.
LESSON 11

Route, then compress — every request earns its context

Route decides two things at once: how much context this request deserves and which model tier receives it — a high-confidence match on a simple query takes three chunks and the cheap model; no strong match at all means this is a tool call, not a retrieval problem; only genuinely complex queries earn the deep path. Skipping this stage — “always send the top 20 chunks to the strongest model” — is safe, expensive, and often worse, because irrelevant context dilutes attention even in a frontier model. Compress is not truncation: truncation cuts at an arbitrary boundary with no regard for what it removes; compression removes redundancy and protects the facts. Three strategies cover most cases — extractive (keep the signal-carrying sentences) for dense factual material, abstractive (a cheap model rewrites more densely) for narrative, structural (prose → table or key-value) for information that was never prose in spirit. Prompt engineering asks how to phrase the request; context engineering asks what the model needs to know at all, in the smallest footprint that survives. Better plumbing beats better instructions.

Do this now: Add a four-way route decision (minimal / standard / deep / tool-only) in front of your retrieval and log which tier each of your last twenty questions actually earned. Then convert one prose-formatted report into structural form and record the tokens saved.
Go deeper — the sources this course is built on:
Anthropic’s Effective context engineering for AI agents (compaction, note-taking, sub-agents, just-in-time retrieval) · 12-Factor Agents, factor 3: “Own your context window” · LangChain blog on context engineering · @0xCodez’s “Context Engineering with Claude: 14-step roadmap” (the startup ledger, the four failure modes, delete-first discipline, interface-over-example tool design) — lessons 06–09 synthesize its findings alongside Drew Breunig’s failure-mode taxonomy and Lance Martin’s four moves · @0xWast3’s “Context Engineering: the discipline nobody named” (the ingest–rank–route–compress pipeline, three-signal ranking, compression-not-truncation) — lessons 10–11