codex
codex copied to clipboard
Input exceeds context window error
What version of Codex is running?
0.27.0
Which model were you using?
gpt5-high
What platform is your computer?
macOS
What steps can reproduce the bug?
πβ stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and
try again.
Working (18s β’ Esc to interrupt)
β Write tests for @filename
β send Shift+β newline Ctrl+T transcript Ctrl+C quit 2445968 tokens used 29% context left
29% left and it was only making minor edits and suddenly stopped.
What is the expected behavior?
If it's trying to read in a randomly large file, it should either read a portion in or state what it's doing. No transparency into what it's doing and why it's failing.
What do you see instead?
πβ stream disconnected before completion: Your input exceeds the context window of this model. Please adjust your input and try again.
No clue what I'm supposed to do - adjust which input? Codex was on its own
Additional information
Ask codex to make a minor refactor involving removal of a parameter in a function.
Interestingly, a /compact only increased the context by 3%? Is this expected? I was hoping to regain at least 90% of the original context.
codex
Compact task completed
β Write tests for @filename
β send Shift+β newline Ctrl+T transcript Ctrl+C quit 272054 tokens used 32% context left
I should add - after I posted the above, my next prompt suddenly bumped it to 90%! So this looks like a glitch.
In this topic, I probably described this problem
same issue: https://github.com/openai/codex/issues/2825
Same issue here, similar behavior where compact does not gain much context back and i have 30-40% left despite getting htis message
This is happening to me pretty frequently now, but only on one of 3 projects.
On Codex $200 plan, I get Stream disconnected before completion: input exceeds context window even with ~98% window left. Seems like it disconnects too early.
Same here, 30% context left.
And same here, 30% context left...
And same here 32% context left
Does anyone have a workaround? How do I create a new set of prompts? As it were, how do I clear the input cache?
try to create a new session or a new chat. this is working for me. If are you using a terminal, do a logoff and logon.
90% context left!!! And that was after the FIRST prompt in that context. This was the fifth or sixth time, I tried that.Yesterday, I had that error even with 98% context left.
Codex is just useless!!! Im working for hours here, and did accomplish almost nothing.
same here
same here
Error still persists. Getting the same error
getting the same error in the vs code extension
Mismo error por aquΓ, pero me he dado cuenta de 2 cosas 1β el error solo ocurre en conversaciones largas (al menos en mi caso) 2β al iniciar un chat nuevo el error desaparece, ya que el contexto se reinicia
Same here. Very annoying error since I don't know how to recover. "/compact" doesn't work.
This happened to me with 95% of my context window still available
i have to restart codex in the server terminal for it to resume
Happening to me too on codex-cli 0.39.0
@bolinfest Is it possible to assign someone to this bug please π
@DevVig I have a question: have you run /compact before, or is this your first session? Or did you resume it using resume?
happening to me too in codex extension in cursor
Same here, cli and Cursor extension. On the Pro tier.
here this always happens when the model tries to read a big image. then it gets stuck in it. have no idea how it works, but It must be something related to chat history.
claude code has the same exact issue btw
Yeah this is so annoying. As a $200/mo pro user, I'd expect Codex to compact automatically if its getting close to the limit. The problem is that this will even happen when its progressing through a single prompt, especially when refactoring.. Switching to Claude 4.5 for time being.
Also happening to me, on codex version 0.44.0
Letβs assume you start with around 190k tokens in context, leaving roughly 80k available.
The input counter, however, isnβt updated in real time β it only refreshes after a completed turn.
So if, within the same turn, you issue something like βAnalyze xyzβ¦β followed by βapply corrections,β
it can cause a context overflow that even auto-compaction canβt handle.
The root cause is that each iteration adds to the context,
but the system doesnβt realize it until the entire turn finishes.
As a result, during generation you might already exceed 300k tokens,
yet this isnβt detected until after the fact β too late for prevention.
In optimal conditions, auto-compaction should mitigate this.
But for that to work, token counting must be done in real time,
and compaction should run in a separate thread the moment the size passes the threshold.
Then, subsequent iterations could append directly to the compacted context
instead of the full conversation history.
Alternatively, a scaled compaction + last N elements approach could work,
where N is configurable and dynamically adjusted based on the tools used
and the number of active calls β ensuring nothing critical disappears mid-execution.
This would improve both stability and user experience
(β
no visible pauses or late compaction, smoother flow overall).
The correct behavior should look like this:
β
190 β 210 β β¦ β 250 β (compact) β 120 β 150 β β¦ β end of turn
Currently, it behaves incorrectly:
β 190 β 210 β β¦ β 250 β context overflow (no compaction during the turn)
Claude has access to real-time information about the current context state,
and in such situations, it automatically interrupts generation
before a context overflow can occur.
I found what the cause of premature stream disconnect (i.e., before context = 0) is for me. It is when I resume a conversation that was, when previously loaded, in full approval mode, and order it to do things that require full approval mode before first setting approval to full (as when you resume a convo, even if it was in full approval mode before closing the codex session, it loads auto approval when you resume it). For example I'll be working with codex on a problem in full approval mode. End the conversation. Resume it, forget to switch back to full approval, and get it continue doing what it was doing before, which required full approval, then it occurs (the premature stream disconnect issue).
I tried everything to be able to resume the convo from where the alleged bug happens - resuming via codex resume ID. Resuming via codex resume then selecting the convo. In the convo, switching to full approval and trying to get it to continue after the issue started happening. Merely getting it to say hi. None of those tactics broke the wall.
I started a new convo, and directed it to the broken chat's transcript, sort of quizzing it to get it back up to speed. Usually regained context pretty effectively this way.
This is killing my workflow. What is the deal here? Such great models but without a proper agentic client. Terrible UX.