Codex context window: why you see 258K, and what the 1M setting gives you
Codex shows 258K because most bundled models default to 272,000 tokens and Codex reserves 5% headroom (272,000 × 95% = 258,400, shown as 258K in /status). In openai/codex rust-v0.172.0 (checked 2026-11-30), the bundled gpt-6.2-sol, gpt-6.1-sol and gpt-6.1-terra slugs default to 500,000 tokens (475,000 usable), while model_context_window = 1000000 is silently clamped to each entry's max_context_window of 872,000 — 828,400 usable (828K).
Context window by model in Codex (rust-v0.172.0)
Per codex-rs/models-manager/models.json and openai_models.rs in openai/codex rust-v0.172.0 (checked 2026-11-30), Codex computes usable context as window × 95% (5% reserved for system prompts, tool overhead and output) and default auto-compaction as window × 90%. Every bundled entry below sets max_context_window = 872,000:
| Model | Default | Usable (95%) | Auto-compact (90%) | Max override |
|---|---|---|---|---|
| gpt-6.2-sol | 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 | 272,000 | 258,400 | 244,800 | 872,000 |
| gpt-6-luna | 272,000 | 258,400 | 244,800 | 872,000 |
| gpt-5.6-sol | 272,000 | 258,400 | 244,800 | 872,000 |
| gpt-5.6-terra | 272,000 | 258,400 | 244,800 | 872,000 |
| gpt-5.6-luna | 272,000 | 258,400 | 244,800 | 872,000 |
- Exact arithmetic: 272,000 × 95% = 258,400 (
258K) and × 90% = 244,800; 500,000 × 95% = 475,000 (475K) and × 90% = 450,000; at the 872,000 ceiling, 872,000 × 95% = 828,400 (828K) and × 90% = 784,800. - OpenAI docs vs. client catalog: OpenAI's Codex models page (checked 2026-11-30) lists a default context of 272,000 tokens for
gpt-6.2-astraand 500,000 forgpt-6.2-solandgpt-6.1-sol, and says GPT-6.2 Astra and GPT-6.2 Sol support up to 1 million tokens viamodel_context_window. The two sources differ:models.jsonin rust-v0.172.0 capsmax_context_windowat 872,000 (828,400 usable). - These are the numbers bundled in rust-v0.172.0. A Codex signed in with ChatGPT refreshes its model list from OpenAI (
models-manager/src/manager.rs), so/statusthere can show other numbers; a provider that reads its key fromenv_key, such as Router One's, uses the bundled list. gpt-6-lunaappears in Codex's bundled list, while Router One's 2026-11-30 catalog does not listopenai/gpt-6-luna; verify live IDs on /models.
How to set model_context_window and verify in /status
Place model, model_context_window and model_auto_compact_token_limit at the top level of ~/.codex/config.toml (Windows: %USERPROFILE%\.codex\config.toml), above the first [table] header. Per Codex's config docs (checked 2026-11-30), trusted repos also load .codex/config.toml, and single runs take -c model_context_window=872000:
# ~/.codex/config.toml model = "gpt-6.2-astra" model_context_window = 872000 model_auto_compact_token_limit = 750000 model_auto_compact_token_limit_scope = "total"
- Silent clamping:
model_info.rsappliesmin(model_context_window, max_context_window)with no error, so1000000resolves to 872,000 (828,400 usable). - Auto-compact ceiling and scope: under the default
model_auto_compact_token_limit_scope = "total", Codex usesmin(configured, window × 9 / 10). Settingbody_after_prefixcounts only growth after the carried prefix (context_window.rs), whilewindow × 95%stays a hard cap regardless of scope. Optionalmodel_post_turn_compact_threshold_percent(0–100; omit or0to disable) controls turn-end compaction separately. - Profile overrides: since Codex 0.134.0, profiles live in
~/.codex/<profile-name>.config.tomlwith top-level keys (not[profiles.<name>]) and run viacodex --profile <profile-name>. - Check the result with
/status(tui/src/status/card.rs, rust-v0.172.0): send one short prompt first, then read theContext windowline,<percent>% left (<used> used / <window>). The last number is the usable window, rounded to whole thousands (258,400 shows as258K, 475,000 as475K, 828,400 as828K); the percentage leaves out a fixed 12,000 tokens. Before the first reply the line shows the raw config value (1Mif you wrote1000000), or is missing if you did not set the key.
Third-party models (DeepSeek, Grok and custom slugs)
For a model slug absent from models.json, such as deepseek-v4.1-flash or grok-4.7 on a custom provider, model_info.rs (rust-v0.172.0, checked 2026-11-30) builds fallback metadata with context_window = 272,000, max_context_window = 272,000 and 95% usable headroom (258,400 / 258K). In the session Codex warns: Model metadata for <slug> not found. Defaulting to fallback metadata; this can degrade performance and cause issues.
- Lower only, never higher: because fallback
max_context_windowis272,000, setting500000or1000000still clamps to 272,000 (258,400 usable); smaller values such as128000do take effect. - Single-prefix matching:
models-manager/src/manager.rsruns longest-prefix matching first and then strips one leadingprovider/segment.openai/gpt-6.2-soltherefore resolves to the bundledgpt-6.2-solentry (500,000 default / 872,000 max), whereas DeepSeek and Grok slugs have no bundled match. - Custom catalog: Codex's config reference (checked 2026-11-30) documents two ways to describe a model Codex does not know:
model_catalog_json, a local JSON file loaded at startup (a profile file can override it), andmodel_providers.<id>.model_catalog_url, a Codex-format catalog your provider serves. The JSON file must hold at least one entry and replaces the bundled list (core/src/config/mod.rs,model-provider/src/provider.rs), so include every model you use and match your Codex version'sModelInfofields.
Long-context billing on Router One and the 272,000-token line
272,000 tokens is the default window in Codex for GPT-6.2 Astra, GPT-6 Astra, GPT-6 Sol and GPT-5.6, and it is also where Router One's long-context price line starts for GPT-6.x, GPT-5.6 Sol and GPT-5.6 Terra (2026-11-30 catalog; openai/gpt-5.6-luna has no such line). Before raising model_context_window, or running long sessions on models that default to 500,000 (GPT-6.2 Sol, GPT-6.1 Sol, GPT-6.1 Terra), note the rule: when a request's total input is strictly above 272,000 tokens, the whole request bills at that model's long-context line and draws 2 plan requests instead of 1 (GPT-6.x as of the 2026-11-30 catalog; GPT-6 Astra, GPT-5.6 Sol and GPT-5.6 Terra draw 4 above 512,000). A billed request uses plan quota when your plan covers that model and has quota left, and the wallet otherwise.
# ~/.codex/config.toml model = "gpt-6.2-sol" model_provider = "router" # Optional, and only above the first [table]: a 272K window # model_context_window = 272000 [model_providers.router] name = "router" base_url = "https://api.router.one/v1" env_key = "ROUTER_ONE_API_KEY" wire_api = "responses"
- Client-side window: when Codex sends
POST /v1/responsestohttps://api.router.one/v1, Router One does not set or shrink Codex's context window — Codex computes it locally. Full provider setup: https://router.one/codex-responses-api. - Check live model tiers, plan coverage and cross-family windows on /models, /pricing and https://router.one/llm-context-window.
- To lower the chance of crossing the 272K line on models that default to 500,000, set
model_context_window = 272000: auto-compaction then triggers at 244,800 tokens (90%). It is not a guarantee, because one large turn can still exceed 272,000.
Auto-compaction and context-window-exceeded errors
Codex compacts history automatically at 90% of the resolved window (244,800 at 272K, 450,000 at 500K, 784,800 at 872K), or earlier when model_auto_compact_token_limit is lower. If a normal model request still hits upstream context_length_exceeded, Codex stops the turn without retrying and prints (protocol/src/error.rs, rust-v0.172.0, checked 2026-11-30; during a compaction it drops the oldest history item and tries again instead): Codex ran out of room in the model's context window. Start a new thread or clear earlier history before retrying.
- Why it still happens: one oversized turn (huge logs, files or high-resolution images) can cross the server limit before compaction runs, or a custom catalog can advertise a larger window than the model accepts.
- How to recover: run
/compactto summarize history, start a new thread, trim large tool outputs or images, and lowermodel_auto_compact_token_limitif long outputs repeatedly overflow.
FAQ
Is Codex showing a 258K context window a bug?
No. Per openai/codex rust-v0.172.0 (checked 2026-11-30), models defaulting to 272,000 reserve 5% headroom (272,000 × 95% = 258,400), and /status shows that number as 258K.
How do I enable a 1M context window in Codex?
Put model_context_window = 1000000 (or 872000) at the top level of ~/.codex/config.toml, or in a profile file ~/.codex/<name>.config.toml launched with codex --profile <name>. OpenAI's models docs (checked 2026-11-30) state up to 1 million tokens for GPT-6.2 Astra and GPT-6.2 Sol, while rust-v0.172.0's models.json caps max_context_window at 872,000 (828,400 usable / 828K).
Why does Codex still show 828K or 258K after I set model_context_window = 1000000?
Codex silently clamps model_context_window to max_context_window and shows 95% usable in /status after the first turn (model_info.rs, rust-v0.172.0). The GPT entries in the table above clamp to 872,000 → 828K; unrecognized slugs (DeepSeek, Grok) clamp to 272,000 → 258K. Also confirm the key sits above the first [table] header.
Why does the Codex VS Code extension also show 258K?
OpenAI's Codex models docs (checked 2026-11-30) say the ChatGPT desktop app, Codex CLI and IDE extension use the same config.toml, so the settings on this page apply in the extension too, and a model with a 272,000-token window shows 258,400 (258K) there as well. Edit ~/.codex/config.toml, then start a new session or reload the editor window. If you share the file with the extension, the same docs advise picking a model every client offers, such as gpt-6.1-sol.
Why does DeepSeek or Grok only get 258K in Codex?
Because deepseek-v4.1-flash and grok-4.7 are not in Codex's bundled models.json, they get fallback metadata with context_window = 272,000 and max_context_window = 272,000 (258,400 usable). model_context_window cannot raise them above 272,000; a larger window needs a catalog entry, through model_catalog_json or the provider's model_catalog_url.
What should I do when Codex says it ran out of room in the context window?
Upstream rejected the turn with context_length_exceeded and Codex does not retry it (protocol/src/error.rs, rust-v0.172.0). Run /compact, start a fresh thread, keep huge logs or images out of one turn, and lower model_auto_compact_token_limit to compact earlier.
Can I turn off or adjust Codex auto-compaction?
You can adjust it, but rust-v0.172.0 has no config.toml switch that turns it off. Lower model_auto_compact_token_limit to compact earlier (under the default total scope, a value above 90% of the window has no effect), or set model_auto_compact_token_limit_scope = "body_after_prefix" to count only what was added after the carried prefix; 95% of the window stays a hard cap either way. Do not set the limit to 0: the threshold becomes 0 tokens, so Codex treats it as reached every time. Turn-end compaction is separate and stays off unless model_post_turn_compact_threshold_percent is above 0.
Does using a Router One API key change the Codex context window?
Router One does not set, shrink or override it: Codex computes the window on your machine. What can differ is the model list Codex reads. With ChatGPT sign-in it refreshes the list from OpenAI; with a provider that reads its key from env_key, as on this page, it uses the list bundled with your Codex version (models-manager/src/manager.rs, rust-v0.172.0), where both gpt-6.2-sol and openai/gpt-6.2-sol match gpt-6.2-sol. Billing is separate: see the 272,000-token rule above.