When to compact
- The session has been running long enough that responses are getting slower or hitting context limits.
- You want to preserve the thread’s history in place instead of starting a new session.
- You’re finished with an early phase of work (exploration, scaffolding) and want the summary to anchor the next phase.
Compact a session
- Open the session.
- In the session header, select Compact.
- Pick the model that should generate the summary. The session’s current model is selected by default.
- Select Compact to confirm.
Automatic compaction
Sessions can also be compacted automatically by the runtime when the context window fills up. Automatic compactions show up in the conversation the same way, labeled asCompacted automatically instead of attributed to a user.
API
You can trigger compaction programmatically:modelIdis required and must be a validproviderId/modelIdpair for a provider configured in your deployment. See Model providers for how models are registered.- Returns
204 No Contenton success. - Returns
400 Invalid model IDif the model isn’t recognized. - Returns
403 Forbiddenif you aren’t the session owner or an admin. - Returns
409while the session’s OpenCode runtime is still provisioning, and410if the session is archived or deleted.