Claude Sonnet 5.5, Opus 5.5 and Fable 5.2 all list a 1M-token context window, so capacity no longer separates the models; how you curate what goes into it does.
Context rot is an empirical problem of recall and reasoning under distractors, not a mathematical consequence of attention being O(n²). Capacity and effective recall are different things.
Sonnet 5.5 does not receive the injected budget tags that Sonnet 5 does. Count tokens in your own code with the token counting API, or use the beta task budgets feature.
Five patterns cover most of my long-context work: retrieve just-in-time, keep a notes file, compact long histories, delegate to sub-agents, and cache the stable prefix.
Compaction summaries are lossy. Keep exact facts, code and decisions in notes, not only in a summary.
Working With 1M-Token Context Windows: Practical Patterns for AI Agents
The first time I had a full 1M-token window available, I did the obvious thing: I pasted an entire repository into a single prompt and asked Claude Sonnet 5 to find a bug. It found it, eventually, after a slower and less confident pass than I expected from a model this capable. That was my first real lesson about the 1 million token context window — having the room does not mean you should fill it.
A million tokens is no longer a one-model feature. Claude Sonnet 5.5, Opus 5.5 and Fable 5.2 all list it, no beta header required. That is genuinely useful. It is also easy to misuse. This post is for developers building agents, retrieval pipelines or coding assistants, and it covers the patterns I now reach for rather than just marvelling at the number. I use Claude Sonnet 5.5 for the examples, but the ideas travel to other long-context models.
What the 1M-Token Window Actually Gives You
Here is how the current Claude models compare, taken from Anthropic’s models overview:
Model
Context window
Input / output per 1M tokens
Sonnet 5 (now legacy)
1M
$2 / $10
Sonnet 5.5
1M
$2 / $10
Opus 5.5
1M
$4 / $20
Fable 5.2
1M
$8 / $40
Base prices only; caching and batch discounts come on top.
Anthropic now describes Sonnet 5 as a legacy model and recommends moving to Sonnet 5.5, which has the same window and the same base price. Sonnet 5 itself was billed at standard rates for long-context requests, with no long-context surcharge. A single request can also carry up to 600 images or PDF pages, compared with 100 on models still capped at 200k tokens.
There is a catch worth knowing before you budget anything against that figure. Sonnet 5 and Sonnet 5.5 share a tokenizer that arrived with Claude 4.7, and the same text produces roughly 30% more tokens than it did on earlier models. That comparison is against the older models, not between Sonnet 5 and Sonnet 5.5. I covered this in more detail in my look at Sonnet 5’s tokenizer tax; the short version is that a token now buys less text than it used to. By my own rough maths — roughly 4 characters per token, adjusted for the 30% inflation — 1M tokens holds somewhere around half a million words of combined prompt and response. Treat that as an estimate, and recount your own prompts if the number matters to you.
Everything counts toward that window, not just your message text: the system prompt, tool definitions, thinking tokens, and tool results all draw from the same budget.
Count before you send
“Recount your prompts” is easy advice to give and tedious to follow, so here is the smallest useful version. The token counting API is free to use and accepts the same system, messages and tools you would send to the model. Count first, reserve room for the answer, and only then decide whether to send, retrieve or compact.
The example needs a live Anthropic API key, so I have checked it against the token counting docs and compiled it, but not run it end to end.
pip install anthropic
importanthropicMODEL="claude-sonnet-5-5"CONTEXT_LIMIT=1_000_000MAX_OUTPUT=4_096SAFETY_MARGIN=20_000client=anthropic.Anthropic()system="You are a careful Python code reviewer."messages=[{"role":"user","content":("Review this Python module for potential bugs.\n\n""def calculate_total(prices):\n"" return sum(prices)\n"),}]count=client.messages.count_tokens(model=MODEL,system=system,messages=messages)input_tokens=count.input_tokensremaining=CONTEXT_LIMIT-input_tokens-MAX_OUTPUTprint(f"Input: {input_tokens:,} tokens")print(f"Estimated remaining budget: {remaining:,} tokens")ifremaining<SAFETY_MARGIN:print("Too close to the limit: retrieve or compact before sending.")else:response=client.messages.create(model=MODEL,max_tokens=MAX_OUTPUT,system=system,messages=messages,)print(response.content[0].text)print(f"Actual input tokens billed: {response.usage.input_tokens:,}")
Three ideas are packed into those few lines:
The window is a shared budget, not a target to fill.
Reserving output room and a safety margin is cheap insurance.
The counter beats estimating from word or character counts.
Two caveats. The count is an estimate, and Anthropic says the real usage can differ by a small amount, so read the actual figure from response.usage afterwards. And the count only covers what you pass in, so in a real application include your tool definitions too, or the number will flatter you.
Context Rot: Why More Tokens Is Not Automatically Better
Anthropic’s own engineering team has a name for the failure mode a bigger window does not fix: context rot — as the number of tokens in a context window grows, a model’s ability to accurately recall information from that context decreases. This is not specific to any one Claude model. It is a property of current long-context models in general.
It is tempting to explain it with maths. In standard full self-attention, the number of token-to-token interactions grows with the square of the sequence length, O(n²). That is true, and it explains why long prompts cost more compute. But it does not, by itself, prove that recall gets worse. Complexity tells you what a prompt costs; it does not tell you what the model will find in it.
Context rot is about the quality of retrieval and reasoning, and that depends on other things: how many distractors sit near the answer, where in the prompt the key fact lives, how hard the task is, and how the model was trained. A million tokens is not just more to read. It is more for the model to weigh against everything else in view.
Anthropic frames context as a finite resource with diminishing marginal returns: good context engineering means finding the smallest set of high-signal tokens that gets you the outcome you want, not the largest set you can fit. That is the opposite of how a 1M-token window instinctively makes you behave. A bigger window tempts you to stop curating. Context rot is the reason you should not.
Budget Awareness: Sonnet 5 Has It, Sonnet 5.5 Does Not
This is the part of the post that aged fastest, so here is the current picture.
Some Claude models have context awareness. The API injects a tag at the start of every request telling the model its total token budget:
You do not enable this and you never send these tags yourself. Sonnet 5, Sonnet 4.6, Sonnet 4.5 and Haiku 4.5 get them. Sonnet 5.5 does not. Nor do Opus 4.7 and later, Fable 5.x, Mythos 5.x or Haiku 5.5. If you moved an agent from Sonnet 5 to Sonnet 5.5 and your prompt says “check your remaining budget”, the model now has nothing to check. Awkward.
You have two options on the newer models:
Application-side monitoring. Count tokens yourself, as in the example above, and act on the result: retrieve, compact or stop.
Task budgets (beta). You give the model an advisory token budget for a whole agentic loop, and it paces itself against a server-side countdown. It needs the task-budgets-2026-03-13 beta header and a task_budget inside output_config, with a minimum of 20,000 tokens.
Two details matter. The budget is advisory, so the model may occasionally overshoot, and max_tokens stays the hard cap. And the countdown is visible to the model only, so you still track spend in your own code if you want to see it. Task budgets are available on the Messages API, not in Managed Agents, Claude Code or Cowork.
Five Practical Patterns for Working Inside 1M Tokens
These are the patterns I actually reach for, in roughly the order I try them. The diagram shows how they fit together. Notice that most of the machinery sits outside the window: the window is only the working surface.
Diagram 1. The context window is the active workspace; knowledge and task history can live outside it. You need not use every mechanism on every request.
1. Retrieve just-in-time instead of loading everything up front
The instinct with a 1M-token window is to pre-load everything relevant. Anthropic’s guidance pushes the other way: maintain lightweight identifiers — file paths, stored queries, links — and load the actual content only when the model needs it, the way Claude Code uses grep and glob to navigate a codebase rather than reading it all in up front. Slower per step than one giant prompt, but the working set stays small and relevant instead of large and diluted.
2. Keep a running notes file for long tasks
For anything spanning more turns than fit comfortably in one window, have the agent write its own progress notes to a file outside the conversation — decisions made, open questions, what has already been tried — and read them back in when a new session starts. This is the same pattern behind Anthropic’s memory tool, and it works even without that specific tool: a plain NOTES.md the agent is instructed to maintain does most of the job.
Still in this guide
A Desk, Not a Warehouse: A Mental Model for the Context Window
Checklist: Working With Long Context Windows
Final Thoughts
References
You've hit a Deep Dive tutorial.
I spend dozens of hours researching, coding, and breaking things to write these guides. This content is free, but reserved for my subscriber community. Drop your email below to unlock this guide (and all past/future deep dives):
Full content temporarily unavailable — refresh in a moment
You're in
I'll send weekly notes on AI tools, Python, and what I'm actually building. Check your inbox for Set a password to unlock articles — the form does not log you in.
New subscribers get an inbox mail: Set a password to unlock articles. The form does not log you in — use the same email afterwards.
References
About Elena
Elena, a PhD in Computer Science, simplifies AI concepts and helps you use machine learning.
Citation
Elena Daehnhardt. (2026) 'Working With 1M-Token Context Windows: Practical Patterns for AI Agents', daehnhardt.com, 11 November 2026. Available at: https://daehnhardt.com/blog/2026/11/11/claude-sonnet-5-1m-token-context-window-patterns/
Want the Fantastic AI 2026 toolkit and the AI Coding Safety Card in your inbox?
Fantastic AI: The 2026 ToolkitAI Coding Safety CardVibe Coding Checklist
+4more free gifts
You're in
I'll send weekly notes on AI tools, Python, and what I'm actually building. Check your inbox for Set a password to unlock articles — the form does not log you in.