Make context window and auto-compaction settings model-aware
Open 💬 6 comments Opened Mar 28, 2026 by GraviyDev
💡 Likely answer: A maintainer (github-actions[bot], contributor)
responded on this thread — see the highlighted reply below.
What feature would you like to see?
Model-aware context window and auto-compaction settings.
Problem
Codex currently allows global configuration like:
model_context_window = 1000000
model_auto_compact_token_limit = 500000
This works for a large-context model such as gpt-5.4, but becomes misleading or unsafe when switching to a smaller-context model such as gpt-5.4-mini.
The user can end up in a state where:
- the UI still appears to reflect the large configured context window
- the selected model actually has a smaller context limit
- auto-compaction does not happen soon enough
- the session fails with a context window exceeded error
Proposal
Please make context handling explicitly model-aware.
Possible approaches:
- support per-model overrides in config
- automatically clamp
model_context_windowto the selected model's true maximum - automatically clamp
model_auto_compact_token_limitto a safe threshold under the selected model's limit - show both:
- configured context window
- effective context window for the currently selected model
- show a warning when the configured values exceed the selected model's actual supported window
Why this matters
This is especially important for users who intentionally use:
gpt-5.4with a very large configured context windowgpt-5.4-minifor cheaper or faster work in the same app
Right now the config model and the active UI-selected model can drift apart in a way that is hard to reason about.
Expected outcome
Switching models should never leave the user with stale or unsafe context settings.
The app should either:
- transparently adapt the effective limits, or
- explicitly tell the user that the current context settings are incompatible with the newly selected model.
6 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Related bug report: #16139
@GraviyDev Hey — I know this kind of issue too well. It is very close to the agent reliability problem I’m working on.
I’m building AgaveCore, and I’d like to let a few early people use it for free while I shape it into something stronger.
It helps when a coding agent starts to drift, loses important context, or gives you an output you do not fully trust.
In practice, it works through two habits:
remember-progressorremember-thiswhen something important should not be lostconsult-brainwhen the current task needs more grounded feedback on what to do nextOver time, as useful journals, decisions, and failures pile up, the product should help the agent make sharper decisions and take better actions with less drift.
If this sounds relevant, reply here and I’ll send the exact steps. You can also use the email or Telegram on my profile.
Cheers,
Mads.
I'm using local model, and I can only afford 64k context window.
I set model_context_window inside profile like this:
Then if I run /status, I get this:
│ Context window: 86% left (45.9K used / 258K) │
How can I set the context window for the profile properly?
Thanks!
Nevermind, I asked Codex to look codex repo, and it said model_context_window is top level config.
It worked if I set it on the top!
Additional deterministic evidence from macOS / Codex CLI 0.145.0 with
gpt-5.6-sol.Environment
0.145.0gpt-5.6-solhighmodel_catalog_jsonentry declared:context_window = 1048576max_context_window = 1048576effective_context_window_percent = 95996147.272000.Observed behavior
Four separate tool-heavy threads failed with
context_window_exceededafter the last successful request reached approximately:364559input tokens369007input tokens369869input tokens371440input tokensThe next request failed with:
The affected rollouts contained no
compactedorcontext_compactedevent before failure. The client was waiting for the locally advertised ~996K threshold while the request path rejected the conversation much earlier.This made the thread unrecoverable: even a short follow-up asking for a summary failed with the same error.
Workaround and compact smoke test
A safe local workaround was:
I also ran a deterministic compact smoke test using the same model and CLI, temporarily overriding the threshold to
32000:37128input tokens.compactedcontext_compactedThis confirms the compact machinery itself works when the threshold is below the real request boundary. The failure is the unsafe split between configured/catalog context metadata and the actual accepted context.
Suggested fix
context_windowto it.context_window_exceeded, perform one emergency compact-and-retry before making the thread unrecoverable./statusand diagnostics.model_catalog_jsonadvertises a window larger than the selected provider accepts.This appears to be a concrete GPT-5.6 instance of the model-aware context handling requested in this issue.