Skip to content
DigitalNeuron
Agents & automation

Your agent's context window is a budget, not a diary — here's how Anthropic spends it

Anthropic's context-engineering guidance treats the context window as a scarce, decaying resource. Four techniques it documents: context editing, an external memory tool, compaction, and sub-agents with their own clean windows.

By DigitalNeuron Desk3 min read

Quick answer

How does Anthropic recommend managing context in long-running AI agent sessions?

Anthropic's guidance reframes prompt engineering as context engineering: curate the smallest set of high-signal tokens for each turn instead of accumulating everything. In its own evals, automatically clearing stale tool results plus an external memory file improved a search task by 39% and cut token use by 84% over 100 turns.

Key takeaways

  • Anthropic frames the goal as finding the smallest set of high-signal tokens that maximize the odds of the outcome you want, not maximizing how much you fit in the window.
  • Context editing automatically strips stale tool calls and results as a session nears its token limit — in Anthropic's own 100-turn eval this cut token consumption by 84%.
  • A memory tool lets an agent write files to a directory that persists across conversations, outside the context window entirely, instead of trying to re-derive everything from a shrinking transcript.
  • Compaction — summarizing history and reinitializing from the summary — should be tuned for recall first and precision second, using real agent traces rather than made-up examples.
  • Sub-agents that explore with their own clean context window and report back a condensed summary (Anthropic cites roughly 1,000-2,000 tokens) keep the main agent's window from filling with someone else's scratch work.

A long agent session doesn't run out of intelligence. It runs out of room. Every tool call, every file it reads, every retry gets added to the transcript, and none of it leaves on its own — until the window is mostly the record of what the agent already tried, with less and less space for what it's supposed to do next. Anthropic's engineering team has published a specific answer to this, and it is less "write a better prompt" and more "manage a shrinking budget."

The reframe: context engineering, not prompt engineering

Anthropic's own framing is a single sentence: find the smallest set of high-signal tokens that maximize the likelihood of your desired outcome. That's a different goal from "fit as much relevant material as possible." A long agent session accumulates information whether or not it's still useful, and the fix isn't a bigger window — it's actively deciding what stays.

Context editing: clear what's stale

The most direct tool is context editing, which automatically removes old tool calls and their results as a session approaches its token limit, rather than leaving them to sit as dead weight. In Anthropic's internal evals, this alone produced a 29% improvement on an agentic search task. Combined with the memory tool below, that rose to 39%. In a separate 100-turn web-search evaluation, context editing cut total token consumption by 84% — and let the agent finish workflows that failed outright without it, because the transcript ran out of room before the task did.

Memory that lives outside the window

The memory tool gives an agent a directory it can create, read, update, and delete files in, and that directory persists across conversations — it isn't part of the context window at all. Instead of re-deriving what it already figured out three turns ago from a transcript that keeps getting trimmed, the agent can write it down once, outside the conversation, and read it back when needed.

Compaction: summarize, then start over

For sessions too long to keep patching, compaction summarizes the history and reinitializes the agent from that summary rather than the full transcript. Anthropic's guidance on tuning a compaction prompt is specific about order: get recall right first — make sure nothing important is dropped — then tighten for precision once you're confident nothing's missing. Clearing stale tool results, by contrast, is described as one of the lightest-touch, safest forms of compaction available, which is a reasonable place to start before reaching for a full summarization step.

Sub-agents keep their own mess to themselves

This is the technique Anthropic points to for parallel exploration: several sub-agents can each burn through their own scratch work without ever polluting the main agent's window with somebody else's dead ends. Anthropic's write-up cites a demo agent playing Pokémon and maintaining task precision across thousands of game steps using this combination of techniques.

Structured notes, kept outside the conversation

The last piece is low-tech on purpose: an agent keeping a running external note — a to-do list, a NOTES.md file — instead of relying on the conversation itself as its only memory of what it has and hasn't done. Anthropic's own Claude Code is the example cited for this pattern. It costs nothing to build and it doesn't compete with the context window for space, because it isn't in it.

Check the date. Context editing and the memory tool are documented as a public beta as of this writing (Anthropic dated its own posts September 29, 2025, describing Claude Sonnet 4.5). Beta features change quickly — read the linked pages directly for current availability rather than relying on this summary months later.

Frequently asked questions

Is context editing something I have to build myself?
No — Anthropic ships it as a public-beta feature on the Claude Developer Platform, Amazon Bedrock, and Google Cloud Vertex AI for Claude Sonnet 4.5, which also has built-in awareness of its own token usage.
What's the difference between the memory tool and just writing a longer system prompt?
The memory tool is a separate directory Claude reads and writes as files across conversations. It sits outside the context window entirely rather than taking up room inside every single turn.
Does OpenAI publish something equivalent for ChatGPT or its Agents API?
Not that this article found. Anthropic has published detailed engineering guidance and beta features specifically framed as context engineering; a directly comparable OpenAI document was not found in our research for this piece.
What's the simplest version of this to try first?
Anthropic calls clearing stale tool results "one of the safest, lightest touch" forms of compaction — it's the smallest change to make before reaching for a memory tool or a sub-agent architecture.

Sources

  1. Effective context engineering for AI agentsAnthropic
  2. Managing context on the Claude Developer PlatformAnthropic
Tagsclaudeagentscontext-windowmemorytool-useclaude-code

Related reading

Anthropic partners with Allen Institute and HHMI on scientific AI systems

Anthropic announced life-sciences partnerships with the Allen Institute and Howard Hughes Medical Institute. HHMI will work with Anthropic on specialized laboratory agents, while the Allen Institute will collaborate on coordinated multi-agent systems for scientific analysis, experimental design and other research tasks. Both partnerships will also inform Claude’s broader life-science capabilities.

2 min read

Analysis: OpenAI open-sourced the harness, not the model — and that is the strategy

A harness is the code around the model: it assembles context, runs the tool-call loop, streams events, compacts long sessions, and holds irreversible actions behind human approval. OpenAI released Codex's harness — codex exec, the app-server and the SDK — under Apache-2.0, so any company can embed that same agent loop in its own software while still paying for the model behind it.

5 min read