Optimize your agent

Return less

Clear old tool results

Long sessions keep every earlier tool result in context, and most of it is never read again. Context editing drops stale tool results as the conversation grows, and compaction summarises older turns. Both keep long runs inside the window without starting over.

Checked on the vendor's pages 30 Nov 2026

Where it fits

Building my own agent Fits

Context editing and compaction on the Claude API.

Using a coding agent Fits

/compact and automatic compaction.

Using an enterprise assistant Partly

Handled by the vendor.

Using a workflow tool Not available

Runs are short.

The setting in each harness

Read on each vendor's own page, linked next to the setting.

HarnessSetting
Claude API and Agent SDK
Beta

context_management with clear_tool_uses_20250919, or server-side compaction

platform.claude.com, read 30 Nov 2026
OpenAI Responses and Agents SDK

context_management: [{ type: "compaction", compact_threshold }] on Responses requests

developers.openai.com, read 30 Nov 2026
Pi

/compact, and the compaction settings for automatic compaction

github.com, read 30 Nov 2026
Claude Code
On by default

Auto-compaction summarises old turns; CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=50 makes it compact earlier

code.claude.com, read 30 Nov 2026
Codex
On by default

Automatic compaction at the model's default threshold; model_auto_compact_token_limit moves it

learn.chatgpt.com, read 30 Nov 2026
OpenCode

Compaction: { auto: true, keep: { tokens: 15000 } } in opencode.json

opencode.ai, read 30 Nov 2026