Codex “Ran Out of Room in the Model’s Context Window” Fix

Check which message Codex gave you. If it only says it “ran out of room in the model’s context window,” one chat has piled up more tokens than the model can hold. Run /compact once and re-pin five facts. If the message starts with “Error running remote compact task,” update Codex first. Neither message is the 5-hour or weekly usage limit. If it keeps coming back, carry the confirmed facts into /new.

I hit this error during a long refactor in Codex CLI, and the steps below are what I do now when it shows up.

On this page
  1. What “ran out of room in the model’s context window” means
  2. Right after it hits: /compact once, then re-pin five facts
  3. When /compact itself fails: “Error running remote compact task”
  4. Picking the next chat: resume, fork or /new
  5. Why it hits sooner now, and how far settings go
  6. When I stop compacting and start over

What “ran out of room in the model’s context window” means

It means the chat itself is full: your messages, the files Codex read, command output and diffs add up past the model’s window. Usage limits reset with time; this doesn’t. /status shows how much context is left.

The full message ends with “Start a new thread or clear earlier history before retrying.” That wording is quoted in GitHub issue #19269, opened April 24, 2026 against v0.124.0 and closed as a duplicate. An OpenAI Developer Community thread shows the same text, and the OpenAI_Support account there only asked for the version, model and logs.

My first guess was wrong. A week earlier I’d been cut off by the usage limit, so I opened the usage screen first. There was plenty left. I sent the same prompt twice more, it failed the same way both times, and only then did I see that the chat was full.

The quickest way to tell the two apart is a new chat. A usage limit is per account, so a new chat is blocked too. A full context window is per chat, so a new chat works right away.

Where it came from: a multi-module refactor that kept growing

I was cleaning up existing logic in a Java/Spring multi-module repository. It started as a change to two or three files, but the area I had to investigate kept widening, and the files Codex read and the diffs it produced piled up. I went around the same loop several times: run the tests, check why they failed, fix the code, rerun.

It didn’t fail all at once. Toward the end I more often had to re-confirm things we’d already decided, or tidy up the context. That warning sign came back a few times before it turned into the error. Reading several modules and their test files at once is what eats the window.

I’ve seen the error about twice more since, and neither was a refactor. One was a session where I kept pasting long Gradle failure logs while tracing integration tests that broke module by module. The other was an investigation that spread until Codex kept opening configuration classes across modules. Now I paste only the failing test name and the line with the cause.

Right after it hits: /compact once, then re-pin five facts

/compact replaces earlier turns with a short summary to free up context, per the official slash command reference. Auto-compaction is the same summary running on its own once the chat crosses a token threshold.

After I run it, I add back one sentence for each of these:

  • The final goal of the current task
  • The edit scope for this session
  • Tests that are still failing
  • Approaches I tried and dropped
  • Areas that must not be touched
Checklist of five things to restate after /compact: goal, edit scope, failing tests, dropped approaches, and off-limits areas

What stayed and what I had to restate

In my sessions, /compact kept the big goal, the main files and the decisions already made. The reasoning behind smaller decisions often had to be pointed out again. When the session was already very long, or the direction had changed several times, I still had to add explanations back. In the refactor, I compacted once and then kept re-explaining why I’d dropped an approach.

So I treat /compact as a way to keep a chat going, not as a saved copy of it. I don’t stack compacts either, because a summary of a summary only gets blurrier.

When /compact itself fails: “Error running remote compact task”

In issue #29041 (June 19, 2026, Codex CLI v0.140.0), the reporter couldn’t run /compact at all once this appeared. On June 29, 2026, an OpenAI maintainer wrote in issue #28937 that compaction had moved to local logic, which “eliminates ‘remote compaction’ errors.”

The latest release, 0.167.0 (November 6, 2026), says auto-compaction now counts the remaining output of a failed response (#58404). Issue #43963, about a Windows desktop thread that stays blocked after repeated remote compaction failures, is still open as of November 9, 2026.

What to do, in order:

  1. Update Codex CLI to the latest release and retry /compact.
  2. If the error cut off a turn mid-edit, check git diff before anything else. A failed agent turn can still leave changed files, as in a Claude outage where the request failed but files still changed.
  3. If compaction still fails, stop and start a new chat with /new, carrying the facts from the list above.

Picking the next chat: resume, fork or /new

Resume continues the same judgment and keeps the full history, so a full chat stays full. Fork tests a different approach from the same context. /new restarts with only the facts you carry in.

Command What it does When I use it
/compact Summarizes earlier turns Re-explaining has just started to cost more
codex resume --last Reopens the latest chat as is The direction is right; only details remain
codex fork --last Copies the chat into a new branch Same context, different approach
/new Starts a fresh chat in the same CLI Dead ends have polluted the context
/clear Starts a fresh chat and clears the screen I rarely use it

Using resume, fork and /new interchangeably tangles the context further. Per the official reference, codex resume --last picks the most recent chat in the current directory unless you add --all.

Does resuming free up context?

No. Resume brings back the same history, so if the window was already full, the error can come straight back. To free space you need /compact or a new chat.

Why it hits sooner now, and how far settings go

InfoWorld reported on July 20, 2026 that with GPT-5.6, the default Codex CLI input window dropped from 372,000 to 272,000 tokens (PR #34009). OpenAI didn’t explain the change in that report.

Window sizes have changed between versions, so I read the remaining share from /status instead.

Can you raise the limit?

Only partly. The config reference lists model_context_window as the context window tokens available to the active model, and model_auto_compact_token_limit as the token count that triggers auto-compaction. Per issue #11805, from v0.100.0 a user-set threshold is capped at 90% of the window.

Auto-compaction has also been uneven across versions: in issue #4363, compact didn’t run automatically in v0.42.0 with a large change set. Since September 2026 I’ve compacted by hand rather than waiting for auto-compaction, because if Codex compacts on its own at the end, I don’t get to choose what the summary keeps.

When I stop compacting and start over

I switch when re-explaining the context costs more than compressing and keeping it. A long context by itself isn’t the problem. In refactoring, where decisions keep changing midway, pulling out only the confirmed facts and starting fresh has been more stable for me than dragging compressed history along.

Decision flowchart for choosing between codex resume, codex fork, and /new when re-explaining context starts costing too much

In that first refactor I moved to /new after one compact. I took the goal in one line, the git diff at that point, the confirmed cause, the failing test names, the dropped approaches and the modules not to touch. I took none of the chat history. The remaining modules were done in under two hours, the tests passed, and I pushed it that day.

My /status rule now: at around half the context left, I keep going unless the direction has already flipped twice. Below 20 to 30% left, any task where I’d been pasting logs moves to a new chat. If the investigation keeps widening, I split the question into separate chats.

If you carry only three lines, make them the goal, the edit scope and the failing tests. Rules that should survive every new chat belong in AGENTS.md, which Codex reads before it starts work, per the AGENTS.md guide.

I tested how much of a rules file an agent actually follows on the Claude side, and short rules held up best. If the CLI itself isn’t set up yet, my Codex CLI npm install and sandbox notes cover that.

I’ll revisit this post when #43963 reaches a conclusion or the default window changes again.

Sources

Show 7 more sources
  • Issue #19269, openai/codex, 2026-04-24: the “Codex ran out of room…” message (v0.124.0, closed as duplicate)
  • OpenAI Developer Community thread 1384241, OpenAI Developer Community: same error, OpenAI_Support reply
  • Issue #29041, openai/codex, 2026-06-19: “Error running remote compact task:” (v0.140.0; 2026-10-30 comment pointing to #43963)
  • Issue #28937, openai/codex, 2026-06-29: maintainer reply on local compaction
  • Issue #43963, openai/codex, opened 2026-09-09, open as of 2026-11-09: “Windows Desktop: saved thread remains blocked after repeated context_window_exceeded during remote compaction”
  • Issue #11805, openai/codex, 2026-02-14: auto-compaction threshold capped at 90% from v0.100.0 (not planned, closed the same day)
  • Issue #4363, openai/codex, closed 2025-10-21: compact not auto-running in v0.42.0 (completed)

Related posts


I first wrote this in Korean on my blog: https://jjeongil.tistory.com/3568.