Skip to content

Codex memory grows to 75GB+ during basic session #20740

Open

Description

@evilfps

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.

Activity

  1. added
    bugSomething isn't working
    CLIIssues related to the Codex CLI
    contextIssues related to context management (including compaction)
    on May 2, 2026
  2. changed the title [-]Urgent: Codex memory grows to 75GB+ during basic session[/-] [+]Codex memory grows to 75GB+ during basic session[/+] on May 2, 2026
  3. added
    CLIIssues related to the Codex CLI
    and removed
    CLIIssues related to the Codex CLI
    on May 2, 2026
  4. dpandey82 commented on May 5, 2026

    @dpandey82

    I faced same issue on my macbook m3pro

  5. mistersilver-uk commented on May 5, 2026

    @mistersilver-uk

    I've experienced the same issue on Ubuntu.

  6. IgorGanapolsky commented on May 6, 2026

    @IgorGanapolsky

    I hit a very similar macOS failure mode while cleaning up a local multi-project agent workstation. The useful distinction was separating Codex memory growth from session-restore amplification.

    A few diagnostics that made the issue easier to reason about:

    ps -axo pid,rss,command | sort -nrk2 | head -20
    launchctl list | rg -i 'codex|agent|tmux|restore|openclaw'
    tmux ls 2>/dev/null
    find "$HOME/Library/Mail" -path '*Outbox.mbox*Messages*.emlx' -type f 2>/dev/null | wc -l

    The mitigation that stopped the machine-wide collapse was:

    • disable automatic tmux/terminal/app restore for agent sessions
    • cap concurrent/background agents to 1 until memory is stable
    • move long-lived work into named workspaces with explicit owners/stop conditions
    • kill stale helper processes after GUI/Computer Use transport failures
    • keep Mail/Gmail/browser outbound automation off until the queue is proven empty

    This does not prove the root cause inside Codex, but it prevents a single leak/regression from being multiplied by restored sessions and background launch jobs.

    I wrote up the operational checklist here in case it helps other macOS users debug safely without wiping their workspace: https://igorganapolsky.github.io/AI_OpenClaw_Setup_Kits/guides/codex-openclaw-runaway-agent-safety.md

  7. omry commented on May 15, 2026

    @omry

    For WSL / Ubuntu users hitting this class of memory growth, I posted a containment workaround here: #18041 (comment)

    Short version: use the VS Code extension setting chatgpt.cliExecutable to point at a wrapper that launches the bundled native Codex binary through systemd-run --user --scope with MemoryMax / MemorySwapMax.

    This does not fix the leak, but it prevents Codex from taking down the whole WSL VM or Linux desktop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLIIssues related to the Codex CLIbugSomething isn't workingcontextIssues related to context management (including compaction)performance

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions