GuidesRunning & maintaining

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.

November 23, 2026The Everpod team
The short answer

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.

ModelWindow in CodexUsable (95%)Auto-compacts at (90%)Most you can set
gpt-6.2-sol (default)
500,000475,000450,000872,000
gpt-6.2-astra
272,000258,400244,800872,000
gpt-6.1-terra
500,000475,000450,000872,000
gpt-6.1-sol
500,000475,000450,000872,000
gpt-6-astra
272,000258,400244,800872,000
gpt-6-sol, gpt-6-luna
272,000258,400244,800872,000
A model Codex does not know
272,000258,400244,800272,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:

/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."
Copied

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.
Copied

In 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:

  1. Run /compact once and retry.
  2. 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.
  3. Reopening the same thread with codex resume brings 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

Claude Code handles the same problem differently, with its own thresholds and settings; its version is in Claude Code’s /compact and auto-compact.

Run Codex on an always-on developer pod.

A developer pod is a permanent cloud computer (VPS), set up and secured for you, with your pick of Claude Code, Codex, OpenCode, Pi, Hermes and OpenClaw installed. Run more agents at once than your laptop can hold, and keep them working when it’s closed. From $24 a month, built in about ten minutes.