context-editing changedbuild-with-claude/context-editing
Nearest release: v2.1.239, published 2 hours before this site recorded the change. Shown because the two are within 24 hours of each other. Nothing here says the release caused the edit.
Recorded here
Lines+21added
Lines−88removed
From line
20
where the diff opens
First seen
14 Aug 2026
this site's first read of the page
Recorded edits19to this page, all time
The whole hunk
from line 20, old and new numbered
/
from line 20
2020* **Thinking block clearing** - For managing thinking blocks when using extended thinking, with options to preserve recent thinking for context continuity
2121* **Client-side SDK compaction** - An SDK-based alternative for summary-based context management (server-side compaction is generally preferred)
2222
23| Approach | Where it runs | Strategies | How it works |
24| --------------- | ------------- | ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
25| **Server-side** | API | Tool result clearing (`clear_tool_uses_20250919`) Thinking block clearing (`clear_thinking_20251015`) | Applied before the prompt reaches Claude. Clears specific content from conversation history. Each strategy can be configured independently. |
26| **Client-side** | SDK | Compaction | Available in [Python, TypeScript, and Ruby SDKs](https://platform.claude.com/docs/en/cli-sdks-libraries/overview) when using [`tool_runner`](https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-runner). Generates a summary and replaces full conversation history. See [Client-side compaction](https://platform.claude.com/docs/en/build-with-claude/context-editing#client-side-compaction-sdk). |
23| Approach | Where it runs | Strategies | How it works |
24| --------------- | ------------- | ----------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
25| **Server-side** | API | Tool result clearing (`clear_tool_uses_20250919`) Thinking block clearing (`clear_thinking_20251015`) | Applied before the prompt reaches Claude. Clears specific content from conversation history. Each strategy can be configured independently. |
26| **Client-side** | SDK | Compaction | Available in [TypeScript and Ruby SDKs](https://platform.claude.com/docs/en/cli-sdks-libraries/overview) when using [`tool_runner`](https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-runner). Generates a summary and replaces full conversation history. See [Client-side compaction](https://platform.claude.com/docs/en/build-with-claude/context-editing#client-side-compaction-sdk). |
2727
2828## Server-side strategies
2929
from line 2325
23252325<Warning>
23262326 **Anthropic recommends server-side compaction over SDK compaction.** [Server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction) handles context management automatically with less integration complexity, better token usage calculation, and no client-side limitations. Use SDK compaction only if you specifically need client-side control over the summarization process.
23272327
2328 The `compaction_control` parameter is deprecated in the Python, TypeScript, and Ruby SDKs and will be removed in a future version. The SDKs emit a deprecation warning when it is enabled. To use server-side compaction with a tool runner, pass the `compact_20260112` edit in the request's `context_management` parameter.
2328 The `compaction_control` parameter is deprecated in the TypeScript and Ruby SDKs and will be removed in a future version. The SDKs emit a deprecation warning when it is enabled. The Python SDK removed it in v1.0. To use server-side compaction with a tool runner, pass the `compact_20260112` edit in the request's `context_management` parameter.
23292329</Warning>
23302330
23312331<Note>
2332 Compaction is available in the [Python, TypeScript, and Ruby SDKs](https://platform.claude.com/docs/en/cli-sdks-libraries/overview) when using the [`tool_runner` method](https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-runner).
2332 Compaction is available in the [TypeScript and Ruby SDKs](https://platform.claude.com/docs/en/cli-sdks-libraries/overview) when using the [`tool_runner` method](https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-runner).
23332333</Note>
23342334
23352335Compaction is an SDK feature that automatically manages conversation context by generating summaries when token usage grows too large. Unlike server-side context editing strategies that clear content, compaction instructs Claude to summarize the conversation history, then replaces the full history with that summary. This allows Claude to continue working on long-running tasks that would otherwise exceed the [context window](https://platform.claude.com/docs/en/build-with-claude/context-windows).
from line 2361
23612361 </Tab>
23622362
23632363 <Tab title="Python">
2364 ```python Python
2365 client = anthropic.Anthropic()
2366
2367 runner = client.beta.messages.tool_runner(
2368 model="claude-opus-5",
2369 max_tokens=1024,
2370 tools=[read_file],
2371 messages=[{"role": "user", "content": "What's in config.json?"}],
2372 compaction_control={"enabled": True, "context_token_threshold": 100000},
2373 )
2374
2375 for message in runner:
2376 print(f"Tokens used: {message.usage.input_tokens}")
2377 ```
2364 <Note>
2365 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2366 </Note>
23782367 </Tab>
23792368
23802369 <Tab title="TypeScript">
from line 2493
25042493 </Tab>
25052494
25062495 <Tab title="Python">
2507 ```python Python
2508 client = anthropic.Anthropic()
2509
2510 runner = client.beta.messages.tool_runner(
2511 model="claude-opus-5",
2512 max_tokens=1024,
2513 tools=[read_file],
2514 messages=[{"role": "user", "content": "What's in config.json?"}],
2515 # Lower values compact more often; raise to 150000 when the task needs more context
2516 compaction_control={"enabled": True, "context_token_threshold": 50000},
2517 )
2518
2519 for message in runner:
2520 print(f"Tokens used: {message.usage.input_tokens}")
2521 ```
2496 <Note>
2497 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2498 </Note>
25222499 </Tab>
25232500
25242501 <Tab title="TypeScript">
from line 2579
26022579 </Tab>
26032580
26042581 <Tab title="Python">
2605 ```python Python
2606 client = anthropic.Anthropic()
2607
2608 runner = client.beta.messages.tool_runner(
2609 model="claude-opus-5",
2610 max_tokens=1024,
2611 tools=[read_file],
2612 messages=[{"role": "user", "content": "What's in config.json?"}],
2613 compaction_control={
2614 "enabled": True,
2615 "context_token_threshold": 100000,
2616 "model": "claude-haiku-4-5",
2617 },
2618 )
2619
2620 for message in runner:
2621 print(f"Tokens used: {message.usage.input_tokens}")
2622 ```
2582 <Note>
2583 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2584 </Note>
26232585 </Tab>
26242586
26252587 <Tab title="TypeScript">
from line 2671
27092671 </Tab>
27102672
27112673 <Tab title="Python">
2712 ```python Python
2713 client = anthropic.Anthropic()
2714
2715 runner = client.beta.messages.tool_runner(
2716 model="claude-opus-5",
2717 max_tokens=1024,
2718 tools=[read_file],
2719 messages=[{"role": "user", "content": "What's in config.json?"}],
2720 compaction_control={
2721 "enabled": True,
2722 "context_token_threshold": 100000,
2723 "summary_prompt": """Summarize the research conducted so far, including:
2724 - Sources consulted and key findings
2725 - Questions answered and remaining unknowns
2726 - Recommended next steps
2727
2728 Wrap your summary in <summary></summary> tags.""",
2729 },
2730 )
2731
2732 for message in runner:
2733 print(f"Tokens used: {message.usage.input_tokens}")
2734 ```
2674 <Note>
2675 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2676 </Note>
27352677 </Tab>
27362678
27372679 <Tab title="TypeScript">
from line 2856
29142856 </Tab>
29152857
29162858 <Tab title="Python">
2917 The Python SDK logs compaction events at the INFO level. Enable the `anthropic.lib.tools` logger:
2918
2919 ```python Python
2920 import logging
2921
2922 logging.basicConfig(level=logging.INFO)
2923 logging.getLogger("anthropic.lib.tools").setLevel(logging.INFO)
2924
2925 # Logs will show:
2926 # INFO: Token usage 105000 has exceeded the threshold of 100000. Performing compaction.
2927 # INFO: Compaction complete. New token usage: 2500
2928 ```
2859 <Note>
2860 In v1.0 and later, the Python SDK's tool runner does not support `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction) instead.
2861 </Note>
29292862 </Tab>
29302863
29312864 <Tab title="TypeScript">
No line in this hunk matches that.