Prompt & Context Engineering Best Practices
Cutting token spend and protecting answer quality are not competing goals: the same discipline usually achieves both at once.
Search across all documentation pages
Cutting token spend and protecting answer quality are not competing goals: the same discipline usually achieves both at once.
This is a standalone checklist of practices for deciding what goes into a prompt, which model handles it, and how a long-running agent manages its context over time.
count_tokens call turns "this feels smaller" into a number you can track over time.Start with "Minimize What You Send," since trimming context removes tokens outright with no added API call, making it usually the highest-leverage starting point.
No, weigh each by the task's volume and stakes.
Treating "send more, use the strongest model, max out effort" as the safe default, when in practice it's usually the most expensive choice and not even guaranteed to be the highest-quality one, due to context rot.
Test the summary against real downstream questions and check whether it still supports a correct answer.
If it can't, lengthen the summary, add a focus instruction, or skip summarization for that document in favor of exact extraction.
For small, low-volume systems where the engineering cost of tiering logic outweighs the savings, yes, that can be a reasonable simplification.
At meaningful volume, the cost difference between tiers usually justifies at least basic routing logic.
Whenever task inputs, volume, or the model lineup change meaningfully, and on a regular cadence, quarterly is a reasonable default, for any high-volume task category.
Applying a rule that sounds right but has no measured effect on your specific task can cost engineering effort without a corresponding benefit.
Pair every practice here with an evaluation set where possible, rather than trusting the rule in the abstract.
No, they work together: caching avoids re-executing and re-transmitting duplicate results, which both saves cost and keeps the conversation history from padding out with repeated data.
Because tiering, budgeting, and effort decisions all rely on judgment calls specific to a task's stakes and volume, and those judgment calls need to be revisited as circumstances change.
Undocumented decisions tend to either never get revisited or get silently re-decided inconsistently by different engineers.
There's no single metric; track token cost per task category alongside a quality metric (pass rate on an eval set) together, since a token reduction that costs quality isn't actually a win.
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 19, 2026