Codex context window: sizes, /compact and auto-compaction
Codex's context window per model (500K GPT-6.2 Sol, 272K Astra), when it auto-compacts, /compact, model_context_window, and the ran-out-of-room error.
As of Codex 0.171.0 (November 2026), Codex gives GPT-6.2 Sol, GPT-6.1 Sol and GPT-6.1 Terra a 500,000-token context window, and GPT-6.2 Astra, GPT-6 Astra, GPT-6 Sol and GPT-6 Luna 272,000. Its source treats 95% of that as usable for input and compacts automatically when the conversation reaches 90% of the window (450,000 tokens on GPT-6.2 Sol, 244,800 on GPT-6.2 Astra), and /compact does it on demand. The footer shows NN% context left, and /status shows the tokens used against the window. Raise the window with model_context_window in ~/.codex/config.toml (Codex caps it at 872,000 for these models); lower the compaction point with model_auto_compact_token_limit. When a request still does not fit, Codex stops with “Codex ran out of room in the model’s context window.”
The window for each model
These are the values in the model catalogue bundled with Codex 0.171.0, and they match the “Default context in Codex” figures on OpenAI’s Codex models page where that page gives one. The usable and auto-compact columns are arithmetic from the source, explained below.
| Model | Window in Codex | Usable (95%) | Auto-compacts at (90%) | Most you can set |
|---|---|---|---|---|
gpt-6.2-sol (default) | 500,000 | 475,000 | 450,000 | 872,000 |
gpt-6.2-astra | 272,000 | 258,400 | 244,800 | 872,000 |
gpt-6.1-terra | 500,000 | 475,000 | 450,000 | 872,000 |
gpt-6.1-sol | 500,000 | 475,000 | 450,000 | 872,000 |
gpt-6-astra | 272,000 | 258,400 | 244,800 | 872,000 |
gpt-6-sol, gpt-6-luna | 272,000 | 258,400 | 244,800 | 872,000 |
A model Codex does not know | 272,000 | 258,400 | 244,800 | 272,000 |
The sources disagree on how far the window can go. OpenAI’s API pages give GPT-6.2 Sol and GPT-6.2 Astra a 1,050,000-token window and 128,000 output tokens, and the Codex models page, where it explains raising the window in Codex, says both “support a context window of up to 1 million tokens.” The 0.171.0 catalogue caps an override at 872,000, so in that version a larger model_context_window is cut to 872,000. A model name missing from the catalogue (a custom provider’s, say) logs Unknown model <name> is used. This will use fallback model metadata. and gets 272,000, with no room to raise it.
To see the catalogue your copy of Codex has, codex debug models prints it as JSON; each model’s context_window and max_context_window are in it, before any value from your config is applied. The listed models, and which plans get them, are in the Codex models guide.
What the CLI shows
The footer under the composer shows NN% context left. In the 0.171.0 source, the percentage leaves out a fixed 12,000 tokens Codex counts as always present (“prompts, tools and space to call compact”), and it is measured against the usable 95% of the window, not the full figure. By that arithmetic, on GPT-6.2 Sol the 450,000-token compaction point reads (475,000 − 450,000) ÷ (475,000 − 12,000), about 5% left, and on the 272,000-token models about 6%.
/status adds a Context window line in the form NN% left (X used / Y), Y being, in the source, the usable window, and, on an API key, a Token usage line with input and output totals; with a ChatGPT sign-in the token line is hidden. To keep a context figure in the footer next to other items, /statusline lets you pick and order them, including context stats, and saves the choice to tui.status_line.
When Codex compacts, and what it keeps
Compaction replaces the earlier turns with a summary written by the model, so the session can carry on. In the 0.171.0 source, Codex runs it in three places:
- Before sending a turn, if the conversation is already at the auto-compact limit (90% of the window) or at the usable window (95%).
- In the middle of a task, after a model response that needs another step, when the same limit is reached. A long agentic run therefore compacts without stopping.
- When you switch with
/modelto a model with a smaller window and the conversation is over the new model’s limit. The old model writes the summary before the new one takes over, so moving from GPT-6.2 Sol to GPT-6.2 Astra at 300,000 tokens compacts first.
/compact does it by hand: type it, confirm when Codex offers to summarize, and, in the words of OpenAI’s slash command reference, “Codex replaces earlier turns with a concise summary, freeing context while keeping critical details.” Compacting at a natural break, after a feature lands and before the next one, gives a better summary than one taken mid-edit.
When Codex compacts locally, the 0.171.0 source shows what the new history holds: the start-up context Codex builds for a session (your AGENTS.md instructions among it) put back in, your own messages up to 20,000 tokens, chosen from the newest back, and the summary, with some tool outputs Codex marks to retain. The rest of the earlier turns survives only as far as the summary describes it. If the summary request itself does not fit, Codex drops the oldest item in the history and tries again. Each compaction loses detail; instructions that must hold for the whole session belong in AGENTS.md, which comes back every time, not in an early message.
The settings in config.toml
All of these go in ~/.codex/config.toml, or a profile, or on the command line as -c key=value for one run, including a codex exec job. From the config reference and the 0.171.0 source:
model = "gpt-6.2-sol"
model_context_window = 800000 # raise or lower the window; capped at the model's maximum
model_auto_compact_token_limit = 300000 # compact earlier; above 90% of the window it has no effect
model_post_turn_compact_threshold_percent = 80 # also compact after a finished answer at 80% of the usable window
tool_output_token_limit = 10000 # how much of each tool output is kept in history
compact_prompt = "Keep the failing test names, file paths and the current plan."Copiedmodel_context_windowis “Context window tokens available to the active model.” In the 0.171.0 source, Codex takes the smaller of your value and the model’s maximum, and the auto-compact point moves with it, staying at 90%. The source applies it to every model you use under that config, whatever its name, so a value set for GPT-6.2 Sol also shrinks or grows GPT-6 Luna’s.model_auto_compact_token_limitis the “Token threshold that triggers automatic history compaction (unset uses model defaults).” In the source, Codex uses the lower of it and 90% of the window, so it can only bring compaction earlier.model_auto_compact_token_limit_scope = "body_after_prefix"counts, in the reference’s words, “only growth after the carried compaction-window prefix” instead of the full active context (total, the default).model_post_turn_compact_threshold_percentcompacts once a turn has finished, rather than in the middle of the next one. Unset or0turns it off, and “The usual auto-compaction limits still apply.”compact_promptreplaces the instructions Codex gives the model for writing the summary;experimental_compact_prompt_filereads them from a file. A replacement has to ask for everything the default would have kept.tool_output_token_limitis the “Token budget for storing individual tool/function outputs in history.” The current models’ catalogue default is 10,000 tokens per output.
The config reference lists no key that turns automatic compaction off. For scripts of your own around it, hooks have PreCompact and PostCompact events. How profiles, project files and -c stack is in the config.toml guide.
A bigger window is not free. On an API key, OpenAI’s GPT-6.2 pages say “For requests with more than 272K input tokens, input and cache rates double” and output costs 1.5 times as much for the whole request, which already applies to a GPT-6.2 Sol session past 272,000 tokens at the default 500,000. On a ChatGPT plan, the pricing page warns that “extended sessions that require the agent to hold more context will use significantly more per message,” with one exception: “GPT-6.1 Sol usage drawn from your subscription has no long-context surcharge in Codex or ChatGPT Work.”
At the limit: “Codex ran out of room”
When a request does not fit and compaction cannot make room, 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.CopiedIn reports on Codex’s issue tracker, the API’s own refusal underneath it reads “Your input exceeds the context window of this model. Please adjust your input and try again.” with the code context_length_exceeded. A search of the tracker for “ran out of room” returned dozens of reports on November 23, 2026, many of them still open. Two patterns recur in them: a session that reads nearly empty right after a compaction and still fails on the next message (#39310), and a long task where the error survives /compact and resuming the task (#52567, on GPT-6.1 Sol, where one reporter’s way out was a fresh thread with a handoff). OpenAI’s only reply there asks affected users to run /feedback.
What gets work moving again, in order:
- Run
/compactonce and retry. - If it fails again, ask Codex for nothing more in that thread. Start a new one with
/new(or/clear, which also clears the screen) and paste a short handoff: the goal, the files involved, what is done and what is next. If the old thread can still answer, have it write that handoff to a file before you leave it. - Reopening the same thread with
codex resumebrings back the same history, so expect it to fail the same way; resuming a Codex session is for threads that ended for other reasons.
Keeping a long session inside the window
- One task per thread.
/newbetween unrelated jobs costs nothing and starts the next one with the whole window. - Keep standing instructions in
AGENTS.md. It is put back after every compaction. Keep it short: it takes up context for the whole session, andproject_doc_max_bytescaps how much of it Codex reads. - Cut what fills the context by itself. OpenAI notes that “Every MCP server adds more context to your messages”; switch off the ones a project does not use. Large command output is the other usual filler: ask for the failing lines, not the whole log.
- Pick the window for the work. A refactor that has to hold many files at once suits GPT-6.2 Sol’s 500,000, or a raised
model_context_window; GPT-6.2 Astra’s 272,000 fills sooner on the same work. - For unattended
codex execruns, which compact mid-task like any session, have the job write its progress and plan to a file it can reread after a summary has dropped the detail, and a lowermodel_auto_compact_token_limitpassed with-cleaves more room between the compaction point and the hard limit.
Claude Code handles the same problem differently, with its own thresholds and settings; its version is in Claude Code’s /compact and auto-compact.