# Codex context window: why you see 258K, and what the 1M setting gives you

> Markdown mirror of https://router.one/codex-context-window for AI assistants and crawlers. Router One is a unified, OpenAI-compatible LLM API gateway.
> Last updated: 2026-11-30

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-astra` and 500,000 for `gpt-6.2-sol` and `gpt-6.1-sol`, and says GPT-6.2 Astra and GPT-6.2 Sol support up to 1 million tokens via `model_context_window`. The two sources differ: `models.json` in rust-v0.172.0 caps `max_context_window` at 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 `/status` there can show other numbers; a provider that reads its key from `env_key`, such as Router One's, uses the bundled list.
- `gpt-6-luna` appears in Codex's bundled list, while Router One's 2026-11-30 catalog does not list `openai/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`

```toml
# ~/.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.rs` applies `min(model_context_window, max_context_window)` with no error, so `1000000` resolves to 872,000 (828,400 usable).
- Auto-compact ceiling and scope: under the default `model_auto_compact_token_limit_scope = "total"`, Codex uses `min(configured, window × 9 / 10)`. Setting `body_after_prefix` counts only growth after the carried prefix (`context_window.rs`), while `window × 95%` stays a hard cap regardless of scope. Optional `model_post_turn_compact_threshold_percent` (0–100; omit or `0` to disable) controls turn-end compaction separately.
- Profile overrides: since Codex 0.134.0, profiles live in `~/.codex/<profile-name>.config.toml` with top-level keys (not `[profiles.<name>]`) and run via `codex --profile <profile-name>`.
- Check the result with `/status` (`tui/src/status/card.rs`, rust-v0.172.0): send one short prompt first, then read the `Context window` line, `<percent>% left (<used> used / <window>)`. The last number is the usable window, rounded to whole thousands (258,400 shows as `258K`, 475,000 as `475K`, 828,400 as `828K`); the percentage leaves out a fixed 12,000 tokens. Before the first reply the line shows the raw config value (`1M` if you wrote `1000000`), 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_window` is `272,000`, setting `500000` or `1000000` still clamps to 272,000 (258,400 usable); smaller values such as `128000` do take effect.
- Single-prefix matching: `models-manager/src/manager.rs` runs longest-prefix matching first and then strips one leading `provider/` segment. `openai/gpt-6.2-sol` therefore resolves to the bundled `gpt-6.2-sol` entry (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), and `model_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's `ModelInfo` fields.

## 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 (Router One provider)`

```toml
# ~/.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/responses` to `https://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 `/compact` to summarize history, start a new thread, trim large tool outputs or images, and lower `model_auto_compact_token_limit` if 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.

## See also

- LLM context window comparison: https://router.one/llm-context-window
- Claude Code context window: https://router.one/claude-code-context-window
- Codex Responses API: https://router.one/codex-responses-api
- Codex CLI in China: https://router.one/codex-china
- Codex usage limit: https://router.one/codex-usage-limit
- Codex 401 and missing variable fix: https://router.one/codex-401-unauthorized
- Pricing methodology: https://router.one/pricing-methodology
- CLI setup guide: https://router.one/docs/guides/cli-setup
- OpenAI Codex models docs: https://learn.chatgpt.com/docs/models
- OpenAI Codex config reference: https://learn.chatgpt.com/docs/config-file/config-reference
- Canonical page: https://router.one/codex-context-window
- Models and per-model token rates: https://router.one/models (markdown: https://router.one/models.md)
- Pricing: https://router.one/pricing
- API docs (markdown): https://router.one/docs.md
- Company facts: https://router.one/facts/company.md
