codex - 💡(How to fix) Fix Codex CLI runs out of context instead of compacting/resuming long thread with many tool calls [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#19842Fetched 2026-04-28 06:36:08
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×3unlabeled ×1

Error Message

  1. Before the error, the session token logs showed cumulative token usage growing well beyond the model context window. The final token-count event immediately before the failure was:

Code Example

Codex ran out of room in the model's context window. Start a new thread or clear earlier
history before retrying.

---

curl -sL
'https://raw.githubusercontent.com/Tasshack/dreame-vacuum/master/custom_components/dreame_vacuum/dreame/resources.py'
Original token count: 815104
Output bytes in transcript: 40167
RAW_BUFFERClick to expand / collapse

What version of Codex CLI is running?

codex-cli 0.125.0

What subscription do you have?

Pro

Which model were you using?

gpt-5.5 xhigh

What platform is your computer?

Darwin 24.6.0 x86_64 i386

What terminal emulator and version are you using (if applicable)?

Ghostty 1.3.1

What issue are you seeing?

During a long Codex CLI session, Codex hit the context-window limit and showed this message:

Codex ran out of room in the model's context window. Start a new thread or clear earlier
history before retrying.

The session was not able to continue normally from the existing thread. I had to start/use a new compacted context instead of the CLI automatically compacting the conversation or giving a working continuation path.

Uploaded thread:

019dd000-1909-7592-9fa5-c26c1f006225

What steps can reproduce the bug?

  1. Start a Codex CLI session using codex-cli 0.125.0.
  2. Ask Codex to do a research-heavy task that requires current web/GitHub investigation.
  3. In my thread, the task was researching Xiaomi S20+ vacuum map backup/recovery. The turn included:
  • 30 built-in web tool actions: 8 searches, 20 page opens, and 2 find-in-page operations.
  • 58 shell tool interactions: 53 exec_command calls and 5 write_stdin calls.
  • All 53 exec_command calls were curl-backed shell commands, covering GitHub raw files, GitHub API endpoints, Xiaomi MIOT spec endpoints, and related project documentation.
  1. Several tool outputs were large. The largest recorded tool output was:
curl -sL
'https://raw.githubusercontent.com/Tasshack/dreame-vacuum/master/custom_components/dreame_vacuum/dreame/resources.py'
Original token count: 815104
Output bytes in transcript: 40167
  1. Before the error, the session token logs showed cumulative token usage growing well beyond the model context window. The final token-count event immediately before the failure was:

total_tokens: 258400 model_context_window: 258400

  1. Codex then failed before producing the final answer with:

Codex ran out of room in the model's context window. Start a new thread or clear earlier history before retrying.

Uploaded thread: 019dd000-1909-7592-9fa5-c26c1f006225

What is the expected behavior?

Codex CLI should compact the conversation automatically instead of requiring the user to start a new thread or manually clear earlier history.

Additional information

No response

extent analysis

TL;DR

The most likely fix is to implement automatic conversation compaction in the Codex CLI to prevent hitting the model's context window limit.

Guidance

  • Review the Codex CLI code to identify where the context window limit is being checked and consider adding a mechanism to automatically compact the conversation when the limit is approached.
  • Investigate the codex-cli command-line options to see if there are any existing flags or parameters that can be used to control conversation compaction or context window size.
  • Consider adding a warning or notification to the user when the context window limit is approaching, to allow them to take action before the error occurs.
  • Examine the uploaded thread (019dd000-1909-7592-9fa5-c26c1f006225) to understand the specific sequence of events that led to the error and identify potential areas for optimization.

Example

No code snippet is provided as the issue does not include specific code examples, but the solution may involve modifying the Codex CLI code to include automatic conversation compaction.

Notes

The solution may require modifications to the Codex CLI code and may not be possible through configuration changes alone. The exact implementation will depend on the specifics of the Codex CLI codebase and the requirements of the model's context window.

Recommendation

Apply a workaround by manually compacting the conversation or clearing earlier history when the context window limit is approached, until a permanent fix can be implemented. This is because the current behavior requires manual intervention, which can be error-prone and inefficient.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Codex CLI runs out of context instead of compacting/resuming long thread with many tool calls [1 participants]