Support asynchronous/background compaction in Codex CLI
Resolved 💬 3 comments Opened Apr 15, 2026 by sebthom Closed Jul 1, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor)
responded on this thread — see the highlighted reply below.
What variant of Codex are you using?
cli
What feature would you like to see?
Problem
In long Codex CLI sessions, compaction can interrupt the flow once the remaining context gets low. This is especially noticeable in fast-moving chats where the user wants to keep working instead of pausing for context management.
Proposal
Support asynchronous/background compaction that starts before the context window is nearly exhausted.
For example, when remaining context drops below a configurable threshold such as 15%, Codex CLI could:
- start compacting the current conversation state in the background
- allow the chat to continue while compaction is running
- switch to the compacted history once it is ready
Expected behavior
- Session is approaching context pressure.
- Codex CLI detects that remaining context is below a threshold.
- It starts compaction asynchronously on a snapshot of the current history.
- New turns continue to be added while compaction runs.
- Once compaction finishes, Codex CLI merges or replays the interim turns and atomically switches to the compacted state.
Why this helps
- avoids workflow interruptions in long sessions
- makes context management feel seamless
- improves UX for iterative or agentic workflows
- reduces the need to stop and wait at the worst possible moment
Implementation sketch
A possible approach:
- trigger compaction when remaining context falls below a threshold, for example 15%
- compact a snapshot of the conversation state
- keep a delta log of turns added while compaction is in progress
- once compaction completes, replay or merge the delta onto the compacted result
- atomically replace the active history with the updated compacted history
Open questions
- Should the threshold be configurable?
- Should this be opt-in, opt-out, or default behavior?
- How should the CLI surface compaction status?
- What is the fallback if context runs out before background compaction finishes?
- How should merge/replay conflicts be handled for deterministic behavior?
Potential acceptance criteria
- background compaction can start automatically before context exhaustion
- user can continue chatting while compaction is running
- interim turns are preserved correctly
- switch to compacted history happens without losing conversation state
- behavior is deterministic and debuggable
Example
If only 15% of context remains, Codex CLI starts compaction in the background instead of waiting until the session is nearly blocked. The user continues chatting normally. When compaction is ready, the CLI transparently switches to the compacted history.
Additional information
_No response_
3 Comments
Related: https://github.com/openai/codex/pull/17286
Question for clarification:
Is the current user-visible compaction pause considered an actual issue/limitation, or is it currently working as designed?
Also, has it been confirmed that compaction does not affect model performance, reasoning quality, task continuity, or instruction retention after the compacted history is applied?
I understand that compaction is intended to preserve the necessary conversation state while reducing context size, but from a user/workflow perspective it would be useful to know whether:
This would help clarify whether the proposed background compaction is only about avoiding pauses, or whether it also protects long-running agentic workflows from possible context-quality issues.
This feature request hasn't received enough upvotes, so it is being closed automatically. If you still feel this feature is needed, please open a new feature request with an updated title and description.