What each harness does when the conversation outgrows the context window: when it compacts, what it keeps, and how you can steer it.
When it happens
| Question | Codex CLIchecked at 0.162.1 |
|---|---|
| Automatic compaction, and when | Yes. Before each turn, after each model step that needs a follow-up, and when you switch to a model with a smaller window, Codex compares the active context (the last reported input + output token count) to an auto-compact limit of 90% of the model's context window (or
0.166.0 keeps track of whether the last reported token count already included reasoning from earlier turns, and saves that with the thread. Resumed and forked threads no longer count that reasoning twice, which could trigger automatic compaction too early. Older saved threads without this information keep the previous estimate. 0.167.0 release fix, traced at 0.167.2: retained output from failed or usage-less responses remains in the token estimate until a usable server count covers it. History tracks the last usage-covered item boundary; total usage adds the estimated tail. Completion updates that boundary only when token_usage is present. This changes counting, not the configured compaction threshold; no runtime probe. |
| Change the trigger or turn it off | Partly Set
|
| Compact by hand | |
| See how full the context is | The TUI footer shows |
What it does
| Question | Codex CLIchecked at 0.162.1 |
|---|---|
| What replaces the conversation | With OpenAI (and Azure Responses) providers, Codex uses remote compaction: it sends the history plus a compaction trigger through the Responses API, and the server-side model returns one encrypted Custom providers can choose with With the |
| What survives | Partly Codex rebuilds the initial context after compaction: base and developer instructions, Images in retained messages may be dropped (only their text is kept) when the token budget is exceeded. |
| Trimming without summarising | Partly Yes, separately from compaction: each tool or function output is truncated when it is stored in history, to 10,000 tokens by default for bundled models. You can change this with |
| The full history afterwards | Yes. The session rollout under |
Shaping it
| Question | Codex CLIchecked at 0.162.1 |
|---|---|
| Customise the summary or hook in | Set |
| When a request overflows anyway | Partly If a normal request still overflows, the turn ends with "Codex ran out of room in the model's context window. Start a new thread or clear earlier history before retrying." Codex then marks the context as full, so the next turn compacts before sending, but it does not retry the failed request. If the compaction request itself overflows during local compaction, Codex drops the oldest history items one at a time and retries. Codex compacts and retries in the same turn only for Guardian auto-review sessions whose review budget is exhausted. 0.164.0 source: local compaction works on a cloned history and installs replacement history after a successful response; background take_ready drops a closed result channel instead of later awaiting it, returning no candidate to the foreground compaction path. Existing trigger/provider conditions remain independently audited; no runtime preservation probe. |