The two sides of this change are more than 400 edits apart, too far apart to line up, so this is the differ's own diff of it and the words inside a line are not marked.
from line 14
1414 For most use cases, [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction) is the primary strategy for managing context in long-running conversations. The strategies on this page are useful for specific scenarios where you need more fine-grained control over what content is cleared.
1515</Note>
1616
17Context editing allows you to selectively clear specific content from conversation history as it grows. Beyond optimizing costs and staying within limits, this is about actively curating what Claude sees: context is a finite resource with diminishing returns, and irrelevant content degrades model focus. Context editing gives you fine-grained runtime control over that curation. For the broader principles behind context management, see [Effective context engineering](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents). This page covers:
18
19* **Tool result clearing** - Best for agentic workflows with heavy tool use where old tool results are no longer needed
20* **Thinking block clearing** - For managing thinking blocks from earlier turns, with options to preserve recent thinking for context continuity
21* **Client-side SDK compaction** - An SDK-based alternative for summary-based context management (server-side compaction is generally preferred)
17Context editing allows you to selectively clear specific content from conversation history as it grows. Beyond optimizing costs and staying within limits, this is about actively curating what Claude receives: context is a finite resource with diminishing returns, and irrelevant content degrades model focus. Context editing gives you fine-grained runtime control over that curation. For the broader principles behind context management, see [Effective context engineering](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents). This page covers:
18
19* **Tool result clearing:** Best for agentic workflows with heavy tool use where old tool results are no longer needed
20* **Thinking block clearing:** For managing thinking blocks from earlier turns, with options to preserve recent thinking for context continuity
21* **Client-side SDK compaction:** An SDK-based alternative for summary-based context management (server-side compaction is generally preferred)
2222
2323| Approach | Where it runs | Strategies | How it works |
2424| --------------- | ------------- | ---------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
from line 35
3535
3636### Tool result clearing
3737
38The `clear_tool_uses_20250919` strategy clears tool results when conversation context grows beyond your configured threshold. This is particularly useful for agentic workflows with heavy tool use. Older tool results (like file contents or search results) are no longer needed once Claude has processed them.
38The `clear_tool_uses_20250919` strategy clears tool results when conversation context grows beyond your configured threshold. This is particularly useful for agentic workflows with heavy tool use. Older tool results (such as file contents or search results) are no longer needed once Claude has processed them.
3939
4040When activated, the API automatically clears the oldest tool results in chronological order. The API replaces each cleared result with placeholder text indicating to Claude that it was removed. By default, only tool results are cleared. You can optionally clear both tool results and tool calls (the tool use parameters) by setting `clear_tool_inputs` to true.
4141
from line 56
5656 Use this strategy to override the default. If your code runs across multiple model tiers, set `keep` explicitly rather than relying on the per-model default.
5757</Tip>
5858
59An assistant conversation turn may include multiple content blocks (for example, when using tools) and multiple thinking blocks (for example, with [interleaved thinking](https://platform.claude.com/docs/en/build-with-claude/thinking#interleaved-thinking)).
60
61### Context editing happens server-side
59An assistant conversation turn might include multiple content blocks (for example, when using tools) and multiple thinking blocks (for example, with [interleaved thinking](https://platform.claude.com/docs/en/build-with-claude/thinking#interleaved-thinking)).
60
61### Context editing occurs server-side
6262
6363Context editing is applied server-side before the prompt reaches Claude. Your client application maintains the full, unmodified conversation history. You do not need to sync your client state with the edited version. Continue managing your full conversation history locally as you normally would.
6464
from line 70
7070
7171* **Tool result clearing:** Invalidates cached prompt prefixes when content is cleared. To account for this, clear enough tokens to make the cache invalidation worthwhile. Use the `clear_at_least` parameter to ensure a minimum number of tokens is cleared each time. You'll incur cache write costs each time content is cleared, but subsequent requests can reuse the newly cached prefix.
7272
73* **Thinking block clearing:** When thinking blocks are **kept** in context (not cleared), the prompt cache is preserved, enabling cache hits and reducing input token costs. When thinking blocks are **cleared**, the cache is invalidated at the point where clearing occurs. Configure the `keep` parameter based on whether you want to prioritize cache performance or context window availability.
73* **Thinking block clearing:** When thinking blocks are **kept** in context (not cleared), the prompt cache is preserved, allowing cache hits and reducing input token costs. When thinking blocks are **cleared**, the cache is invalidated at the point where clearing occurs. Configure the `keep` parameter based on whether you want to prioritize cache performance or context window availability.
7474
7575## Supported models
7676
from line 83
8383<CodeGroup>
8484 ```bash cURL
8585 curl https://api.anthropic.com/v1/messages \
86 --header "x-api-key: $ANTHROPIC_API_KEY" \
87 --header "anthropic-version: 2023-06-01" \
88 --header "content-type: application/json" \
89 --header "anthropic-beta: context-management-2025-06-27" \
90 --data '{
91 "model": "claude-opus-5-5",
92 "max_tokens": 4096,
93 "messages": [
94 {
95 "role": "user",
96 "content": "Search for recent developments in AI"
97 }
98 ],
99 "tools": [
100 {
101 "type": "web_search_20250305",
102 "name": "web_search"
103 }
104 ],
105 "context_management": {
106 "edits": [
107 {"type": "clear_tool_uses_20250919"}
108 ]
109 }
110 }'
86 -H "x-api-key: $ANTHROPIC_API_KEY" \
87 -H "anthropic-version: 2023-06-01" \
88 -H "content-type: application/json" \
89 -H "anthropic-beta: context-management-2025-06-27" \
90 -d '{
91 "model": "claude-opus-5-5",
92 "max_tokens": 4096,
93 "messages": [
94 {
95 "role": "user",
96 "content": "Search for recent developments in AI"
97 }
98 ],
99 "tools": [
100 {
101 "type": "web_search_20250305",
102 "name": "web_search"
103 }
104 ],
105 "context_management": {
106 "edits": [
107 {"type": "clear_tool_uses_20250919"}
108 ]
109 }
110 }'
111111 ```
112112
113113 ```bash CLI
from line 296
296296<CodeGroup>
297297 ```bash cURL
298298 curl https://api.anthropic.com/v1/messages \
299 --header "x-api-key: $ANTHROPIC_API_KEY" \
300 --header "anthropic-version: 2023-06-01" \
301 --header "content-type: application/json" \
302 --header "anthropic-beta: context-management-2025-06-27" \
303 --data '{
304 "model": "claude-opus-5-5",
305 "max_tokens": 4096,
306 "messages": [
307 {
308 "role": "user",
309 "content": "Create a simple command line calculator app using Python"
310 }
311 ],
312 "tools": [
313 {
314 "type": "text_editor_20250728",
315 "name": "str_replace_based_edit_tool",
316 "max_characters": 10000
317 },
318 {
319 "type": "web_search_20250305",
320 "name": "web_search",
321 "max_uses": 3
322 }
323 ],
324 "context_management": {
325 "edits": [
326 {
327 "type": "clear_tool_uses_20250919",
328 "trigger": {
329 "type": "input_tokens",
330 "value": 30000
331 },
332 "keep": {
333 "type": "tool_uses",
334 "value": 3
335 },
336 "clear_at_least": {
337 "type": "input_tokens",
338 "value": 5000
339 },
340 "exclude_tools": ["web_search"]
341 }
342 ]
299 -H "x-api-key: $ANTHROPIC_API_KEY" \
300 -H "anthropic-version: 2023-06-01" \
301 -H "content-type: application/json" \
302 -H "anthropic-beta: context-management-2025-06-27" \
303 -d '{
304 "model": "claude-opus-5-5",
305 "max_tokens": 4096,
306 "messages": [
307 {
308 "role": "user",
309 "content": "Create a simple command line calculator app using Python"
310 }
311 ],
312 "tools": [
313 {
314 "type": "text_editor_20250728",
315 "name": "str_replace_based_edit_tool",
316 "max_characters": 10000
317 },
318 {
319 "type": "web_search_20250305",
320 "name": "web_search",
321 "max_uses": 3
322 }
323 ],
324 "context_management": {
325 "edits": [
326 {
327 "type": "clear_tool_uses_20250919",
328 "trigger": {
329 "type": "input_tokens",
330 "value": 30000
331 },
332 "keep": {
333 "type": "tool_uses",
334 "value": 3
335 },
336 "clear_at_least": {
337 "type": "input_tokens",
338 "value": 5000
339 },
340 "exclude_tools": ["web_search"]
343341 }
344 }'
342 ]
343 }
344 }'
345345 ```
346346
347347 ```bash CLI
from line 699
699699<CodeGroup>
700700 ```bash cURL
701701 curl https://api.anthropic.com/v1/messages \
702 --header "x-api-key: $ANTHROPIC_API_KEY" \
703 --header "anthropic-version: 2023-06-01" \
704 --header "content-type: application/json" \
705 --header "anthropic-beta: context-management-2025-06-27" \
706 --data '{
707 "model": "claude-opus-5-5",
708 "max_tokens": 16000,
709 "messages": [{"role": "user", "content": "Hello"}],
710 "context_management": {
711 "edits": [
712 {
713 "type": "clear_thinking_20251015",
714 "keep": {
715 "type": "thinking_turns",
716 "value": 2
717 }
718 }
719 ]
702 -H "x-api-key: $ANTHROPIC_API_KEY" \
703 -H "anthropic-version: 2023-06-01" \
704 -H "content-type: application/json" \
705 -H "anthropic-beta: context-management-2025-06-27" \
706 -d '{
707 "model": "claude-opus-5-5",
708 "max_tokens": 16000,
709 "messages": [{"role": "user", "content": "Hello"}],
710 "context_management": {
711 "edits": [
712 {
713 "type": "clear_thinking_20251015",
714 "keep": {
715 "type": "thinking_turns",
716 "value": 2
717 }
720718 }
721 }'
719 ]
720 }
721 }'
722722 ```
723723
724724 ```bash CLI
from line 928
928928<CodeGroup>
929929 ```bash cURL
930930 curl https://api.anthropic.com/v1/messages \
931 --header "x-api-key: $ANTHROPIC_API_KEY" \
932 --header "anthropic-version: 2023-06-01" \
933 --header "content-type: application/json" \
934 --header "anthropic-beta: context-management-2025-06-27" \
935 --data '{
936 "model": "claude-opus-5-5",
937 "max_tokens": 16000,
938 "messages": [{"role": "user", "content": "Hello"}],
939 "context_management": {
940 "edits": [
941 {
942 "type": "clear_thinking_20251015",
943 "keep": {
944 "type": "thinking_turns",
945 "value": 3
946 }
947 }
948 ]
931 -H "x-api-key: $ANTHROPIC_API_KEY" \
932 -H "anthropic-version: 2023-06-01" \
933 -H "content-type: application/json" \
934 -H "anthropic-beta: context-management-2025-06-27" \
935 -d '{
936 "model": "claude-opus-5-5",
937 "max_tokens": 16000,
938 "messages": [{"role": "user", "content": "Hello"}],
939 "context_management": {
940 "edits": [
941 {
942 "type": "clear_thinking_20251015",
943 "keep": {
944 "type": "thinking_turns",
945 "value": 3
946 }
949947 }
950 }'
948 ]
949 }
950 }'
951951 ```
952952
953953 ```bash CLI
from line 1140
11401140<CodeGroup>
11411141 ```bash cURL
11421142 curl https://api.anthropic.com/v1/messages \
1143 --header "x-api-key: $ANTHROPIC_API_KEY" \
1144 --header "anthropic-version: 2023-06-01" \
1145 --header "content-type: application/json" \
1146 --header "anthropic-beta: context-management-2025-06-27" \
1147 --data '{
1148 "model": "claude-opus-5-5",
1149 "max_tokens": 16000,
1150 "messages": [{"role": "user", "content": "Hello"}],
1151 "context_management": {
1152 "edits": [
1153 {
1154 "type": "clear_thinking_20251015",
1155 "keep": "all"
1156 }
1157 ]
1143 -H "x-api-key: $ANTHROPIC_API_KEY" \
1144 -H "anthropic-version: 2023-06-01" \
1145 -H "content-type: application/json" \
1146 -H "anthropic-beta: context-management-2025-06-27" \
1147 -d '{
1148 "model": "claude-opus-5-5",
1149 "max_tokens": 16000,
1150 "messages": [{"role": "user", "content": "Hello"}],
1151 "context_management": {
1152 "edits": [
1153 {
1154 "type": "clear_thinking_20251015",
1155 "keep": "all"
11581156 }
1159 }'
1157 ]
1158 }
1159 }'
11601160 ```
11611161
11621162 ```bash CLI
from line 1340
13401340<CodeGroup>
13411341 ```bash cURL
13421342 curl https://api.anthropic.com/v1/messages \
1343 --header "x-api-key: $ANTHROPIC_API_KEY" \
1344 --header "anthropic-version: 2023-06-01" \
1345 --header "content-type: application/json" \
1346 --header "anthropic-beta: context-management-2025-06-27" \
1347 --data '{
1348 "model": "claude-opus-5-5",
1349 "max_tokens": 16000,
1350 "messages": [
1351 {
1352 "role": "user",
1353 "content": "Search for the latest developments in quantum error correction and summarize the key breakthroughs."
1354 }
1355 ],
1356 "tools": [
1357 {
1358 "type": "web_search_20250305",
1359 "name": "web_search",
1360 "max_uses": 5
1361 }
1362 ],
1363 "context_management": {
1364 "edits": [
1365 {
1366 "type": "clear_thinking_20251015",
1367 "keep": {
1368 "type": "thinking_turns",
1369 "value": 2
1370 }
1371 },
1372 {
1373 "type": "clear_tool_uses_20250919",
1374 "trigger": {
1375 "type": "input_tokens",
1376 "value": 50000
1377 },
1378 "keep": {
1379 "type": "tool_uses",
1380 "value": 5
1381 }
1382 }
1383 ]
1343 -H "x-api-key: $ANTHROPIC_API_KEY" \
1344 -H "anthropic-version: 2023-06-01" \
1345 -H "content-type: application/json" \
1346 -H "anthropic-beta: context-management-2025-06-27" \
1347 -d '{
1348 "model": "claude-opus-5-5",
1349 "max_tokens": 16000,
1350 "messages": [
1351 {
1352 "role": "user",
1353 "content": "Search for the latest developments in quantum error correction and summarize the key breakthroughs."
1354 }
1355 ],
1356 "tools": [
1357 {
1358 "type": "web_search_20250305",
1359 "name": "web_search",
1360 "max_uses": 5
1361 }
1362 ],
1363 "context_management": {
1364 "edits": [
1365 {
1366 "type": "clear_thinking_20251015",
1367 "keep": {
1368 "type": "thinking_turns",
1369 "value": 2
1370 }
1371 },
1372 {
1373 "type": "clear_tool_uses_20250919",
1374 "trigger": {
1375 "type": "input_tokens",
1376 "value": 50000
1377 },
1378 "keep": {
1379 "type": "tool_uses",
1380 "value": 5
1381 }
13841382 }
1385 }'
1383 ]
1384 }
1385 }'
13861386 ```
13871387
13881388 ```bash CLI
from line 1413
14131413 ```
14141414
14151415 ```python Python
1416 client = anthropic.Anthropic()
1417
14161418 response = client.beta.messages.create(
14171419 model="claude-opus-5-5",
14181420 max_tokens=16000,
from line 1725
17231725
17241726| Configuration option | Default | Description |
17251727| -------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
1726| `trigger` | 100,000 input tokens | Defines when the context editing strategy activates. Once the prompt exceeds this threshold, clearing begins. You can specify this value in either `input_tokens` or `tool_uses`. |
1728| `trigger` | 100,000 input tokens | Defines when the context editing strategy activates. Once the prompt exceeds this threshold, clearing starts. You can specify this value in either `input_tokens` or `tool_uses`. |
17271729| `keep` | 3 tool uses | Defines how many recent tool use/result pairs to keep after clearing occurs. The API removes the oldest tool interactions first, preserving the most recent ones. |
17281730| `clear_at_least` | None | Ensures a minimum number of tokens is cleared each time the strategy activates. If the API can't clear at least the specified amount, the strategy will not be applied. This helps determine if context clearing is worth breaking your prompt cache. |
17291731| `exclude_tools` | None | List of tool names whose tool uses and results should never be cleared. Useful for preserving important context. |
from line 1792
17901792<CodeGroup>
17911793 ```bash cURL
17921794 curl https://api.anthropic.com/v1/messages/count_tokens \
1793 --header "x-api-key: $ANTHROPIC_API_KEY" \
1794 --header "anthropic-version: 2023-06-01" \
1795 --header "content-type: application/json" \
1796 --header "anthropic-beta: context-management-2025-06-27" \
1797 --data '{
1798 "model": "claude-opus-5-5",
1799 "messages": [
1800 {
1801 "role": "user",
1802 "content": "Continue our conversation..."
1803 }
1804 ],
1805 "context_management": {
1806 "edits": [
1807 {
1808 "type": "clear_tool_uses_20250919",
1809 "trigger": {
1810 "type": "input_tokens",
1811 "value": 30000
1812 },
1813 "keep": {
1814 "type": "tool_uses",
1815 "value": 5
1816 }
1817 }
1818 ]
1795 -H "x-api-key: $ANTHROPIC_API_KEY" \
1796 -H "anthropic-version: 2023-06-01" \
1797 -H "content-type: application/json" \
1798 -H "anthropic-beta: context-management-2025-06-27" \
1799 -d '{
1800 "model": "claude-opus-5-5",
1801 "messages": [
1802 {
1803 "role": "user",
1804 "content": "Continue our conversation..."
1805 }
1806 ],
1807 "context_management": {
1808 "edits": [
1809 {
1810 "type": "clear_tool_uses_20250919",
1811 "trigger": {
1812 "type": "input_tokens",
1813 "value": 30000
1814 },
1815 "keep": {
1816 "type": "tool_uses",
1817 "value": 5
1818 }
18191819 }
1820 }'
1820 ]
1821 }
1822 }'
18211823 ```
18221824
18231825 ```bash CLI
from line 2083
20812083
20822084## Using with the memory tool
20832085
2084Context editing can be combined with the [memory tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/memory-tool). When your conversation context approaches the configured clearing threshold, Claude receives an automatic warning to preserve important information. This enables Claude to save tool results or context to its memory files before they're cleared from the conversation history.
2086Context editing can be combined with the [memory tool](https://platform.claude.com/docs/en/agents-and-tools/tool-use/memory-tool). When your conversation context approaches the configured clearing threshold, Claude receives an automatic warning to preserve important information. This allows Claude to save tool results or context to its memory files before they're cleared from the conversation history.
20852087
20862088This combination allows you to:
20872089
2088* **Preserve important context:** Claude can write essential information from tool results to memory files before those results are cleared
2089* **Maintain long-running workflows:** Enable agentic workflows that would otherwise exceed context limits by offloading information to persistent storage
2090* **Access information on demand:** Claude can look up previously cleared information from memory files when needed, rather than keeping everything in the active context window
2090* **Preserve important context:** Claude can write essential information from tool results to memory files before those results are cleared.
2091* **Maintain long-running workflows:** Claude can continue agentic workflows that would otherwise exceed context limits by offloading information to persistent storage.
2092* **Access information on demand:** Claude can look up previously cleared information from memory files when needed, rather than keeping everything in the active context window.
20912093
20922094For example, in a file editing workflow where Claude performs many operations, Claude can summarize completed changes to memory files as the context grows. When tool results are cleared, Claude retains access to that information through its memory system and can continue working effectively.
20932095
from line 2098
20962098<CodeGroup>
20972099 ```bash cURL
20982100 curl https://api.anthropic.com/v1/messages \
2099 --header "x-api-key: $ANTHROPIC_API_KEY" \
2100 --header "anthropic-version: 2023-06-01" \
2101 --header "content-type: application/json" \
2102 --header "anthropic-beta: context-management-2025-06-27" \
2103 --data '{
2104 "model": "claude-opus-5-5",
2105 "max_tokens": 4096,
2106 "messages": [
2107 {
2108 "role": "user",
2109 "content": "Hello"
2110 }
2111 ],
2112 "tools": [
2113 {
2114 "type": "memory_20250818",
2115 "name": "memory"
2116 }
2117 ],
2118 "context_management": {
2119 "edits": [
2120 {"type": "clear_tool_uses_20250919"}
2121 ]
2122 }
2123 }'
2101 -H "x-api-key: $ANTHROPIC_API_KEY" \
2102 -H "anthropic-version: 2023-06-01" \
2103 -H "content-type: application/json" \
2104 -H "anthropic-beta: context-management-2025-06-27" \
2105 -d '{
2106 "model": "claude-opus-5-5",
2107 "max_tokens": 4096,
2108 "messages": [
2109 {
2110 "role": "user",
2111 "content": "Hello"
2112 }
2113 ],
2114 "tools": [
2115 {
2116 "type": "memory_20250818",
2117 "name": "memory"
2118 }
2119 ],
2120 "context_management": {
2121 "edits": [
2122 {"type": "clear_tool_uses_20250919"}
2123 ]
2124 }
2125 }'
21242126 ```
21252127
21262128 ```bash CLI
from line 2308
23062308<Warning>
23072309 **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.
23082310
2309 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.
2311 The `compaction_control` parameter is deprecated in the TypeScript and Ruby SDKs and will be removed in a future version. The TypeScript and Ruby 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.
23102312</Warning>
23112313
23122314<Note>
from line 2324
232223241. **Threshold check:** The SDK calculates total tokens as `input_tokens + cache_creation_input_tokens + cache_read_input_tokens + output_tokens` (see [Prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) for the cache token fields).
232323252. **Summary generation:** When the threshold is exceeded, a summary prompt is injected as a user turn, and Claude generates a structured summary wrapped in `<summary></summary>` tags.
232423263. **Context replacement:** The SDK extracts the summary and replaces the entire message history with it.
23254. **Continuation:** The conversation resumes from the summary, with Claude picking up where it left off.
23274. **Continuation:** The conversation resumes from the summary, with Claude continuing from where it stopped.
23262328
23272329### Using compaction
23282330
from line 2345
23432345
23442346 <Tab title="Python">
23452347 <Note>
2346 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-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2348 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
23472349 </Note>
23482350 </Tab>
23492351
from line 2369
23672369
23682370 <Tab title="C#">
23692371 <Note>
2370 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2372 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
23712373 </Note>
23722374 </Tab>
23732375
23742376 <Tab title="Go">
23752377 <Note>
2376 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2378 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
23772379 </Note>
23782380 </Tab>
23792381
23802382 <Tab title="Java">
23812383 <Note>
2382 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2384 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
23832385 </Note>
23842386 </Tab>
23852387
23862388 <Tab title="PHP">
23872389 <Note>
2388 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2390 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
23892391 </Note>
23902392 </Tab>
23912393
from line 2477
24752477
24762478 <Tab title="Python">
24772479 <Note>
2478 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-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2480 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
24792481 </Note>
24802482 </Tab>
24812483
from line 2502
25002502
25012503 <Tab title="C#">
25022504 <Note>
2503 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2505 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
25042506 </Note>
25052507 </Tab>
25062508
25072509 <Tab title="Go">
25082510 <Note>
2509 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2511 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
25102512 </Note>
25112513 </Tab>
25122514
25132515 <Tab title="Java">
25142516 <Note>
2515 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2517 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
25162518 </Note>
25172519 </Tab>
25182520
25192521 <Tab title="PHP">
25202522 <Note>
2521 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2523 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
25222524 </Note>
25232525 </Tab>
25242526
from line 2563
25612563
25622564 <Tab title="Python">
25632565 <Note>
2564 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-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2566 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
25652567 </Note>
25662568 </Tab>
25672569
from line 2591
25892591
25902592 <Tab title="C#">
25912593 <Note>
2592 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2594 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
25932595 </Note>
25942596 </Tab>
25952597
25962598 <Tab title="Go">
25972599 <Note>
2598 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2600 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
25992601 </Note>
26002602 </Tab>
26012603
26022604 <Tab title="Java">
26032605 <Note>
2604 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2606 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
26052607 </Note>
26062608 </Tab>
26072609
26082610 <Tab title="PHP">
26092611 <Note>
2610 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2612 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
26112613 </Note>
26122614 </Tab>
26132615
from line 2655
26532655
26542656 <Tab title="Python">
26552657 <Note>
2656 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-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2658 In v1.0 and later, the Python SDK's tool runner does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
26572659 </Note>
26582660 </Tab>
26592661
from line 2688
26862688
26872689 <Tab title="C#">
26882690 <Note>
2689 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2691 The C# SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
26902692 </Note>
26912693 </Tab>
26922694
26932695 <Tab title="Go">
26942696 <Note>
2695 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2697 The Go SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
26962698 </Note>
26972699 </Tab>
26982700
26992701 <Tab title="Java">
27002702 <Note>
2701 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2703 The Java SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
27022704 </Note>
27032705 </Tab>
27042706
27052707 <Tab title="PHP">
27062708 <Note>
2707 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
2709 The PHP SDK includes a tool runner, but it does not support client-side `compaction_control`. Use [server-side compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold) instead: it works with the tool runner by passing the `compact_20260112` edit in the request's `context_management` parameter.
27082710 </Note>
27092711 </Tab>
27102712
from line 2750
274827504. **Next Steps:** Specific actions needed, blockers, and priority order.
274927515. **Context to Preserve:** User preferences, domain-specific details, and commitments made.
27502752
2751This structure enables Claude to resume work efficiently without losing important context or repeating mistakes.
2753This structure allows Claude to resume work efficiently without losing important context or repeating mistakes.
27522754
27532755<Accordion title="View full default prompt">
27542756 ```text wrap
from line 2795
27932795 Compaction requires special consideration when using server-side tools such as [web search](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-search-tool) or [web fetch](https://platform.claude.com/docs/en/agents-and-tools/tool-use/web-fetch-tool).
27942796</Warning>
27952797
2796When using server-side tools, the SDK may incorrectly calculate token usage, causing compaction to trigger at the wrong time.
2798When using server-side tools, the SDK might incorrectly calculate token usage, causing compaction to trigger at the wrong time.
27972799
27982800For example, after a web search operation, the API response might show:
27992801
from line 2810
28082810}
28092811```
28102812
2811The SDK calculates total usage as 63,000 + 0 + 270,000 + 1,400 = 334,400 tokens. However, the `cache_read_input_tokens` value includes accumulated reads from multiple internal API calls made by the server-side tool, not your actual conversation context. Your real context length might only be the 63,000 `input_tokens`, but the SDK sees 334k and triggers compaction prematurely.
2813The SDK calculates total usage as 63,000 + 0 + 270,000 + 1,400 = 334,400 tokens. However, the `cache_read_input_tokens` value includes accumulated reads from multiple internal API calls made by the server-side tool, not your actual conversation context. Your real context length might only be the 63,000 `input_tokens`, but the SDK calculates 334k and triggers compaction prematurely.
28122814
28132815**Workarounds:**
28142816
2815* Use the [token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting) endpoint to get accurate context length
2816* Avoid compaction when using server-side tools extensively
2817* Use the [token counting](https://platform.claude.com/docs/en/build-with-claude/token-counting) endpoint to get accurate context length.
2818* Avoid compaction when using server-side tools extensively.
28172819
28182820#### Tool use edge cases
28192821
28202822