compaction-threshold changedbuild-with-claude/compaction-threshold
Nearest release: v2.1.333, published 4 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+63added
Lines−0removed
From line
2,339
where the diff opens
First seen
21 Sep 2026
this site's first read of the page
Recorded edits30to this page, all time
### Message threads #### When a thread gets no summary
The whole hunk
from line 2339, old and new numbered
/
from line 2339
23392339
23402340When using server tools (such as web search), the compaction trigger is checked at the start of each sampling iteration. Compaction might occur multiple times within a single request depending on your trigger threshold and the amount of output generated.
23412341
2342### Message threads
2343
2344A [message thread](https://platform.claude.com/docs/en/build-with-claude/message-threads) accepts the `compact_20260112` edit in one form: `pause_after_compaction` set to `true` and no `instructions`. You can set `trigger`. This form is available on the Claude API, Claude Platform on AWS, and Claude in Microsoft Foundry. Any other form returns a 400 error.
2345
2346A thread is append-only, so you can’t replace its earlier turns with a summary. The API doesn’t store the response that contains the `compaction` block, so you can’t append that response and continue the thread. Instead, start a new thread from the summary. For create requests, continue requests, and replay, see [How message threads work](https://platform.claude.com/docs/en/build-with-claude/message-threads#how-message-threads-work).
2347
2348Follow these steps:
2349
23501. Send the edit and the beta headers `message-threads-2026-08-12` and `compact-2026-01-12` on every request of the thread, starting with the create request. They are fixed fields, so keep them the same, `trigger` included (see [What to send on each request](https://platform.claude.com/docs/en/build-with-claude/message-threads#what-to-send)). Below the trigger, the thread works as usual.
23512. Look for a `compaction` block in each response. When the input tokens reach the trigger, the API writes the summary and stops. The response contains a `compaction` block, and `stop_reason` is `"compaction"`. It might contain other blocks too, for example those of server tools. The API doesn’t store this response or the request’s messages, so a continue request from this response’s `id` returns a 404 error.
23523. Check the block’s `content`. If it is `null`, there is no summary. Stop here and see [When a thread gets no summary](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold#when-a-thread-gets-no-summary).
23534. Send a create request with `system`, `tools`, the edit (still with `pause_after_compaction` set to `true`), and the same beta headers. Make its first message an `assistant` message that contains only the `compaction` block. Leave out the other blocks of that response and every message from before the block. The summary covers the whole conversation, including the new messages of the request that reached the trigger, such as your `tool_result` blocks. You don’t need to send those messages again.
23545. Continue the new thread from its first response `id`. Your copy of the conversation now starts at the `assistant` message that contains the block: replay from there after a 404 error.
2355
2356The following example shows the body of the create request in step 4:
2357
2358```json
2359{
2360 "model": "claude-opus-5-5",
2361 "max_tokens": 1024,
2362 "cache_control": { "type": "ephemeral" },
2363 "system": "You are a support agent for Acme. Keep replies short.",
2364 "thread": { "type": "create" },
2365 "context_management": {
2366 "edits": [{ "type": "compact_20260112", "pause_after_compaction": true }]
2367 },
2368 "messages": [
2369 {
2370 "role": "assistant",
2371 "content": [
2372 {
2373 "type": "compaction",
2374 "content": "Summary of the conversation: the user asked about a late order. The agent confirmed that it shipped on Monday. The user then asked how long standard shipping usually takes."
2375 }
2376 ]
2377 }
2378 ]
2379}
2380```
2381
2382You can also keep recent turns word for word: add them as messages after that `assistant` message, and end with a `user` message. On the models named in [What to send on each request](https://platform.claude.com/docs/en/build-with-claude/message-threads#what-to-send), leave the `thinking` and `redacted_thinking` blocks out of the turns that you add.
2383
2384These limits apply:
2385
2386* Put the block in an `assistant` message, with no messages before it, and don’t end the request with an `assistant` message that contains anything besides the block. Otherwise, the API might serve the request but not store it, and the next continue request returns a 404 error.
2387* Don’t send the `task-budgets-2026-03-13` beta header for [task budgets](https://platform.claude.com/docs/en/build-with-claude/task-budgets) on a thread that uses this edit. With that header, the block might contain a value in `encrypted_content`, and the API serves but doesn’t store a create request with such a block. If you need task budgets, send the conversation without `thread`.
2388* Send the edit on every request that contains a `compaction` block. Without it, the request returns a 400 error.
2389* Use a model that supports threshold compaction. Claude Opus 4.5, Claude Sonnet 4.5, and Claude Haiku 4.5 don’t, and a request with the edit returns a 400 error on them. See [API support for threshold compaction](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold#availability-feature-support).
2390
2391#### When a thread gets no summary
2392
2393The API stops at the trigger even if it writes no summary. The block’s `content` is then `null`, and `stop_reason` is `"compaction"`, or `"refusal"` if safeguards blocked the summary. So look for the block, and don’t test `stop_reason` alone. The API stored nothing from the request that reached the trigger, so [After a refusal](https://platform.claude.com/docs/en/build-with-claude/message-threads#after-a-refusal) doesn’t apply.
2394
2395Don’t start a thread from a block whose `content` is `null`. The API ignores such a block and returns no error, so the new thread holds none of the conversation. With the `compact-2026-09-04` beta header, the request returns a 400 error instead.
2396
2397Do one of the following:
2398
2399* Send the same request again. For a continue request, keep the same `previous_message_id`. The API makes another summary call, which might fail again, for example when the request has `tools` (see [Current limitations](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold#current-limitations)). If `stop_reason` is `"refusal"`, the same request might be refused again, so prefer the other two options.
2400* Write your own summary (see [Compact a conversation](https://platform.claude.com/docs/en/build-with-claude/message-threads#compaction)).
2401* Send the full conversation without `thread`. That request accepts `instructions`.
2402
23422403### Token counting
23432404
23442405The token counting endpoint (`/v1/messages/count_tokens`) applies existing `compaction` blocks in your prompt but does not trigger new compactions. Use it to check your effective token count after previous compactions:
from line 3538
34773538 ```text wrap
34783539 Summarize the transcript inside <summary></summary> tags. Include relevant information in the summary for continuing the task in the next context window. Do not call any tools while writing this summary; respond with text only.
34793540 ```
3541
3542 A [message thread](https://platform.claude.com/docs/en/build-with-claude/message-threads) doesn’t accept `instructions`. For threads, see [When a thread gets no summary](https://platform.claude.com/docs/en/build-with-claude/compaction-threshold#when-a-thread-gets-no-summary).
34803543
34813544## Next steps
34823545
No line in this hunk matches that.