Codex spawning too many mcp instances and never kills them, memory is getting overwhelmed
Open 💬 6 comments Opened Mar 13, 2026 by VladimirBrejcha
💡 Likely answer: A maintainer (github-actions[bot], contributor)
responded on this thread — see the highlighted reply below.
What version of the Codex App are you using (From “About Codex” dialog)?
Version 26.311.21342 (993)
What subscription do you have?
Plus
What platform is your computer?
Darwin 25.3.0 arm64 arm
What issue are you seeing?
<img width="1063" height="942" alt="Image" src="https://github.com/user-attachments/assets/91d54f19-be6f-4377-86bf-9ca515c1de53" />
<img width="711" height="230" alt="Image" src="https://github.com/user-attachments/assets/0b7a14aa-234f-4461-9dcf-c974addb50c3" />
Codex is spawning more and more MCP server instances. Maybe it's subagents, maybe not.
Anyways, they are spawned and never killed, taking all the memory.
What steps can reproduce the bug?
Uploaded thread: 019ce516-facd-7543-bebd-44a8abf7b5df
What is the expected behavior?
_No response_
Additional information
_No response_
6 Comments
Potential duplicates detected. Please review them and close your issue if it is a duplicate.
Powered by Codex Action
yeah, I make the same issue.. Can't work in multi-agent mode, 30 RAM + 20 Swap with 4 codex cli 🗡️ 💃
If you disable subagents (in experimental functions), everything will work. I recommend doing that for now; we're waiting for the openAI team to confirm the decision. @VladimirBrejcha
<img width="2032" height="1162" alt="Image" src="https://github.com/user-attachments/assets/94000664-b3f8-4d6e-b19e-7496632bdae2" />
this is getting too far
I even disabled subagents but that didn't really change a thing
Same build, same macOS, and not only subagents
@VladimirBrejcha i hit this on the exact same build and platform. @rldyourmnd mentioned multi-agent load, but on my side this also happened with ordinary conversations over time.
My setup
26.311.21342 (build 993)Darwin 25.3.0, Apple Silicon2.5 days18conversations/tasks in that timecontext7,playwright,chrome-devtools,webflow mcp-remote, custom Python MCPWhat the buildup looked like
So at least on my machine this was not just "subagents went wild". Each finished conversation was leaving a full MCP bundle behind.
I also tried the quit and reopen cleanup path. It killed most of the big pile, but not all of it:
The old survivors matched Codex sessions from
March 9, 2026andMarch 14, 2026.So for me this feels like a real lifecycle cleanup bug, not just a heavy RAM usage side effect. I also had active Claude Code sessions on the same machine and those cleaned up normally, so this did not look like a generic macOS resource issue.
I also agree with the framing from
#12333/#14233: i am not asking for one shared MCP instance for all active work. The bug is that finished work is not converging back to a sane baseline.I can reproduce the Linux CLI/job-control variant of this on the current stable CLI as well.
Environment
codex-cli 0.139.0zsh, running undertmux/PTY sessionsserena,playwright-mcp, andmcp-server-puppeteerReproduction
codex --dangerously-bypass-approvals-and-sandboxin a terminal.Ctrl+Z.ps -t <pts> -o pid,ppid,pgid,sid,tpgid,stat,etime,cmd.codexin the same shell before resuming the first one.Observed behavior
After
Ctrl+Z, the Codex wrapper/native processes are stopped, but the MCP child processes keep running in separate process groups:If I then start another
codexin the same shell, the PTY ends up with one stopped Codex process group plus one active Codex process group, while the old MCP server processes are still alive. This matches the accumulation pattern described here and in #16256, but on0.139.0rather than older CLI builds.The foreground process group also confirms the layering pattern: after starting the second Codex, the TTY foreground
TPGIDbelongs to the new Codex, while the previous Codex remainsTland its MCP children remainSl.Why this seems to happen
This looks like a process lifecycle/job-control issue rather than only subagent behavior.
SIGTSTPstops the Codex process group, but MCP stdio servers are spawned into independent process groups and are not stopped or torn down with the suspended session.Suggested direction
A robust fix probably needs MCP subprocess lifecycle management in the CLI/native side, for example:
SIGTSTP, either suspend/terminate the MCP process groups consistently before the parent stops, or make resume (SIGCONT) reconcile MCP state explicitly;For now, using
tmux detachinstead of terminalCtrl+Zavoids triggering this, because the Codex process is not suspended.