Fetching from the wire…
Top 5 · 2026-05-23 · source-backed
Context engineering just got its cookbook.
Anthropic's Claude Cookbook published a complete guide to three API-level primitives that, used together, reduced a research agent's peak context from 335K tokens to a sustained 50-80K range. Server-side compaction. Tool-result clearing. Persistent memory. Each one is simple. Together they change the economics of long-running agents.
Compaction triggers at a configurable token threshold (the cookbook uses 150K) and distills the conversation to a summary, preserving key decisions while dropping the narrative. Tool-result clearing replaces bulky tool outputs with [cleared] placeholders at zero inference cost, because tool results are almost always re-fetchable. Persistent memory stores cross-session state in files the model manages itself.
The diagnostic framework is the part I keep thinking about. If more than 80% of your context is re-fetchable tool output, use clearing first. If long dialogue accumulates, add compaction. If work spans sessions, add memory. That's not a recipe. It's a decision tree. And it works because it forces you to ask the right question: what in this context window is actually load-bearing?
I run a research agent pipeline every day in my personal projects. Context bloat is the single biggest reliability problem I hit. Agents get dumber as context fills up. They start ignoring earlier instructions. They lose track of what they've already done. The fix isn't a bigger context window. It's being surgical about what stays in it.
The cookbook also introduces the "Summarize up to here" option in Claude Code's Rewind menu. Manual mid-conversation compaction. Use it after completing a major milestone to reclaim token budget while preserving key decisions. Claude Code docs confirm this shipped recently.
For builders: implement tool clearing before anything else. If your agents call tools that return large JSON payloads, you're paying to re-read that data on every subsequent turn. Clear it after extraction. The cost savings compound with every interaction.
Each link below shares sources, entities, or timing with this story.
Opus built by Anthropic / Shared entities / Same source / Shared topic / What happened next
Linked by a graph relationship (Opus built by Anthropic); both cover Anthropic, Compaction; cite the same source (Anthropic's Claude Cookbook).
Sapiom uses Anthropic / Shared entities / Same source domain / Shared topic / What happened next
Linked by a graph relationship (Sapiom uses Anthropic); both cover Anthropic, Claude Code; reported by the same outlet (platform.claude.com).
Anthropic released Claude Code / Shared entities / Shared topic / What happened next
Linked by a graph relationship (Anthropic released Claude Code); both cover Anthropic, Claude Code, Compaction; overlapping topics (agent, context, token).
Anthropic released Claude / Shared entities / Shared topic / Earlier coverage / Downstream implication
Linked by a graph relationship (Anthropic released Claude); both cover Anthropic, Each, JSON; overlapping topics (agent, context).
Anthropic released Claude Code / Shared entities / Shared topic / Earlier coverage
Linked by a graph relationship (Anthropic released Claude Code); both cover Claude Code, Context, Tool; overlapping topics (agent, context, tool).
Linked by a graph relationship (Anthropic released Claude Code); both cover Anthropic, Claude Code, Each; overlapping topics (agent, context, token).
Anthropic released Claude / Shared entities / Shared topic / What happened next
Linked by a graph relationship (Anthropic released Claude); both cover Anthropic, Compaction; overlapping topics (agent, compaction, context, cost, token).
Anthropic released Claude Code / Shared entities / Shared topic / Earlier coverage / Tension
Linked by a graph relationship (Anthropic released Claude Code); both cover Claude Code, Each; overlapping topics (agent, context, decision, tool).