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.
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.
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:
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.
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.
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 role | With 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 state | With 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 task | Precise 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.
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 format | With 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:
| Habit | What goes wrong | Fix |
|---|---|---|
| The naked paste | A 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 shorthand | Team 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 decision | A 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:
| Task | Parts that matter most | Common miss |
|---|---|---|
| Debugging | State (the error, what you tried) + Task (expected behavior) | Code pasted without the error message or steps to reproduce |
| Writing code | Role + Task (exact spec) + Constraints (stack, patterns) | No stack named, so the model picks one for you |
| Code review | State (what the code is for) + Constraints (scope) + Format | No intent given, so the model argues with deliberate choices |
| Docs and writing | Role (who reads it) + Task (topic and scope) + Format (length, tone) | No audience, so it comes out too basic or too dense |
| Architecture calls | State (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 |
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.
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, sendvalidateUserand the types it uses, not all ofauth.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.