Nguyen Le Phong

Context Engineering Is Briefing a Smart New Hire

Most weak AI answers come from thin context, not bad wording.

You paste a 40-line test into an AI chat and ask why it's flaky. The answer is a tidy list of usual suspects: async timing, a leaky mock, a missing await. All reasonable, none of them your bug. So you add four facts: it only fails in CI, the suite runs in parallel, every worker shares one Postgres container, and the failures started after last week's migration. The next answer goes straight to shared database state and suggests a per-worker schema. Same model, roughly the same question. What changed is what the model could see.

That gap is what people now call context engineering. This post covers what goes into a model's context window, a five-part checklist for filling it, the habits that waste it, and a template you can reuse on Monday.

Definition

Shopify's CEO Tobi Lütke put it in one line: context engineering is "the art of providing all the context for the task to be plausibly solvable by the LLM" (quoted by Simon Willison). Your wording still matters. The bigger question is whether the model has the facts it needs.

Phong and teammates present their drone thesis project next to the prototype workbench, with the people, hardware and room all in view.
Anyone walking into this room gets the full picture at a glance: who built it, what it is, where it has to fly. A prompt has to spell all of that out in text.

Where the term came from, and why it stuck

"Context engineering" took off in June 2025, when Tobi Lütke and then Andrej Karpathy said they preferred it to "prompt engineering." Karpathy called it "the delicate art and science of filling the context window with just the right information." Simon Willison, who had defended the older term for years, explained the switch: most people hear "prompt engineering" and picture typing clever phrases into a chatbot, and that misses most of the work.

Anthropic's engineering team wrote the most practical version a few months later. They describe context engineering as "the set of strategies for curating and maintaining the optimal set of tokens (information) during LLM inference," and they point out that in agent setups most of those tokens don't come from you at all. They come from tool results, files, earlier turns and instructions loaded at startup (Effective context engineering for AI agents, September 2025).

A kitchen comparison helps. Cooks call it mise en place: every ingredient prepped and on the counter before the pan gets hot. A good cook doesn't stop halfway through a dish to go find the garlic. With AI, you're the one doing the prep, and the model cooks with whatever is on the counter.

Anthropic's own prompting guide has a test that works for any model: show your prompt to a colleague who knows nothing about the task and ask them to follow it. If they'd be confused, the model will be too (Prompting best practices, checked November 2026). The question shifts from "how do I phrase this?" to "what would a smart new hire need to know?"

What's actually in the window

The context window is everything the model can read when it writes a reply. Per Anthropic's docs, that's the system prompt, every message (tool results, images and documents included), your tool definitions, and the reply the model is generating (Context windows). It helps to picture it as four layers:

Four layers inside a context window: system prompt, injected material, conversation history and the user message all feed the model, which writes the response. CONTEXT WINDOW: everything the model reads before it writes a word ROLE System prompt Role, standing rules and house style that apply to every turn in the session DOCS Injected material Files, logs, search results, tool output and tool definitions the model works from MEM Conversation history Earlier turns and decisions, kept until the session is trimmed or summarized TASK User message The question you just typed: often the shortest layer, and the one people polish most LLM reads it all, then writes Response only as good as its inputs All four layers share one token budget. Your job is choosing what earns a spot.
Four layers, one budget. Most people only tune the bottom layer, the message they type. The top two usually decide whether the answer fits your situation.

The system prompt holds the rules that apply every turn: who the model is working for, the house style, what it must never do. In a chat app you might set this through custom instructions or a project file. In a coding agent it's often a file like CLAUDE.md or AGENTS.md that gets loaded at the start.

The injected material is what the model reasons over: the code, the stack trace, the schema, the doc page. It's the difference between telling a friend "fix this" and handing them the code, the error and the relevant docs. When an answer is generic, this layer is usually where something is missing.

A drone prototype on a crowded workbench next to a laptop and a monitor, with parts and tools within reach.
Debugging is easier with the parts on the bench. Same for a model: paste the log and the schema, don't describe them from memory.

The conversation history grows every turn. That's handy, since the model can see what you agreed on ten messages ago. It also costs room, and old dead ends stay in view long after you've moved on.

The user message is the question itself. It gets most of our attention, yet in a well-set-up session it's often the shortest part of the window.

How big is the window? As of November 2026, Anthropic's docs list up to 1M tokens depending on the model, and the same page warns that "more context isn't automatically better": as token count grows, accuracy and recall degrade, which they call context rot (Context windows). Big windows give you room. They don't decide what belongs in the room.

Why answers miss: five gaps

When context is thin, the model fills the holes with the most typical answer for a question shaped like yours. Typical is rarely what you need. Most misses trace back to one of five gaps:

No role. The model doesn't know who it's writing for. A security review for a senior engineer and an intro for a new grad are different documents, even on the same topic.

No state. It doesn't know what exists, what you've tried or what already failed. So it suggests the three things you ruled out an hour ago.

A fuzzy task. "Help me with this" has a hundred readings. The model hedges and covers all of them a little.

No constraints. It doesn't know you're on Python 3.11, can't add dependencies or must keep the public API stable. You get a nice answer for somebody else's codebase.

No format. You wanted a table and three bullets. You got an essay.

A five-part checklist

Each gap has a matching fix. Call them pillars or just a checklist; the point is to run through them before you hit send.

Five parts of a well-filled context: role, state, task, constraints, format. 1 Role Who is the model, and who is it writing for? 2 State What exists, what's decided, what you tried 3 Task One sentence: verb, object, scope WRITE THIS FIRST 4 Constraints Limits, plus the reason behind each 5 Format Shape, length, level of detail
Write the task first, then fill in the other four around it. A quick lookup may only need role, task and format. Debugging usually needs all five.

1. Role

Say who the model is and who it's talking to. That shifts vocabulary, depth and which trade-offs it brings up. Anthropic's guide notes that even a single sentence of role in the system prompt makes a difference (Prompting best practices). The audience half is the part people forget.

Without roleWith role
Explain authentication. You're a senior backend engineer who focuses on security. You're writing for a junior developer who knows JavaScript but has never built auth. Explain JWT, with the trade-offs and what usually goes wrong.

2. State

Tell the model what already exists: the stack, the relevant code, what you tried, what happened, which decisions are settled. This is the pillar people skip most, and it's the one from the flaky-test story at the top.

Without stateWith state
Fix this bug.
(pasted code, nothing else)
[code] This debounce works for typing but fires immediately on fast scroll instead of waiting. I already call clearTimeout at the start; no change. Stack: React 18, TypeScript. Console: [message].

3. Task

Name the job, not the topic. "Help with my API" is a topic. "Write an Express middleware that validates JWTs, returns 401 when the token is missing or invalid, and puts the decoded user on req.user" is a job. Once you can write it as one sentence with a verb, an object and a scope, the rest of the checklist gets easier.

Vague taskPrecise task
Write some tests for this function. Write Jest unit tests for validateEmail (a pure function). Cover: valid formats, missing @, missing TLD, spaces, empty string, null, undefined. One named test per case, no test.each, so failures are easy to read.

4. Constraints

Constraints cut out a whole class of answers that are technically right and useless for you. Typical ones: the stack and versions, libraries you can't add, a length limit, whether you want code only or an explanation too, and whether the model should ask questions or make assumptions.

Say what you want, and why

Two tips from Anthropic's guide. First, tell the model what to do instead of only what to avoid: "write in flowing paragraphs" works better than "no markdown." Second, give the reason. Their example: "NEVER use ellipses" is weaker than explaining the reply will be read by a text-to-speech engine that can't pronounce them, because the model can generalize from the reason (Prompting best practices). Hard limits like "don't touch the public API" still deserve a plain sentence. Just add the why.

5. Format

Describe the shape of the answer: length, structure, level of detail, who reads it. Without that, the model guesses, and you get 500 words when you wanted a paragraph.

Without formatWith format
What's the best database for my app? Compare PostgreSQL and MongoDB for a SaaS app with structured user records plus flexible per-user metadata, about 10k users now, maybe 1M later. Give a table (read/write patterns, schema flexibility, ops effort), then a pick with 3 reasons. Under 300 words.

Habits that waste the window

These feel natural in the moment and keep producing weak answers:

HabitWhat goes wrongFix
The naked pasteA wall of code and "what's wrong?"Add three lines on top: what the code should do, what it does instead, what you tried.
The bundle"Review this, write tests and rename things," all in one message.One job per message. Each answer is easier to check, and one weak part doesn't drag down the rest.
The insider shorthandTeam acronyms and service names the model has never seen.Write like it's a smart contractor on day one. Spell out what "the sync worker" or "BFF" means in your setup.
The lost decisionA new question that depends on something agreed twenty messages ago.Restate it: "We picked Redis for the cache. Given that..."
The contradiction"Be brief but cover every edge case."Pick the priority: "Keep it short. Name the edge cases, don't explain them."

A template you can reuse

Once the checklist feels natural, save it as a template for the tasks you repeat. Here's a general one for engineering work:

## Role
You are [ROLE], focused on [DOMAIN].
You're writing for [AUDIENCE], who [WHAT THEY KNOW OR NEED].

## Background state
Stack: [LANGUAGES / FRAMEWORKS / VERSIONS]
What exists: [SHORT DESCRIPTION]
What I tried: [ATTEMPTS AND RESULTS]
Error or log: [IF ANY]

## Task
[ONE SENTENCE: verb + object + scope]

## Constraints
- Stay within [LIBRARY / APPROACH], because [REASON]
- Keep [ASPECT] under [LIMIT]
- If something is unclear, [ASK FIRST / ASSUME X AND SAY SO]

## Output format
[LENGTH] | [STRUCTURE] | [LEVEL OF DETAIL]

You won't fill every field every time. For a quick lookup, role, task and format are plenty. When you paste long material (a big log, several files, a spec), put it above the instructions and the question. Anthropic reports that putting the query at the end can improve response quality by up to 30 percent in their tests, especially with complex, multi-document inputs (Prompting best practices).

Here it is filled in for a code review:

## Role
You are a senior TypeScript engineer who cares about maintainability.
You're reviewing for a mid-level developer who wants to learn, not just get a list of fixes.

## Background state
Stack: TypeScript 5.4, React 18, function components only.
This file holds custom hooks for auth state. It has no tests yet.

## Task
Review it for correctness, type safety and maintainability.

## Constraints
- Keep state in React; we chose not to add a state library, so skip that suggestion
- Show a concrete fix for each issue, not just a description
- At most 5 issues, most important first

## Output format
List: issue | why it matters | fix (2 to 5 lines of code)

"Review my code" turns into a bounded review with a clear reader, a known off-limits area and a fixed shape. You can also check the answer against the template: five issues, each with a fix, none of them about state libraries.

Which parts matter for which job

Different tasks lean on different parts of the checklist. A rough guide:

TaskParts that matter mostCommon miss
DebuggingState (the error, what you tried) + Task (expected behavior)Code pasted without the error message or steps to reproduce
Writing codeRole + Task (exact spec) + Constraints (stack, patterns)No stack named, so the model picks one for you
Code reviewState (what the code is for) + Constraints (scope) + FormatNo intent given, so the model argues with deliberate choices
Docs and writingRole (who reads it) + Task (topic and scope) + Format (length, tone)No audience, so it comes out too basic or too dense
Architecture callsState (system, scale, limits) + Task (the decision) + Format (options, then a pick)"What's the best approach?" with none of the limits that make it hard
Phong stands on a rocky summit above the coast with a small pack, carrying only the gear he picked for the climb.
A context window works like a daypack. You could stuff it, but the climb goes better with the few things you'll actually use.

More context isn't always better

With windows this big, it's tempting to paste the whole repo and let the model sort it out. The research says that's a bad trade:

  • In "Lost in the Middle," Liu and colleagues found that performance is often highest when the relevant information sits at the start or end of the input, and drops when the model has to find it in the middle of a long context (Liu et al., 2023).
  • Shi and colleagues added irrelevant sentences to grade-school math problems and saw accuracy drop sharply. Telling the model to ignore irrelevant information helped (Shi et al., ICML 2023).
  • Chroma tested 18 models in July 2025 and found performance degraded as input length grew, even on simple tasks, and even a single distractor lowered it (Context Rot).

Anthropic's team sums up the goal well: find "the smallest possible set of high-signal tokens" that makes the outcome you want likely (Effective context engineering). Ten relevant files beat fifty files where ten are relevant.

The "just in case" test

Before you paste something, ask whether it helps answer this question or whether you're adding it just in case. If it's just in case, leave it out. You can always add it in the next turn.

A few habits that keep the window clean:

  • Paste the function, not the file. If the question is about validateUser, send validateUser and the types it uses, not all of auth.ts.
  • Restart long sessions with a summary. When a chat has wandered, open a fresh one with a short "here's where we are" note. As of November 2026, many agent tools do a version of this for you (Anthropic calls it compaction), but your own summary keeps the decisions you care about. The context window bottleneck post goes deeper on long sessions.
  • Put standing rules in the system prompt or project file once, instead of repeating them in every message.
  • Strip noise from pastes: license headers, long import blocks and generated code rarely help.

Try this week

  • Take one prompt you send often and rewrite it with the five parts: role, state, task, constraints, format.
  • Add a "because" to every constraint in it.
  • Next time you debug with AI, paste the exact error and what you already tried before you ask anything.
  • When a chat gets long and the answers drift, start a new one with a five-line summary and compare.
  • Save your best prompt as a template file your team can copy.

Before you send the next prompt, run the new-hire test: would a smart colleague who just joined have enough to do this well? Add what they'd ask for, cut what they'd skip. Some things never fit in a prompt at all, like runtime behavior or team history, and What AI Cannot Know From the Prompt Alone picks up from there.

What did you think?

Frequently asked questions

What is context engineering?
It's the work of choosing what goes into a model's context window before it answers: the role, the current state, the task, the constraints and the output format, plus any files, logs or tool results. Tobi Lütke described it as providing all the context for the task to be plausibly solvable by the LLM. The term caught on in June 2025.
How is it different from prompt engineering?
Prompt engineering is mostly about how you phrase a request. Context engineering is about what information the model can see when it answers, including the system prompt, pasted material, tool output and earlier turns. A well-worded question still gets a generic answer if the model doesn't know your stack, what you tried or what's off-limits.
What should a good prompt include?
Run through five parts: role (who the model is and who it's writing for), state (what exists and what you already tried), task (one sentence with a verb, object and scope), constraints (limits, each with its reason) and format (length, structure, detail). A quick lookup may only need role, task and format. Debugging usually needs all five.
Is a bigger context window always better?
No. Anthropic's docs list windows of up to 1M tokens as of November 2026, and the same page warns that accuracy and recall degrade as token count grows. Research such as Lost in the Middle (Liu et al., 2023) and Chroma's Context Rot report (July 2025) found performance drops with long inputs and distracting content. Send the smallest set of material that answers the question.
Should I write constraints as "do not" rules?
For hard limits, a plain sentence is fine, but add the reason. For style, Anthropic's prompting guide recommends saying what you want instead of what to avoid, for example "write in flowing paragraphs" instead of "no markdown". Explaining why a rule exists helps the model apply it to cases you didn't list.