Context Engineering vs Prompt Engineering

Prompt engineering is about what you ask. Context engineering is about everything the model can see when you ask it. For agents working over many steps, the second matters more.

Context Engineering vs Prompt Engineering — Troiana insight cover

In short

Prompt engineering is writing clear instructions for a model. Context engineering is deciding what information the model sees at each step, including instructions, files, tool results and history. Anthropic calls the goal the smallest possible set of high-signal tokens. Prompts still matter, but in long agent sessions, what's in context often decides the result: keep it relevant, retrieve details when needed, and clear what's stale.

Definitions

Anthropic's engineering team draws the distinction well. Prompt engineering covers “methods for writing and organizing LLM instructions for optimal outcomes”. Context engineering covers “the set of strategies for curating and maintaining the optimal set of tokens” during inference, including everything beyond the prompt, such as tools, external data and message history.

Here's a simple way to think about it. A prompt is the question you ask a consultant. Context is the folder of documents on their desk when you ask it. A great question won't help if the folder is full of irrelevant or out-of-date papers.

Prompt engineeringContext engineering
FocusThe wording of instructionsAll information available to the model
WhenUsually written onceDecided at every step
Typical unitOne requestA whole session or workflow
Main skillClear writingDesigning what's retrieved and removed
Fails whenThe instruction is vagueThe relevant fact is missing, or buried

For more on the first one, see prompt engineering for product teams.

Why this became important

A single question and answer is mostly a prompting problem. Agents are different. They run for many steps, read files, call tools and collect results, all of which pile up. So a long session can end up holding thousands of lines of old logs, along with files that have since changed and instructions that no longer apply.

Anthropic describes models as having an “attention budget”, and notes that performance can degrade as context grows. That matches what many developers see: an agent that was sharp in the morning becomes confused by late afternoon, in the same session. It's also expensive, since each request sends the conversation again. See what a context window is.

PromptRulesToolsFiles readHistory
An illustrative split, not a measurement. In a long session the prompt you wrote is a small part of what the model sees.

The principles

Anthropic's guidance gives a helpful set of principles:

  • Treat context as finite. Aim for “the smallest possible set of high-signal tokens”.
  • Set instructions at the right level. Avoid brittle, hard-coded logic and also vague guidance.
  • Keep tools minimal and unambiguous. Overlapping or bloated tools confuse agents.
  • Use a few canonical examples, rather than long lists of edge-case rules.
  • Retrieve just in time. Let the agent look things up when needed, rather than loading everything first.
  • Manage long tasks with compaction, structured notes and subagents.

What it looks like in practice

Here's how the same task differs in a coding agent.

Prompt-only approach:

“You are an expert engineer. Carefully fix the checkout bug and be thorough.”

With context engineering:

  • A short project file sets conventions and test commands
  • The prompt names the error, and points to the relevant file
  • A subagent does the noisy log search, and returns only the failing line
  • The conversation is cleared before you begin an unrelated task

The second approach doesn't need clever wording. It just gives the model what it needs, and nothing that it doesn't.

Practical techniques

Keep always-loaded files short. Anything in CLAUDE.md or AGENTS.md costs you in every session. Anthropic suggests keeping CLAUDE.md under 200 lines. Include only what's needed in most tasks.

Move occasional knowledge into skills. They load only when relevant.

Isolate noisy work. Let subagents read the logs and return summaries.

Clear between tasks. Stale context is worse than no context. Start new tasks with a clean session, and use /clear or its equivalent.

Point rather than paste. “See src/auth/session.ts” is often better than pasting the file, since the agent can read what it needs and get the latest version.

Write notes that survive. For long projects, ask the agent to keep a progress file, with decisions and next steps, so that a new session can pick up without replaying everything.

Curate your tools. Connecting many MCP servers adds overlap and choices. Disable those you aren't using.

Filter output. Have tests report failures only, and search for errors rather than reading a whole log.

Use retrieval for large knowledge bases. See what RAG is. But be careful of retrieving too much: more isn't better.

For product teams

If you're building an AI feature rather than using a coding tool, the same ideas apply:

  • Decide exactly what user data each request needs. Don't send the whole record because it's easier.
  • Summarise long conversations rather than resending everything.
  • Keep system prompts versioned, and test them. See how to evaluate an LLM feature.
  • Log what context was sent, so you can debug bad answers. See how to log and debug AI features.
  • Treat retrieved content as untrusted. It may contain instructions aimed at the model. See how to stop prompt injection.
  • Watch your costs. Context is what you're paying for. See how to control AI API costs.

Sending less customer data also reduces privacy risk. See is it safe to send customer data to an LLM?

Does prompting still matter?

Yes. Clear goals, constraints, examples and output formats still make a big difference. Context engineering doesn't replace them; it's the broader discipline that contains them. What's fading are the old tricks, such as magic phrases and elaborate role-play, because modern models need clarity more than incantations.

Teams also talk about harness engineering, which is broader again: the whole system around the model, including tools, permissions and feedback loops.

How to start tomorrow

  1. Run your coding agent's context view, such as /context in Claude Code, and see what's taking up space.
  2. Cut your project instructions down to what's true for most tasks.
  3. Start a fresh session for each unrelated task.
  4. Move your noisiest task to a subagent.

If you'd like help building reliable AI workflows or features, book a call.

Common questions

What is context engineering?

It's the practice of deciding what information an AI model sees at each step, including instructions, files, tool results and conversation history. The goal is to provide the smallest set of relevant information that makes a good result likely.

Is context engineering replacing prompt engineering?

Not replacing it, but extending it. Clear instructions still matter. In long agent workflows, though, what's in context often has more effect than the wording, so context engineering has become the more important skill for that kind of work.

Why does an agent get worse during long sessions?

Context fills up with old logs, outdated files and earlier instructions, which can distract the model and crowd out what matters. Anthropic notes that performance can degrade as context grows. Clear between tasks, and keep long-running notes in a file.

How do I reduce context in a coding agent?

Keep project instruction files short, move occasional procedures into skills, use subagents for noisy work, point to files rather than pasting them, filter command output and clear the session between unrelated tasks. Disable tools that you aren't using.

Have something worth building right?