Make context compaction use a configurable model independent of the active session model
What variant of Codex are you using?
CLI
What feature would you like to see?
Please allow Codex CLI to configure the model used for context compaction independently from the active session model.
Context compaction is a different job from normal interactive coding or planning. The active session model is optimized for reasoning, tool use, code edits, and following the current task. Compaction is a background/system summarization task whose main requirement is to preserve task state faithfully and predictably across long sessions.
Because those jobs have different cost, latency, and quality tradeoffs, users should be able to choose a separate compaction model and reasoning effort.
For example:
model = "gpt-5.5"
model_reasoning_effort = "high"
[compaction]
model = "gpt-5.4-mini"
reasoning_effort = "low"
fallback = "session_model"
A minimal flat config would also work:
model = "gpt-5.5"
compaction_model = "gpt-5.4-mini"
compaction_reasoning_effort = "low"
Problem this solves
Long-running Codex sessions often compact multiple times. Each compaction affects all future turns, so the compaction path is part of the core reliability story for the CLI, not just an implementation detail.
Today, users who want a high-capability model for real work appear to also pay that same model/cost/latency profile for compaction. That is not always the best tradeoff:
- A strong main model may be unnecessarily expensive for summarization-only compaction.
- A slower or higher-reasoning main model can make compaction feel more disruptive.
- A model that is excellent for coding/tool use may not be the model a user trusts most for conservative state compression.
- Repeated compactions can amplify summary quality issues, so users need a way to tune this path separately.
- When compaction fails or degrades, session continuity suffers even if the main model is otherwise working well.
Expected behavior
If a compaction model is configured:
- Manual
/compactuses the configured compaction model. - Automatic compaction uses the configured compaction model.
- If
compaction.reasoning_effortis configured, it is applied only to compaction requests. - If the configured compaction model is unavailable, Codex falls back to the active session model and shows/logs a clear warning.
/status, debug logs, or trace output show which model and reasoning effort handled the most recent compaction.- If no compaction-specific config is set, Codex keeps the current behavior.
Why this matters
This gives users practical control over the main long-session tradeoffs:
- cost: use an expensive model for coding, a cheaper model for compaction
- latency: use a faster model for background summarization
- reliability: choose a model that behaves well for conservative state summaries
- debuggability: make compaction model selection visible instead of implicit
- workflow fit: match model selection to task phase, rather than forcing one model to do everything
This also aligns with adjacent requests for per-phase/per-role model selection in Codex.
Related issues and signal
This is a more explicit version of #13739, which was closed because it did not receive enough upvotes. I understand maintainers need a triage signal, but this particular feature can be under-voted even when it is valuable: many users only notice the need after they have spent hours in a long session and hit compaction cost, latency, failure, or quality problems.
Related context and model-selection issues:
- #4106 — control over auto-compaction parameters
- #5558 — separate model selection for Plan vs Execute modes
- #11795 — configure subagent model and
reasoning_effort - #16140 — model-aware context window and auto-compaction settings
- #18007 — asynchronous/background compaction
- #22335 — remote compaction failures and session continuity problems
- #14589 — compaction information loss across long coding sessions
These are not all the same request, but together they show that context compaction and per-phase model control are recurring workflow pain points.
Possible acceptance criteria
- Add documented config for compaction model selection.
- Add documented config for compaction reasoning effort, if supported by the selected model.
- Keep backwards-compatible default behavior when no compaction config is present.
- Add tests that verify compaction requests use the configured model instead of the active session model.
- Add fallback behavior and tests for unavailable compaction models.
- Surface the effective compaction model in
/statusor logs.
Additional information
This can be treated as an advanced/opt-in setting if maintainers are concerned about exposing too many knobs. Even an experimental config flag would be useful for users who run long-lived Codex sessions and need to tune compaction separately from the main model.
5 Comments
Strong feature request — the cost asymmetry between "primary reasoning model" and "summary-only compaction model" is real, and it gets worse on long sessions that compact several times.
A quick map of where this would land in the current code, in case it helps scope:
turn_context.model_info(e.g.codex-rs/core/src/compact_remote.rs::run_remote_compact_task_inner_implat thecompact_conversation_history(..., &turn_context.model_info, ...)callsite, and similarly incodex-rs/core/src/compact.rs::run_compact_task_inner_impl). Todayturn_contextis built once per turn from the session model, so there's no seam for a per-compaction model override.ConfigTomlincodex-rs/config/src/config_toml.rsalready carries acompact_prompt: Option<String>field for prompt overrides — adding a siblingcompact_model: Option<String>(pluscompact_reasoning_effort) is the obvious shape for the flat TOML you proposed, and mirrors the existing override pattern.turn_contextcould be cloned with.with_model(compact_model, &sess.services.models_manager)(which already exists for the model-downshift path atcodex-rs/core/src/session/turn.rs::maybe_run_previous_model_inline_compact). That gives a turn-scopedTurnContextwith the alternate model without touching the main session model.A few open design questions the team would probably want to settle before scoping:
fallback = "session_model"suggestion is nice but the current model resolver doesn't have a "model not available, fall back" path; it errors. So the fallback would need to be implemented at config-resolution time (validate compact model availability on startup) or at runtime in the compaction wrapper.compact_conversation_history(remote) sends the model slug to the compact endpoint; the endpoint may not accept arbitrary models. The inline path is more permissive. So model selection might need to also pick the implementation path (remote when supported, inline otherwise).CompactConversationRequestSettings { effort, summary, ... }for remote and throughPrompt.personalityfor inline. Both are derived fromturn_contextso thewith_modelclone above carries them naturally if config provides them.Not opening a PR for this — just leaving the code map in case it's useful as the team prioritizes.
Thanks, this code map is very helpful. The remote vs inline split and fallback behavior are good points; even an opt-in inline-only implementation would already be useful if remote compaction cannot support arbitrary models yet.
Agreed — inline-only opt-in is probably the lowest-risk first cut. The seam is already there in practice:
run_inline_auto_compact_task→run_compact_task_inner→run_compact_task_inner_implall thread aTurnContextthat could be cloned via the existingwith_model(...)helper (used today for the model-downshift path). So a singlecompact_model: Option<String>inConfigToml, resolved at compact-time and swapped in before that callsite, would cover the bulk of the requested behavior without touching the remote path or the model resolver itself.I ran into the same class of problem from a latency/reliability angle: I want normal turns to keep their usual quality profile, but compaction to use a faster/lower-reasoning path.
I prepared a narrower implementation that does not yet add a separate compaction model, but does add compaction-specific
reasoning_effortandservice_tier:Branch:
https://github.com/Cccceb/codex/tree/compact-specific-reasoning-service-tier
Commit:
https://github.com/Cccceb/codex/commit/64b6b1e00ad40558c9e4d78c4a6d17b4d01f3b7a
Summary:
compact_service_tierandcompact_model_reasoning_effortconfig fieldscompact_service_tier = "fast"through the same fast-mode service-tier normalization path as regularservice_tierTesting:
cargo fmt --checkenv CARGO_HOME=/private/tmp/codex-cargo-home cargo test -p codex-core config_toml_compact_env CARGO_HOME=/private/tmp/codex-cargo-home cargo test -p codex-core remote_manual_compact_uses_compact_specific_service_tier_and_reasoning_effortI tried opening this as a PR, but PR creation is restricted to collaborators on this repo. Happy to adjust the branch if maintainers think this narrower config surface is a useful first step toward the broader compaction-model proposal.
Concrete economic evidence: compaction should not automatically inherit the premium session route
I have now encountered this as part of a wider investigation into Codex request-pipeline economics.
One analysed GPT-5.6 Sol / High / Standard session contained:
The session was doing load-bearing architecture/specification work, so selecting Sol was deliberate.
What was not deliberate was making that choice implicitly apply to mechanically different pipeline phases such as context compaction.
Cost asymmetry is now substantial
At the current Codex rate card:
Therefore, for the same token mix:
This means a Luna compaction request can theoretically cost about 96% less than the same request routed through Sol, before considering a lower reasoning effort.
Obviously summary fidelity matters. I am not suggesting blindly replacing all compaction with the cheapest model.
I suggest treating compaction as a small governed pipeline:
The premium model becomes a fallback for difficult compression rather than the default merely because it was selected for the surrounding coding task.
Suggested configuration
I would explicitly not default compaction to Fast mode. Compaction is normally throughput-insensitive and input-heavy, while Fast mode increases GPT-5.6 credit consumption.
Telemetry
Whichever implementation is chosen, I strongly suggest exposing:
That matters because users currently see the cost of compaction only indirectly as part of overall session consumption.
Broader architectural lesson
The issue is not simply “let users choose a cheaper summariser”.
Codex currently tends to associate a model with a session or turn. Economically, model selection needs to occur at the work-phase boundary.
The user should be able to reserve Sol for the part of the workflow where Sol-level reasoning creates value without necessarily purchasing Sol-level reasoning for evidence preparation, waiting, deterministic validation and context maintenance.
The existing opt-in proposal in this issue would be an excellent first step and can remain fully backwards compatible.