Context engineering: giving AI the right information, not just the right words

TL;DR: Context engineering is the practice of choosing what information an AI model sees and in what form: instructions, documents, examples, memory and tool results. Prompt engineering is about wording the request. Context engineering is about what surrounds it. More is not better: models get less reliable as input grows, so include only what changes the answer.

What context engineering is

Everything a model reads before it answers is its context: your instructions, the files you attach, the chat so far, any examples, any search results. Context engineering is the work of deciding what goes into that space and how it is laid out.

Anthropic, in its September 2025 engineering post on the subject, describes context engineering as "the set of strategies for curating and maintaining the optimal set of tokens (information)" a model works with. Its guiding principle is the most useful sentence on the topic: find "the smallest possible set of high-signal tokens that maximize the likelihood of some desired outcome."

In plain terms: give the model everything it needs to do the job well, and nothing that distracts it.

Context engineering vs prompt engineering

Anthropic calls context engineering "the natural progression of prompt engineering". Prompt engineering is about writing and organizing the instructions. Context engineering covers the instructions plus everything else in the window. The post adds that it is iterative: "the curation phase happens each time we decide what to pass to the model."

Prompt engineering and context engineering compared
Prompt engineeringContext engineering
The question it asksHow should I word this request?What should the model know when it reads this request?
What it shapesThe instructionInstructions, documents, examples, memory, tool results and their order
When it happensOnce, when you write the promptEvery time you send something to the model
Typical failureVague or ambiguous wordingMissing facts, or so much material that the key facts get lost
Typical fixRewrite the instructionAdd the missing fact, cut the noise, restructure the inputs

They are not rivals. A well-worded prompt with the wrong facts still gives a wrong answer, and the right facts with a muddled instruction give a muddled one. For the wording side, see how to write a prompt. This article is about the facts.

Why more context is not better

It is tempting to attach everything and let the model sort it out. Research says that backfires.

  • Models get less reliable as input grows. Chroma's 2025 Context Rot report tested 18 models, including GPT-4.1, Claude 4 and Gemini 2.5, and found that performance "grows increasingly unreliable as input length grows".
  • Near-misses hurt. The same report found that even a single distractor, text on the same topic that doesn't actually answer the question, lowered accuracy, and more distractors lowered it further.
  • Position matters. The 2023 Lost in the Middle study found models did best when the relevant information sat at the start or end of the input, and worse when it was buried in the middle.

Anthropic's post names the result "context rot" and explains it with an "attention budget": every token you add uses up some of the model's attention, so context is "a finite resource with diminishing marginal returns." An old price list in your attachments isn't harmless background. It is a distractor that competes with the current one.

The six kinds of context

Whatever tool you use, the context is built from the same parts. Most bad answers trace back to one of them being missing, wrong or bloated.

What a model sees, and where it comes from
PartWhat it isWhere you set it
InstructionsRole, rules, tone, formatSystem prompt, custom or project instructions, the prompt itself
Facts and documentsPolicies, prices, product details, the file to work onAttachments, pasted text, project files
ExamplesOne or more samples of what good output looks likePasted into the prompt or the project
Memory and historyThe chat so far, saved preferences, earlier chatsThe conversation, memory and past-chat features
Tool resultsWeb search results, database lookups, file readsTools the model calls, or results you paste in
The taskThe specific request right nowYour message

Instructions that should hold for a whole conversation belong in the system prompt, and the request in the user prompt; system prompt vs user prompt covers that split. Examples are their own technique, covered in few-shot prompting.

How to give a model the right context for a work task

You don't need to build an agent to do context engineering. Anyone who pastes material into ChatGPT, Claude or Gemini is already doing it. Doing it on purpose takes five steps.

  1. Write down what a good answer depends on. Before you open the chat, list the facts a colleague would need to do this task well: who it is for, what they already know, the numbers, the deadline, the constraint. That list is your context.
  2. Pull the facts, not the files. If the answer depends on three numbers in a 40-page report, paste the three numbers with a note on where they came from. Attach the whole file only when the task is about the file.
  3. Label each part. Put facts, examples and rules in separate, named sections. Anthropic's docs recommend XML-style tags such as <context> and <instructions> for this. Headings work in any model.
  4. Put long material first and the question last. For long inputs, Anthropic's docs advise placing documents near the top and the query at the end, and report that this improved response quality by up to 30 percent in their tests.
  5. Say what to do when something is missing. "If you need a fact that isn't here, put it in [brackets]" turns a guess into a visible gap you can fill.

Step 2 is where most time goes, because the facts are spread across your website, your documents and your head. This is the step Prompt Expert is built for: it reads your site and files so the prompt carries your real facts, each with its source.

What to leave out

  • Outdated versions. Last year's prices, the old policy, the draft before the final. The model can't tell which is current unless you say so, so remove them.
  • Internal debate. The thread where the team argued about the price is not the price. Give the decision, not the discussion.
  • Material on the same topic that doesn't answer the question. This is the distractor problem: a competitor deck attached to a renewal email gives the model a second set of numbers to mix up.
  • Raw exports. A CRM export with 60 columns, when the task needs four of them.
  • Anything you wouldn't want quoted. Assume anything in the context can appear in the output. Leave out personal data and secrets the task doesn't need.
  • Repetition. Saying the same rule three times wastes tokens. If a rule matters, give its reason once.

Anthropic's post adds a useful caution: minimal "does not necessarily mean short." Cutting noise is the goal, not cutting facts the task needs.

A worked example: a renewal email with a price increase

The task: a client's annual contract is ending and the price is going up. The client, a dental group, is made up for this example. Here is how most people start.

Before: everything attached, nothing chosen
Write a renewal email to Harbor Dental. Our price is going up. Make it persuasive. Here is everything I have: [CRM export, 40 emails, the pricing debate thread, the competitor deck, last year's price sheet]

The instruction is short, but the context is huge and mixed. The model has two price sheets to choose between, a debate where some people argued for a smaller increase, and a competitor deck full of other numbers. It doesn't know who is reading, what she cares about, or what the client has gained. You get a long, generic email, possibly with the wrong price.

Now the same task with the context chosen and labeled. Every fact has a source, so you can check it, and only facts that change the email made it in.

After: chosen, labeled context (314 tokens, o200k_base)
<task>
Write a renewal email to Dana Okafor, Operations Lead at Harbor Dental Group. Their annual contract for our scheduling software ends on 31 January. The price per location goes up. Goal: she renews for another year and feels the increase is fair.
</task>

<facts>
- Current price: $89 per location per month. New price from 1 February: $99. (Source: 2027 price sheet)
- Harbor has 6 locations. (Source: CRM)
- Since they started, Harbor's no-show rate fell from 14% to 8%. (Source: their usage report, October)
- New this year at no extra cost: text reminders in Spanish, and two-way calendar sync. (Source: release notes)
- Customers who renew before 15 January keep $89 for the first three months. (Source: sales policy)
</facts>

<relationship>
Dana is direct and busy. She asked for fewer, shorter emails last spring. She has been happy with support.
</relationship>

<example_of_our_tone>
Hi Dana, quick one: your team's reminder texts now go out in Spanish too. Nothing to set up. Shout if you want a walkthrough. Sam
</example_of_our_tone>

<rules>
- Under 150 words. One clear next step.
- State the new price and the date plainly. No "small adjustment" language.
- Use only the facts above. If you need anything else, put it in [brackets].
</rules>

What changed, and why each part is there:

  • Five facts instead of five files. The one current price, the result the client got, what is new, and the early-renewal offer. Those are the facts the email turns on.
  • A sentence on the reader. "Direct and busy" and "asked for shorter emails" shape the email more than any tone adjective.
  • One real example. A two-line message in your own voice teaches tone faster than describing it.
  • Sources in brackets. They cost a few tokens and let you check every number before you send.
  • A rule for gaps. If the model wants the account manager's phone number, it leaves a blank instead of inventing one.

Measured with OpenAI's o200k_base tokenizer, the whole prompt is 314 tokens. Five attached files would be far longer, and almost all of that length would be noise for this task.

Here is the same structure as a template you can reuse for any task that depends on your facts.

Context template for a work task
<task>
[What you want written or done, for whom, and the goal.]
</task>

<facts>
- [Fact the answer depends on] (Source: [where it came from])
- [Another fact] (Source: [where])
</facts>

<reader>
[Who will read the output, what they know, what they care about.]
</reader>

<example>
[A short sample of output you liked, in your voice.]
</example>

<rules>
- [Length and format.]
- Use only the facts above. If you need anything else, put it in [brackets].
</rules>

Context engineering in agents and long tasks

Anthropic's post is written for people building agents, which run for many steps and call tools. The same principle applies, but the context changes as the agent works, so the techniques are about keeping it clean over time.

  • Just-in-time retrieval. Rather than loading everything up front, the agent keeps lightweight references, such as file paths, stored queries and links, and loads data with tools when it needs it.
  • Compaction. When the context fills up, summarize it and start fresh with the summary. Clearing old tool results is the lightest version.
  • Structured notes. The agent writes notes, such as a to-do list, to a file outside the context and reads them back later.
  • Sub-agents. Focused helpers work in their own clean context and hand back a short summary to the main agent.

You can borrow two of these in an ordinary chat. Compaction: when a long chat starts to drift, ask for a summary of the decisions so far and start a new chat with it. Sub-agents: split a big job into separate chats, each with only the context its step needs, which is the idea behind prompt chaining.

Let the right experts write your prompt

Prompt Expert is an AI prompt generator that brings the right experts to every job. They ask a few questions, read your website and files, and write the prompt for ChatGPT, Claude or Gemini with your real facts, working together when a job needs more than one.

See how it works

Questions

What is context engineering in simple terms?

It is deciding what information an AI model sees before it answers, and how that information is arranged. That includes instructions, documents, examples, chat history and tool results, not just the wording of your request.

Is context engineering replacing prompt engineering?

It is better seen as the broader version. Anthropic calls it the natural progression of prompt engineering: wording the instruction still matters, but most bad answers come from missing or noisy information, which is what context engineering deals with.

Do I need to be a developer to use context engineering?

No. Choosing which facts to paste, labeling them, removing outdated material and saying what to do when something is missing are all context engineering, and they work in any chat app.

Is it better to give AI more context?

Only more relevant context. Studies such as Chroma's Context Rot report found models get less reliable as input grows and that related but irrelevant text lowers accuracy. Include what changes the answer and cut the rest.

Where should I put documents in a long prompt?

Near the top, with your question and instructions at the end. Anthropic's docs recommend this for long inputs, and research has found models use information at the start and end of the input better than information in the middle.

Sources