Input exceeds context window error

Resolved 💬 34 comments Opened Aug 30, 2025 by guidedways Closed Nov 18, 2025
💡 Likely answer: A maintainer (guidedways, contributor) responded on this thread — see the highlighted reply below.

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.

View original on GitHub ↗

34 Comments

guidedways contributor · 10 months ago

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
guidedways contributor · 10 months ago

I should add - after I posted the above, my _next_ prompt suddenly bumped it to 90%! So this looks like a glitch.

synestiqx · 10 months ago

In this topic, I probably described this problem

oyiakoumis contributor · 10 months ago
gabrielbryk · 10 months ago

Same issue here, similar behavior where compact does not gain much context back and i have 30-40% left despite getting htis message

rbergman · 10 months ago

This is happening to me pretty frequently now, but only on one of 3 projects.

vixkram · 10 months ago

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.

nachoal · 10 months ago

Same here, 30% context left.

<img width="1990" height="938" alt="Image" src="https://github.com/user-attachments/assets/eec05159-d531-4682-b5a7-fbea28a3397d" />

s-a-n-i-n · 10 months ago

And same here, 30% context left...

Vamsi-klu · 10 months ago

And same here 32% context left

MilesAheadToo · 10 months ago

Does anyone have a workaround? How do I create a new set of prompts? As it were, how do I clear the input cache?

rporcionato · 10 months ago

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.

hpmartini · 10 months ago

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.

<img width="2626" height="680" alt="Image" src="https://github.com/user-attachments/assets/8dff68cd-a1ab-47b2-91e8-6fabdcb460ae" />

Codex is just useless!!! Im working for hours here, and did accomplish almost nothing.

mateusgalasso · 10 months ago

same here

abutun · 10 months ago

same here

akamalov · 10 months ago

Error still persists. Getting the same error

FearMyShotz · 10 months ago

getting the same error in the vs code extension

<img width="877" height="270" alt="Image" src="https://github.com/user-attachments/assets/088bebd5-52cc-4288-9712-3f99b43cf279" />

Bernyabreu42 · 10 months ago

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

rrainist · 10 months ago

Same here. Very annoying error since I don't know how to recover. "/compact" doesn't work.

<img width="1447" height="462" alt="Image" src="https://github.com/user-attachments/assets/dcfb9f64-a812-4583-b7c4-f242e5fdd728" />

DevVig · 10 months ago

This happened to me with 95% of my context window still available

<img width="1484" height="800" alt="Image" src="https://github.com/user-attachments/assets/f88da1df-14d6-472a-85a8-455b792ebec3" />

i have to restart codex in the server terminal for it to resume

DenisGorbachev · 10 months ago

Happening to me too on codex-cli 0.39.0

@bolinfest Is it possible to assign someone to this bug please 🙏

synestiqx · 10 months ago

@DevVig
I have a question: have you run /compact before, or is this your first session? Or did you resume it using resume?

alooshxl · 9 months ago

happening to me too in codex extension in cursor

billkie · 9 months ago

Same here, cli and Cursor extension. On the Pro tier.

Rodrigo-JM · 9 months ago

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

mgunnin · 9 months ago

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.

tazabreu · 9 months ago

Also happening to me, on codex version 0.44.0

synestiqx · 9 months ago

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.

xxrraa · 9 months ago

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.

fullofcaffeine · 9 months ago

This is killing my workflow. What is the deal here? Such great models but without a proper agentic client. Terrible UX.

farmhutsoftwareteam · 9 months ago

is the solution to start a new chat?

etraut-openai contributor · 8 months ago

I think this issue has been fixed, so I'm closing. If you see a similar issue with the latest versions of codex, please open a new issue and provide any relevant repro steps or other details.

rupertlssmith · 7 months ago

Get this a lot more since ChatGPT 5.2, never had it on 5.1

etraut-openai contributor · 7 months ago

If you see a similar issue with the latest versions of codex, please open a new issue and provide any relevant repro steps or other details.

Locking the issue to prevent additional posts.