Codex agent is stuck in compaction loop
What version of Codex is running?
v0.77.0
What subscription do you have?
Plus
Which model were you using?
gpt-5.1-codex-mini medium
What platform is your computer?
Linux 6.6.87.2-microsoft-standard-WSL2 x86_64 x86_64
What issue are you seeing?
When I run any tasks involving reading files or working on files the codex gets into an endless loop of executing file related commands and compacting the context. Even creating Agents.md with /init gets stuck in an endless loop Even though it is a fresh session. I tested it with GPT gpt-5.1-codex-mini medium, gpt-5.2 medium and gpt-5.1-codex-max medium. All have the same bug. I tested it on Win 11 (Microsoft Windows NT 10.0.26100.0 x64) and have the same issue in CLI. VS code extention for codex v 0.4.56 has the same issue. Below I attached the output for gpt-5.1-codex-mini medium where I started a new session and asked it to /init on that project. Project is a small hobby app for Android. Here is the output:
Ran pwd
└ /mnt/k/dev/Personal/TabletNotes
─ Worked for 6s ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Ran pwd
└ /mnt/k/dev/Personal/TabletNotes
─ Worked for 12s ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Ran pwd
└ /mnt/k/dev/Personal/TabletNotes
─ Worked for 17s ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Ran pwd
└ /mnt/k/dev/Personal/TabletNotes
─ Worked for 21s ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Ran pwd
└ /mnt/k/dev/Personal/TabletNotes
─ Worked for 29s ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Ran pwd
└ /mnt/k/dev/Personal/TabletNotes
─ Worked for 38s ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Ran pwd
└ /mnt/k/dev/Personal/TabletNotes
─ Worked for 45s ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Ran pwd
└ /mnt/k/dev/Personal/TabletNotes
─ Worked for 52s ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Ran pwd
└ /mnt/k/dev/Personal/TabletNotes
─ Worked for 57s ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Context compacted
• Ran pwd
─ Worked for 1m 01s ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Context compacted
• Ran pwd
─ Worked for 1m 07s ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Context compacted
• Ran pwd && ls
settings.gradle.kts
shared
─ Worked for 1m 12s ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Context compacted
• Ran pwd
└ /mnt/k/dev/Personal/TabletNotes
─ Worked for 1m 19s ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Ran pwd
└ /mnt/k/dev/Personal/TabletNotes
─ Worked for 1m 26s ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Explored
└ List ls
─ Worked for 1m 42s ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Updated Plan
└ □ Inspect repository documentation (README.md/package.json) to capture structure, commands, and conventions relevant for AGENTS.md
□ Draft AGENTS.md using required sections and repository specifics, referencing commands and structure
─ Worked for 1m 49s ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Ran pwd
└ /mnt/k/dev/Personal/TabletNotes
─ Worked for 2m 04s ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Context compacted
• Ran pwd
└ /mnt/k/dev/Personal/TabletNotes
─ Worked for 2m 10s ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
• Context compacted
• Explored
└ List ls
The codex on my pc is no longer usable. The last time I was able to use codex was on December 19th 2025. I tried updating to a new version. uninstall codex both in Win 11 and wsl, downgrade to 0.75 and 0.74 but nothing helps.
What steps can reproduce the bug?
Uploaded thread: 019b4baf-6987-7962-bfb0-50343cbf276f
Already described in the issue description
What is the expected behavior?
_No response_
Additional information
_No response_
12 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
Thanks for reporting the issue. We're aware of this problem. Several other users have hit this recently. We think we understand the cause, and we're actively working on a solution.
@etraut-openai Thank you for the information. Is there a way for me to fix it myself (e.g. edit some config, fresh install or something like this)? This week the tool was completely unusable for me due to this issue.
Tried it again with a test project. The project has a single small md file. My prompt:
Readdocument.mdfile, analyze it and save overview tooverview.md`. I sent a session feedback019b560f-e820-7e70-b915-e2d1bd792620 `We've determined that the problem occurs when you have extremely long user prompts and tool outputs. Most users do not hit these conditions, which explains why we've received relatively few reports of this. To work around the issue, avoid usage patterns that involve extremely long user prompts or tool outputs.
@etraut-openai
In my previous message I referenced another session. Just to reiterate my previous message - Tried it again with a test project. The project folder has only one md file with a short text (less than 7000 characters). I have empty
Agents.mdso codex doesn't get stuck in a loop trying to create it. I started a new codex session and used this simple prompt: Readdocument.mdfile, analyze it and save overview tooverview.md. I do not use any mcp or skills. It is as a simple as it gets. There are no long prompts or large files. It is a toy task just as a sanity check. The codex spent over 7 minutes in a loop trying to read the file. Codex could not read the file but just kept making a plan to do it and usedlscommand over and over. I sent a session feedback019b560f-e820-7e70-b915-e2d1bd792620.I would like to emphasize it again: One md file, extremely simple task to read a short file and write the overview to a new file. Prior to this codex was able to read a few source code files and edit them. Now it cannot even read a single file in a project that only has one (1) file.
Prompt
I am not sure how to take your words regarding long prompts to exceed typical usage of codex. Could you please tell if this prompt is more complex than a typical user prompt:
Read document.md file, analyze it and save overview to overview.mdJust a week ago I used prompts with dozens of lines of text that referenced many documents to be read in addition to prompt.
Document
Based on my estimation the document that I tried to analyze could be over 1k tokens. Should I keep documents and code under 1k tokens? I am not sure how low I should go. I just put two words "Hello World" in a document instead of 7000 characters. Codex worked for 5 minutes 44 seconds before I manually stopped it. The detailed log was sent
019b57a3-af32-79f0-85c9-0a4a44a2a61dto you. I do not want to make any assumptions but I suspect most users have more than two words in their documents/source code when codex work on them. So is is highly unlikely that my two-word document exceeded typical use of the tool or overloaded the context with just 2 words.Tools output
I do not use any 3rd party tools or mcp servers. I do not use codex skills. If we are talking about internal tools that codex uses I have no control over it.
To summarize, even with extremely simple prompt and two word document codex goes into endless loop of context compaction and planning. The tool is 100% unusable for me.
During long-term use, context compression occurs at short intervals.
After one compression, the context capacity will start from the beginning, with 30% remaining.
Are there any problems with compression?
@etraut-openai Any chance of a fix? Can't use our main session anymore.
I need this to be effective with Codex.
This just happened to me running codex-cli 0.101.0 in WSL 2 - did one compaction loop and showed 100% remaining context (agent was trying to run some tests with playwright-mcp) and after every start it would do another compaction and restart over and over again.
I found in my case having the agent either take of view screenshots triggered the compaction (consistently). Not sure what but everything was working fine until it tried to take screenshots from the playwright browser.
I tried codex-cli 0.101.0 on Windows directly instead of WSL2 and the same compaction loop gets triggered when I request viewing a screenshot from the playwright MCP server.
Having codex view screenshots from files or using the playwright skill to capture screenshots with the playwright-cli and having codex view them doesn't trigger the compaction though.