Follow Discord
Sweep 20 Nov 2026 · 19:55Z Build v2.1.330 547 read Stable v2.1.323 Latest v2.1.330 Next v2.1.330 Feeds RSS JSON llms.txt llms-full.txt Unofficial
One change · api

Log at info level changedagents-and-tools/tool-use/tool-runner

Nearest release: v2.1.324, published 2 hours after 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+10added
Lines−7removed
From line 43 where the diff opens
First seen 14 Aug 2026 this site's first read of the page
Recorded edits25to this page, all time

### Compacting long conversations ### Automatic context management

The whole hunk

from line 43, old and new numbered
/
lines
from line 43
4343* Manages conversation state
4444* Provides type safety and validation
4545 
46<Note>
47 The tool runner is in beta and available in the [Python SDK](https://github.com/anthropics/anthropic-sdk-python/blob/main/tools.md), [TypeScript SDK](https://github.com/anthropics/anthropic-sdk-typescript/blob/main/helpers.md#tool-helpers), [C# SDK](https://github.com/anthropics/anthropic-sdk-csharp/blob/main/examples/ToolRunnerExample/Program.cs), [Go SDK](https://github.com/anthropics/anthropic-sdk-go/blob/main/tools.md), [Java SDK](https://github.com/anthropics/anthropic-sdk-java/blob/main/anthropic-java-example/src/main/java/com/anthropic/example/BetaToolRunnerRunnableToolExample.java), [PHP SDK](https://github.com/anthropics/anthropic-sdk-php/blob/main/examples/beta/beta_tool_runner.php), and [Ruby SDK](https://github.com/anthropics/anthropic-sdk-ruby/blob/main/helpers.md#3-auto-looping-tool-runner-beta).
48</Note>
46The tool runner is available in the [Python SDK](https://github.com/anthropics/anthropic-sdk-python/blob/main/tools.md), [TypeScript SDK](https://github.com/anthropics/anthropic-sdk-typescript/blob/main/helpers.md#tool-helpers), [C# SDK](https://github.com/anthropics/anthropic-sdk-csharp/blob/main/examples/ToolRunnerExample/Program.cs), [Go SDK](https://github.com/anthropics/anthropic-sdk-go/blob/main/tools.md), [Java SDK](https://github.com/anthropics/anthropic-sdk-java/blob/main/anthropic-java-example/src/main/java/com/anthropic/example/BetaToolRunnerRunnableToolExample.java), [PHP SDK](https://github.com/anthropics/anthropic-sdk-php/blob/main/examples/beta/beta_tool_runner.php), and [Ruby SDK](https://github.com/anthropics/anthropic-sdk-ruby/blob/main/helpers.md#3-auto-looping-tool-runner-beta).
4947 
5048## Basic usage
5149 
from line 842
844842 
845843You take over by modifying the runner’s messages from inside the loop body. The exact method depends on the SDK. See the per-language tabs that follow.
846844 
847When you take over for an iteration, the runner does not append the assistant message or tool results from that turn. You become responsible for keeping the conversation valid: append the assistant message and a tool result yourself (if you want the turn to count), modify state conditionally so the loop can still exit when there are no tool calls, and pass `max_iterations` (csharp, php: `maxIterations`; java: `.maxIterations()`; go: `MaxIterations`) to bound the loop. The SDK supports `max_iterations` (csharp, php: `maxIterations`; java: `.maxIterations()`; go: `MaxIterations`) in all seven languages.
845When you take over for an iteration, the runner does not append the assistant message or tool results from that turn. You become responsible for keeping the conversation valid. Append the assistant message and a tool result yourself if you want the turn to count. Modify state only conditionally, so that the loop can still exit when there are no tool calls. To bound the loop, pass `max_iterations` (csharp, php: `maxIterations`; java: `.maxIterations()`; go: `MaxIterations`).
848846 
849847<Tabs exclude="shell">
850848 <Tab title="Python">
from line 1122
11241122 </Tab>
11251123</Tabs>
11261124 
1127### Automatic context management
1125### Compacting long conversations
11281126 
1129For long-running agentic tasks, the TypeScript and Ruby tool runners support automatic [compaction](https://platform.claude.com/docs/en/build-with-claude/context-editing#client-side-compaction-sdk), which generates summaries when token usage exceeds a threshold so the conversation can continue beyond context window limits. Both SDKs have deprecated this client-side option in favor of [server-side compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold), which works with every SDK’s tool runner through the `context_management` request parameter. The Python SDK (v1.0 and later) and the Go, Java, C#, and PHP tool runners don’t include client-side compaction. The tool runner has a `compact_before_next_turn()` (typescript, java, php: `compactBeforeNextTurn()`; csharp, go: `CompactBeforeNextTurn()`) helper for on-demand compaction. See [Compact in a loop](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand#compact-in-a-loop). Use it or a `context_management` compaction edit on a runner, not both.
1127The tool runner supports two kinds of compaction. [Choose how to compact](https://platform.claude.com/docs/en/build-with-claude/compaction#choose-how-to-compact) compares them.
1128 
1129* [Compaction at a token threshold](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold): when the conversation reaches a token threshold that you can set, the API summarizes it. The runner automatically sends the summary back on its later requests, so the task can continue beyond the context window. Add an entry of type [`compact_20260112`](https://platform.claude.com/docs/en/api/beta/messages#beta_compact_20260112_edit) to the `edits` array of the runner’s [`context_management`](https://platform.claude.com/docs/en/api/beta/messages/create#create.context_management) request parameter. Create the runner with the `compact-2026-01-12` beta, because the runner doesn’t add it.
1130* [Compaction on demand](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand): you choose when to compact. Call the runner’s `compact_before_next_turn()` (ruby: `compact_before_next_turn`; typescript, java, php: `compactBeforeNextTurn()`; csharp, go: `CompactBeforeNextTurn()`) helper, and the runner compacts before its next turn. [Compact in a loop](https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand#compact-in-a-loop) shows the call and names the beta header that it needs.
1131 
1132A runner can’t compact on demand while its `context_management` holds a `compact_20260112` entry, so use one kind on a runner.
11301133 
11311134### Debugging tool execution
11321135 
Feedback