Management with Anthropic Claude: A Guide to Smarter, Longer Conversations
From the publisher’s feed, collected in the ZeroLabs newsroom.
Why Context MattersIf you’ve built with large language models, you’ve hit the wall: context window limits. Conversations grow, token counts climb, costs spiral, and eventually your AI assistant starts forgetting what you talked about just a few messages ago. It’s the fundamental constraint of working with LLMs — until now.Anthropic’s new context editing features are game-changers for developers building serious applications with Claude. They’re not just about saving tokens (though they do that beautifully) — they’re about enabling long-running, complex workflows that were previously impossible.The Two-Sided Solution: Server-Side and Client-SideAnthropic gives us two complementary approaches:1. Server-Side Context Editing (API-level magic)Automatically clears old content before it reaches Claude, while your application keeps the full history locally. No state syncing needed.2. Client-Side Compaction (SDK-level intelligence)Generates conversation summaries and replaces history, enabling truly epic multi-session tasks.Let’s dive into the good stuff.1.1 Server-Side Strategy: Clear Tool UsesThe Problem: Your agent uses 15 web searches, processes 20 files, and now 80% of your context window is filled with old tool results while Claude tries to remember what you’re actually working on.The Solution: clear_tool_uses_20250919response = client.beta.messages.create( model="claude-sonnet-4-5", messages=[your_conversation_history], tools=[your_tools], betas=["context-management-2025-06-27"], context_management={ "edits": [ { "type": "clear_tool_uses_20250919", "trigger": {"type": "input_tokens", "value": 30000}, "keep": {"type": "tool_uses", "value": 3}, "clear_at_least": {"type": "input_tokens", "value": 5000}, "exclude_tools": ["critical_database_query"] } ] })What happens: When your conversation hits 30,000 tokens, Anthropic automatically removes the oldest tool results (keeping the 3 most recent), ensuring at least 5,000 tokens get cleared. Your important database queries stay untouched.The beauty: Claude still sees the tool calls (knowing what actions were taken), but the verbose results get replaced with placeholders. It’s like giving Claude the meeting minutes instead of the full transcript.1.2 Server-Side Strategy: Clear Thinking BlocksThe Problem: You enabled extended thinking (that brilliant “let me think step by step” feature), and now those thinking blocks are eating your context budget.The Solution: clear_thinking_20251015response = client.beta.messages.create( model="claude-sonnet-4-5-20250929", thinking={"type": "enabled", "budget_tokens": 10000}, betas=["context-management-2025-06-27"], context_management={ "edits": [ { "type": "clear_thinking_20251015", "keep": {"type": "thinking_turns", "value": 2} } ] })Pro Tip: Need maximum prompt caching (for cost savings)? Use "keep": "all". Need maximum context space? Keep fewer turns. This is your dial to balance performance vs. cost.The Power Combo: Multiple Strategies TogetherReal applications need both. Here’s the winning configuration:context_management={ "edits": [ # Thinking clearing FIRST (order matters!) { "type": "clear_thinking_20251015", "keep": {"type": "thinking_turns", "value": 2} }, # Then tool clearing { "type": "clear_tool_uses_20250919", "trigger": {"type": "input_tokens", "value": 50000}, "keep": {"type": "tool_uses", "value": 5}, "clear_at_least": {"type": "input_tokens", "value": 10000} } ]}The Secret Weapon: Memory Tool IntegrationThis is where it gets magical. When context editing is paired with the Memory Tool, Claude gets prescient warnings before content is cleared:response = client.beta.messages.create( tools=[ {"type": "memory_20250818", "name": "memory"}, # your other tools ], context_management={ "edits": [{"type": "clear_tool_uses_20250919"}] })What happens: As Claude approaches the clearing threshold, it automatically gets a system warning: “Heads up, old tool results are about to be cleared.” Claude can then proactively save important information to its memory files before that context disappears.Imagine a file editing session where Claude:Makes 50 edits across multiple filesSees the context filling upSummarizes completed work to memoryContinues editing with a clean contextPulls previous summaries from memory when neededThis enables truly persistent workflows that can span days or weeks of intermittent work.2.1 Client-Side Magic: SDK CompactionSometimes you need more radical compression. Enter compaction — the SDK feature that replaces your entire conversation history with a smart summary:runner = client.beta.messages.tool_runner( model="claude-sonnet-4-5", messages=[your_long_conversation], compaction_control={ "enabled": True, "context_token_threshold": 100000, "model": "claude-haiku-4-5" # Cheaper model for summaries })What happens at 100,000 tokens:SDK injects a summary requestClaude generates a structured summary wrapped in tagsSDK replaces all message history with just that summaryConversation continues as if nothing happenedYour 100k-token conversation becomes a 2k-token summary, and Claude picks up right where it left off. It’s like checkpointing in video games.Practical Implementation Tips1. Start Simple# Minimum viable context managementcontext_management={ "edits": [ {"type": "clear_tool_uses_20250919"} ]}2. Monitor What Gets ClearedCheck the response metadata:print(response.context_management['applied_edits'])# Shows: cleared_tool_uses, cleared_input_tokens, cleared_thinking_turns3. Preview Before You SendUse the token counting endpoint to simulate:count = client.beta.messages.count_tokens( messages=your_messages, context_management=your_config)print(f"Will save {count.context_management['original_input_tokens'] - count.input_tokens} tokens")4. Avoid Cache ThrashingSet clear_at_least to meaningful values. Clearing 100 tokens isn’t worth breaking your prompt cache. Aim for 5,000+ tokens to make it worthwhile.When to Use Which Strategy?Here’s my decision framework:Use Server-Side Editing When:You have frequent tool usageYou need precise control over what’s clearedYou want to maintain prompt caching benefitsYour conversations have natural “chunking” (research sessions, file editing)Use Client-Side Compaction When:You’re building long-running autonomous agentsConversations span multiple sessions/daysYou need radical context reductionYou can tolerate summary-based continuityUse Memory + Context Editing When:Building persistent assistantsInformation needs to survive beyond context windowsYou want Claude to decide what’s importantThe Bottom LineContext editing transforms Claude from a “stateless chat API” into a persistent reasoning engine. We’re no longer constrained by 200k-token windows when we can intelligently manage what stays and what goes.The most exciting part? This is just the beta. As these features mature, we’ll see even more sophisticated context management — perhaps semantic compression, automatic importance scoring, or cross-session memory hierarchies.What are you building with long-context Claude? Share your use cases and challenges in the comments — I’d love to hear how you’re pushing these boundaries.Management with Anthropic Claude: A Guide to Smarter, Longer Conversations was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.