How Context Engineering Reduces Token Spend
Context engineering is the discipline of deciding what actually goes into a prompt before it reaches Claude.
Search across all documentation pages
Context engineering is the discipline of deciding what actually goes into a prompt before it reaches Claude.
It sits upstream of prompt wording and model selection, and it is often the single largest lever a team has over API cost.
A team that writes a great prompt but pastes in an entire repository has already lost most of the savings available to it.
This page builds the mental model behind three techniques that recur throughout this section: minimal-context prompting, summarization, and model tiering.
Each of these reduces token spend, and each does so through a different mechanism, so it is worth understanding them as distinct levers rather than one blurred idea of "being efficient."
Every request to Claude has a cost that scales with the number of input tokens and output tokens involved.
Input tokens include the system prompt, the conversation history, any retrieved documents, and any tool results injected into context.
Most teams focus first on output length or on choosing a cheaper model, but for many workloads the input side of the ledger is larger and easier to control.
Minimal-context prompting is the practice of sending only the specific snippets a task needs rather than the full source file, the full document, or the full repository it was pulled from.
Summarization is the practice of using a cheap, fast model to compress a long document into a shorter representation before that representation is sent to a more expensive model for the real work.
Model tiering is the practice of routing a request to the cheapest model in a lineup, such as Claude Haiku 4.5, that can still meet a quality bar, and reserving a stronger model like Claude Opus 4.8 for the requests that actually need it.
A simple analogy: think of Claude's context window as a desk.
You can pile the entire filing cabinet on the desk so nothing is ever missing, or you can pull only the folders relevant to the task in front of you.
The second approach costs less to prepare, and it also keeps the desk usable.
# A minimal-context call: only the relevant function, not the whole file
prompt = f"""Review this function for a null-pointer bug.
{relevant_function_source}
"""These three techniques act at different points in a request's lifecycle, and understanding where each one sits clarifies when to reach for it.
Minimal-context prompting acts at assembly time: before you build the prompt string, you decide which snippets, rows, or paragraphs are relevant and exclude the rest.
This is usually the highest-leverage technique because it removes tokens entirely rather than compressing them, so there is no secondary API call and no compression cost.
The trade-off is that it requires some upfront work to know what is relevant, whether that is a search step, a dependency graph, or a retrieval index.
Summarization acts at pre-processing time: a long document exists, it is too large or too unfocused to send whole, and a cheaper model reduces it before the expensive model ever sees it.
This adds one extra API call, but that call uses a cheap model, so the net cost is still lower than sending the full document to the expensive model.
Summarization is most valuable when the same long document will be referenced across many calls, because the summarization cost is paid once and the savings compound.
Model tiering acts at routing time: for each incoming request, a decision is made about which model in the lineup should handle it.
def choose_model(task_complexity: str) -> str:
if task_complexity == "simple_lookup":
return "claude-haiku-4-5"
if task_complexity == "standard_reasoning":
return "claude-sonnet-5"
return "claude-opus-4-8" # multi-step reasoning, high-stakes outputThe three techniques compose well together.
A pipeline might use minimal-context prompting to select relevant files, summarization to condense any file that is still too long, and model tiering to decide whether the final call needs Sonnet 5 or can run on Haiku 4.5.
None of them requires the others, but stacking them produces multiplicative, not additive, savings, because each technique reduces a different dimension of spend.
At scale, these techniques stop being isolated tricks and start becoming policy decisions that a team documents and revisits.
A context window budget, for example, sets a hard ceiling on how much context an agent is allowed to accumulate before something has to give, whether that is summarization, truncation, or ending the session.
Model tiering decisions benefit from an explicit checklist rather than ad hoc judgment calls, because "does this task need Opus" is a question that different engineers will answer inconsistently without shared criteria.
Minimal-context prompting for code tasks scales further with dependency graphs: instead of hand-picking snippets, a graph of imports and call sites tells you exactly which files are structurally relevant to a change, which scales to large codebases in a way manual selection does not.
It is worth being honest that all three techniques can be pushed too far.
Removing too much context, over-compressing a document, or routing a genuinely hard task to a cheap model all produce a cost saving that is paid for in wrong answers, and a wrong answer that has to be re-run is more expensive than the tokens it saved.
| Technique | Strength | Weakness | Best Fit |
|---|---|---|---|
| Minimal-context prompting | Removes tokens entirely, no extra call | Requires knowing what's relevant | Code review, targeted Q&A, RAG |
| Summarization | Compresses reusable long documents | Adds a call, can lose nuance | Long docs referenced repeatedly |
| Model tiering | Matches cost to task difficulty | Wrong tier degrades quality | High-volume, mixed-difficulty workloads |
The common thread across all three is that they are decisions made before the expensive model call, not after.
Optimizing a prompt's wording after the context is already bloated recovers far less cost than deciding what belongs in the prompt in the first place.
Context engineering is deciding what information to include in a prompt, as opposed to how to word it or which model should receive it.
No.
Minimal-context prompting is usually the highest-leverage starting point because it removes tokens outright with no added API call, whereas summarization and tiering both require some infrastructure to set up.
Yes.
The summarization call uses a cheap, fast model, while the original document would otherwise be sent in full to a costlier model on every use; when a document is referenced many times, the one-time cheap summarization cost is far smaller than the repeated cost of sending the full document.
Model tiering routes each request to the cheapest model in the Claude lineup, such as Haiku 4.5, that can still meet the required quality bar, reserving stronger models like Sonnet 5 or Opus 4.8 for tasks that genuinely need deeper reasoning.
Yes, and combining them is typical in production systems.
A dependency graph maps which files or modules a piece of code imports or calls; sending that graph plus only the relevant snippets keeps a code-related prompt focused, instead of pasting an entire repository.
Yes.
The effort parameter controls how much reasoning the model applies to a given prompt; it is a separate lever from context size, but both are swept and evaluated the same way, from a cheap setting up to the strongest one that still passes quality checks.
Yes.
Optimizing prompt wording before addressing what's included in the prompt at all; wording changes save a small percentage, while context decisions often account for the majority of spend.
If your prompts regularly include full files, full documents, or full conversation histories rather than the specific parts relevant to the current request, there is very likely room to reduce spend without touching model choice.
Stack versions: Written against the Claude model lineup current as of ~June 2026 - Claude Fable 5, Claude Opus 4.8, Claude Sonnet 5 (the default), and Claude Haiku 4.5 - and the official
anthropicPython SDK (latest 0.x release). Model names, pricing, and SDK versions move quickly - verify current specifics at platform.claude.com/docs before relying on them.
Reviewed by Chris St. John·Last updated Jul 16, 2026