# Improve explicit compaction for Anthropic models \(\#62139\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/984bf4d466ed812b60371233158ad80e4c412faf)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 984bf4d466ed812b60371233158ad80e4c412faf

Requested commit: 984bf4d466ed812b60371233158ad80e4c412faf

Commit: 984bf4d466ed812b60371233158ad80e4c412faf

Tree: 533479635cb27f3858389f09d327d395aaf10e0a

Author: Eric Holk

Committer: GitHub

## Message

```
Improve explicit compaction for Anthropic models (#62139)

Explicit compaction (`LanguageModel::compact`) was previously
implemented only for OpenAI-routed cloud models, which use a dedicated
compact operation proxied through `/completions/compact`. Anthropic
models only compacted automatically when a request's `compact_at_tokens`
trigger was crossed, leaving consumers without a provider-backed way to
request compaction immediately.

Anthropic has no compact-on-demand operation, but the `compact_20260112`
context-management edit provides the necessary pieces: the lowest
trigger the API accepts, 50,000 input tokens, combined with
`pause_after_compaction`, which stops the response after the compaction
block. Explicit compaction requests remove tools so the internal
summarizer must produce replacement context while retaining Anthropic's
default summarization prompt. The resulting readable summary, optional
opaque provider state, and usage are collected consistently.

This implements explicit compaction for both direct and hosted Anthropic
models. Hosted requests use the normal `/completions` endpoint; gateway
support for forwarding the compaction fields landed in
zed-industries/cloud#3216. Models expose the 50,000-token minimum so
callers can disable explicit compaction below the provider's floor.
Calls made below that floor still fail if the stream produces no
finalized compaction context.

The existing OpenAI compact operation is moved into a provider-specific
helper without changing its request, endpoint, response handling, or
provider-state ownership.

Testing:

- `cargo nextest run -p anthropic -p language_models_cloud -p
language_models`
- `./script/clippy -p anthropic -p language_model -p
language_models_cloud -p language_models`
- `cargo fmt --all --check`
- `git diff --check`

Release Notes:

- N/A

---------

Co-authored-by: Anant Goel <anant@zed.dev>
```

## Parents

- [8968bf78084f30809aa2ce1574a3be68ed02a513](https://git.cafe/gitcafe/zed/commit/8968bf78084f30809aa2ce1574a3be68ed02a513?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/984bf4d466ed812b60371233158ad80e4c412faf?format=markdown)
