Unlocking Codex's Larger Context Window: 872K Tokens on GPT-5.6
GPT-5.6 can work with an 872,000-token context window, but Codex starts it at 272,000.
Codex doesn't ask the model how many tokens it can handle. It looks the answer up in a model catalog -- a JSON file (~/.codex/models_cache.json) listing every available model alongside its capabilities. Each entry carries two numbers: context_window, the default, and max_context_window, the most Codex will let you raise it to. For every GPT-5.6 and GPT-6 variant the catalog says 272,000 and 872,000. As far as Codex is concerned, 272,000 is the ceiling unless you tell it otherwise.
Codex profiles let you create named configurations -- a different model, different sandbox rules, different settings -- and switch between them with --profile name. Each profile lives in its own file at ~/.codex/<name>.config.toml, using the same top-level keys as ~/.codex/config.toml. Anything you set in a profile file overrides the matching value in config.toml for sessions launched under that profile.
That includes model_context_window.
The profile that unlocks it
Create ~/.codex/long_context.config.toml:
model = "gpt-5.6-sol"
model_context_window = 1000000
model_auto_compact_token_limit = 800000
Three lines. model_context_window asks for a 1M-token window; Codex clamps the request to the catalog's max_context_window, so you get 872,000. model_auto_compact_token_limit triggers conversation compaction at 800K, leaving headroom before the effective ceiling. The same profile works with gpt-6-sol or any of the other GPT-5.6 and GPT-6 variants.
Launch with:
codex --profile long_context
Verifying it works
Inside the Codex TUI, /status shows the context window size. For a definitive check, inspect the rollout JSON from your session:
latest_rollout=$(
find ~/.codex/sessions -name 'rollout-*.jsonl' -printf '%T@ %p\n' \
| sort --numeric-sort \
| tail --lines=1 \
| cut --delimiter=' ' --fields=2-
)
jq -r '
select(.type == "event_msg" and .payload.type == "task_started")
| .payload.model_context_window
' "$latest_rollout"
This returns 828,400. Codex applies a 95% effective context window, so the runtime ceiling is 828,400 of the catalog's 872,000. Without the profile, the same check returns 258,400 -- 95% of 272,000.
What the override actually buys you
It isn't permission to send a big prompt. The server already accepts one: on my Plus account, a single-turn codex exec on GPT-5.6 took 773,605 input tokens with no override at all. (A single turn of about 1.02 million tokens was rejected with "Codex ran out of room in the model's context window", consistent with the 872K ceiling.)
What the override changes is compaction. Codex compacts the conversation once it nears the window it believes it has, and by default that window is 258,400. To see the difference, I sent a ~314,000-token first turn and then a short follow-up in the same session:
- Default: Codex compacted the conversation before the second turn, which went out at 274,082 tokens.
- With the override: no compaction. The second turn carried the whole conversation -- 318,993 tokens.
In a real working session -- long files, long tool output, many turns -- that is the difference between Codex summarizing away your early context at a quarter of a million tokens and keeping it until well past three-quarters of a million.
To reproduce the end-to-end test, build a large input and pipe it to a single turn. Space-separated random digits come out at roughly one token per character, so a 760,000-character file is about 774,000 tokens:
python3 -c "
import random
print(' '.join(str(random.randint(0, 9)) for _ in range(380000)))
" > big_input_file
codex exec --profile long_context --skip-git-repo-check \
'Reply with only the literal word RECEIVED.' < big_input_file
Then read last_token_usage.input_tokens from the rollout's token_count events to see what the server accepted.
What happened to GPT-5.4 and GPT-5.5
This post originally targeted GPT-5.4, which shipped in the catalog with a 1,000,000-token maximum. That no longer applies: GPT-5.4 has dropped out of Codex's catalog, and requesting it on a ChatGPT account now fails with "The 'gpt-5.4' model is not supported when using Codex with a ChatGPT account."
GPT-5.5 can't be raised. Its catalog entry sets both context_window and max_context_window to 272,000, so the override has nothing to clamp to -- the window stays at 258,400 -- and the server agrees: a ~305,000-token single turn was rejected. If you want a bigger window, use GPT-5.6 or GPT-6.
Why this works now (and didn't for a while)
The override has had a bumpy history:
- Before Codex 0.134.0, profiles lived inside
~/.codex/config.tomlas[profiles.X]tables, and that table parser silently droppedmodel_context_window(openai/codex#14456). 0.134.0 moved profiles into their own files, where the key worked. - By Codex 0.144.4, the override was ignored entirely: sessions reported 258,400 whatever you set.
- As of Codex 0.156.1, it is honored again, up to each model's
max_context_window.
I tested all of this on Codex 0.156.1 with one ChatGPT Plus account. On Pro / Enterprise / API the server-enforced ceilings may differ -- I haven't tested them.