codex - 💡(How to fix) Fix Codex memory grows to 75GB+ during basic session [1 comments, 2 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#20740Fetched 2026-05-03 04:46:26
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1renamed ×1unlabeled ×1

Urgent: Codex can grow to extreme memory usage during an apparently basic/single-task session, eventually triggering macOS "Your system has run out of application memory."

Observed in the macOS Force Quit Applications dialog:

Codex: 75.50 GB
cmux (paused): 10.76 GB
Activity Monitor: 60.4 MB
Finder: 125.9 MB

The memory usage reportedly kept increasing and reached roughly 85 GB before Codex was stopped to avoid taking down the system.

Root Cause

Urgent: Codex can grow to extreme memory usage during an apparently basic/single-task session, eventually triggering macOS "Your system has run out of application memory."

Observed in the macOS Force Quit Applications dialog:

Codex: 75.50 GB
cmux (paused): 10.76 GB
Activity Monitor: 60.4 MB
Finder: 125.9 MB

The memory usage reportedly kept increasing and reached roughly 85 GB before Codex was stopped to avoid taking down the system.

Code Example

Codex: 75.50 GB
cmux (paused): 10.76 GB
Activity Monitor: 60.4 MB
Finder: 125.9 MB

---

turn{... model=gpt-5.5 codex.turn.token_usage.input_tokens=1905121 ... codex.turn.token_usage.cached_input_tokens=1818240 ... codex.turn.token_usage.non_cached_input_tokens=86881 ... codex.turn.token_usage.output_tokens=3950 ... codex.turn.token_usage.reasoning_output_tokens=1091 ... codex.turn.token_usage.total_tokens=1909071}: codex_core::tasks: close time.busy=1.18s time.idle=361s
RAW_BUFFERClick to expand / collapse

Summary

Urgent: Codex can grow to extreme memory usage during an apparently basic/single-task session, eventually triggering macOS "Your system has run out of application memory."

Observed in the macOS Force Quit Applications dialog:

Codex: 75.50 GB
cmux (paused): 10.76 GB
Activity Monitor: 60.4 MB
Finder: 125.9 MB

The memory usage reportedly kept increasing and reached roughly 85 GB before Codex was stopped to avoid taking down the system.

Environment

  • Codex CLI: codex-cli 0.128.0
  • OS: macOS 26.4.1, Darwin 25.4.0, arm64
  • Model: gpt-5.5
  • Reasoning effort: medium
  • Config has multi_agent = true, but the observed problem happened during a basic/single-task session, not an intentionally large multi-agent run.

Impact

This is system-threatening on macOS:

  • macOS showed the global "system has run out of application memory" dialog.
  • Codex reached at least 75.50 GB in the Force Quit dialog.
  • The user had to stop Codex manually when it approached roughly 85 GB and was still increasing.
  • This can interrupt work and risks destabilizing the whole machine.

What happened

During a normal Codex session, memory usage climbed continuously even though the user was not running a large task. The behavior looked like runaway accumulation/leak rather than a bounded memory spike.

Relevant local log clue from the same timeframe:

turn{... model=gpt-5.5 codex.turn.token_usage.input_tokens=1905121 ... codex.turn.token_usage.cached_input_tokens=1818240 ... codex.turn.token_usage.non_cached_input_tokens=86881 ... codex.turn.token_usage.output_tokens=3950 ... codex.turn.token_usage.reasoning_output_tokens=1091 ... codex.turn.token_usage.total_tokens=1909071}: codex_core::tasks: close time.busy=1.18s time.idle=361s

That is about 1.9M total tokens for a session that did not feel like a large task from the user's perspective. This may indicate that Codex is retaining/re-sending/accumulating too much session context or cached input state across turns, which may correlate with the memory growth.

Expected behavior

For a basic single-task session, Codex memory should remain bounded and should not grow into tens of GB. If a session/context grows unexpectedly large, Codex should either compact, evict, fail fast with a clear diagnostic, or provide an explicit warning before the desktop app threatens system memory.

Actual behavior

Codex memory kept increasing until macOS forced the user into the application memory pressure dialog. Codex was shown at 75.50 GB and was reportedly near 85 GB before the user stopped it.

Notes

This may be related to a separate WebSocket/Responses streaming instability issue already filed here:

However, this issue is distinct: the urgent failure here is unbounded memory growth / excessive retained context during ordinary usage.

extent analysis

TL;DR

The most likely fix for the unbounded memory growth issue in Codex is to investigate and address potential memory leaks or excessive context retention, possibly by optimizing token usage and caching mechanisms.

Guidance

  • Review the codex-cli configuration and consider adjusting parameters related to token usage, caching, and session context to prevent excessive memory growth.
  • Investigate the multi_agent = true configuration setting, even though the issue occurred during a single-task session, to determine if it contributes to the memory leak.
  • Analyze the provided log clue to understand the token usage patterns and identify potential areas for optimization, such as reducing cached_input_tokens or non_cached_input_tokens.
  • Consider implementing a memory monitoring and alerting system to detect and prevent similar issues in the future.

Example

No specific code snippet can be provided without further information on the Codex implementation, but optimizing token usage and caching mechanisms might involve reviewing and refining functions related to codex.turn.token_usage.

Notes

The issue may be related to the separate WebSocket/Responses streaming instability issue filed in https://github.com/openai/codex/issues/20739, but addressing the memory growth issue should be prioritized due to its system-threatening nature.

Recommendation

Apply a workaround by adjusting the codex-cli configuration and monitoring memory usage closely, as the root cause of the issue is still unknown and may require further investigation and optimization of the Codex implementation.

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…

FAQ

Expected behavior

For a basic single-task session, Codex memory should remain bounded and should not grow into tens of GB. If a session/context grows unexpectedly large, Codex should either compact, evict, fail fast with a clear diagnostic, or provide an explicit warning before the desktop app threatens system memory.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING