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

Resolved 💬 10 comments Opened Dec 17, 2025 by robertotcestari Closed Jun 29, 2026
💡 Likely answer: A maintainer (etraut-openai, contributor) responded on this thread — see the highlighted reply below.

What version of Codex is running?

codex-cli 0.73.0

What subscription do you have?

pro

Which model were you using?

gpt-5.2

What platform is your computer?

Darwin 25.1.0 arm64 arm

What issue are you seeing?

Error running remote compact task: {
"error": {
"message": "Your input exceeds the context window of this model. Please adjust your input and try
again.",
"type": "invalid_request_error",
"param": "input",
"code": "context_length_exceeded"
}
}

What steps can reproduce the bug?

Uploaded thread thread ID 019b2c32-a042-7aa0-af6e-43be27e1451b

What is the expected behavior?

_No response_

Additional information

_No response_

View original on GitHub ↗

10 Comments

robertotcestari · 7 months ago

thread ID 019b2c32-a042-7aa0-af6e-43be27e1451b

wudi · 6 months ago

Manually edit the session file ~/.codex/sessions/xxxx/xx/xx/session-id.jsonl to remove the huge line of text, then do resume the session, then /compact. If the problem still exists, continuous removal of large text lines.

acllm · 6 months ago
Manually edit the session file ~/.codex/sessions/xxxx/xx/xx/session-id.jsonl to remove the huge line of text, then do resume the session, then /compact. If the problem still exists, continuous removal of large text lines.

Excuse me, what does the manually edit actually do on the Agent's side? Is there any side effects?

armaanahluwalia · 5 months ago

Happened to me when I was running a task that required a bunch of internet searches

<img width="1024" height="1536" alt="Image" src="https://github.com/user-attachments/assets/cb15377f-0d4a-47f1-bdd0-921b0ae4ab38" />

kdawgwilk · 4 months ago

Mine was also right after a bunch of web searches, why does auto compaction not kick in here?

plugyawn · 4 months ago

Maybe like a minify attack.

antonkoetzler · 1 month ago

The fact that this hasen't been fixed for 4 months now is embarassing

AXsss · 1 month ago

The fact that this hasen't been fixed for 6 months now is embarassing

Han-1413141 · 1 month ago

English

For conversations already affected by this issue, enter /compact in the chat box to manually compress the context so you can continue the conversation. To prevent this issue from recurring, navigate to C:\Users\[Username]\.codex\config.toml and reduce the value of model_auto_compact_token_limit. The probable cause is context length overflow: either the compression mechanism fails to work properly, or the context length of the last conversation surges past the maximum limit immediately after exceeding the minimum compression threshold, leaving no time for compression to execute.

You can also resolve the problem by cutting down the initial context length, such as shortening system prompts, disabling extra skills and plugins.

Another root cause may be that the current conversation carries background data from other dialogues. Deleting old chat logs can also fix the issue, yet I do not want to lose historical records, so I opted for the previous solution. Here is the second workaround:

  1. Locate the session file path: ~/.codex/sessions/Year/Month/Day/session-id.jsonl; this file may become extremely large.
  2. Remove outdated sessions: manually delete session files with earlier dates while keeping recent chat records.
  3. Restart Codex: reboot the Codex tool after cleanup to apply the modifications.

中文

已经出现该问题的对话,在对话框输入 /compact 手动压缩上下文后即可继续对话。若想要避免再次出现该问题,可打开路径 C:\Users\用户名\.codex\config.toml,将 model_auto_compact_token_limit 参数数值调小。问题推测为上下文长度溢出:自动压缩机制未正常生效,或是上一轮对话上下文刚达到压缩最低阈值就直接超限,系统来不及执行压缩操作。

也可以精简系统提示词、关闭多余技能与插件,缩减初始上下文长度以解决故障。

另一种成因是当前对话会附带其他会话的历史内容,删除旧对话记录也能解决问题,但我不想丢失历史聊天记录,因此选用了第一种方案。以下是第二种解决方法:

  1. 定位会话文件:文件路径为 ~/.codex/sessions/年/月/日/session-id.jsonl,该文件体积可能会很大;
  2. 删除早期会话:手动移除日期较早的会话文件,保留近期聊天记录;
  3. 重启Codex:清理完成后重启Codex工具,使修改生效。
etraut-openai contributor · 21 days ago

Thanks for reporting this problem. Until recently, Codex used a separate endpoint and server-side logic for compaction. We recently switched to a more robust approach where the compaction logic is moved locally using the same endpoint as normal turns. This eliminates "remote compaction" errors and increases the stability and reliability of compaction operations. If you see further problems with compaction, please use /feedback and open a new bug report.