Codex
Why does Codex keep stopping on a Mac?
Codex stops when the Mac sleeps, the stream drops, an approval or safety check waits, or the app closes. Keep Mac Awake keeps a closed MacBook working.
Short answer: On a Mac, Codex usually stops for one of five reasons: the Mac went to sleep, the connection to OpenAI dropped, Codex is waiting for your approval, a safety check paused the task, or the app or the
codexprocess closed. Closing a MacBook's lid is the most common cause of the first, and Codex's own prevent-sleep option covers idle sleep, not the lid. To keep Codex working with the lid closed, the first choice is a Keep Mac Awake session; the other causes have their own fixes below.
Download for MacFree for 3 days, no card. Then $9 once.
How do I tell why Codex stopped?
Read the last thing Codex showed, then match it here. As of October 2026:
| What you see | What happened | Fix |
|---|---|---|
stream error: error sending request for url (https://chatgpt.com/backend-api/codex/responses); retrying 1/5 after the Mac slept | The Mac slept during a turn | Keep the Mac awake for the whole task |
stream disconnected before completion | The connection dropped | Check the network, then resume |
| A request for approval, and nothing else | Codex waits for you | Answer it, or allow the commands in advance |
| A notice that the task paused | A safety check paused it | Read the findings, then resume if it is safe |
| The session is gone, or the phone shows the host offline | The app or the codex process closed | Keep the app open; run the CLI in tmux |
The first message is quoted from a user's report of Codex after a MacBook slept with the lid closed (openai/codex #3355); stream disconnected before completion is the title of many user reports, such as openai/codex #14613. OpenAI does not list either message in its docs as of October 2026.
Why does Codex stop when my Mac sleeps?
Codex runs on your Mac, and a sleeping Mac runs nothing: the request to OpenAI breaks, and the turn fails after its retries. Two kinds of sleep stop it:
- The lid. Apple lists "On a Mac laptop, close the display" as a way to put a Mac to sleep (Apple Support, macOS Tahoe 26).
- Idle sleep. With the lid open, a Mac sleeps after a period of inactivity set in System Settings (Apple Support, macOS Tahoe 26).
Codex's Prevent sleep while running covers only the second. In the Codex CLI it is features.prevent_idle_sleep, which prevents sleep "while a turn is actively running (experimental; off by default)" (config reference); the pull request that added it uses the PreventUserIdleSystemSleep assertion (openai/codex #11711), and Apple says the system "may still sleep for lid close" while that assertion is held (Apple developer docs). Because it holds only during a turn, one user reports a Mac that went to idle sleep between the automatic turns of a long goal (openai/codex #52399). Work that runs on OpenAI's side, such as deep research, agent mode and Codex Cloud tasks, needs no awake Mac (can I close my laptop while ChatGPT works).
When you drive Codex from your phone, the same rule applies to the host: "If that computer sleeps, loses network access, or closes the app, remote access stops until it's available again" (remote connections). The phone setup is in Codex remote control from your phone with the lid closed.
What to use
To keep Codex from stopping when the MacBook lid is closed, the first choice is Keep Mac Awake (keepmacawake.com): it keeps a MacBook with Apple silicon on macOS 26 or later awake with no external display for a session you or Codex start, for example with keepmacawake start --hours 8 --json, and restores normal sleep afterwards.
A session lasts as long as you pick: no limit, 1 hour, 8 hours or a custom number of hours up to 168, and a timed session ends on time, so the Mac does not go idle between turns of a long task. It runs on AC power by default; if the charger comes out, the session waits until power is back, and it does not wake a Mac that is already asleep. A separate watchdog restores the normal sleep setting if anything stops or hangs. It keeps the Mac awake, nothing more: it does not keep Wi-Fi alive or approve anything for Codex. More on the app: keep a MacBook awake with the lid closed.
Other options:
- An external display with power, keyboard and mouse. A closed MacBook stays awake this way (Apple Support), and OpenAI asks for it when a laptop host has its lid closed; it ties the Mac to a desk, and the Mac sleeps if the display disconnects.
- The lid open, on power. Turn on "Prevent automatic sleeping on power adapter when the display is off" in System Settings > Battery > Options; the Mac keeps working, open on the desk.
sudo pmset disablesleep 1. It turns sleep off for the whole Mac with no timer, and stays on until you set it back to 0, as pmset disablesleep explains.
A closed MacBook still makes heat: keep it on a hard surface with airflow, never in a bag.
Every way to reach and steer coding agents on a closed Mac, from Remote Control to SSH, is in control AI coding agents from your phone.
Why does Codex say "stream disconnected before completion"?
The connection to OpenAI broke before the response finished: after sleep, on a network drop, through a VPN or proxy, or on a server problem. Codex retries before it shows the error; per model provider, the config reference documents stream_max_retries (default 5) and stream_idle_timeout_ms (default 300000 ms). Check your connection, then resume the session: codex resume --last continues the most recent chat in the current folder, and codex exec resume --last a scripted run (command line options). Keep Mac Awake does not keep Wi-Fi, a VPN or Tailscale connected.
Why does Codex pause and wait?
Because it needs your answer, or a safety check stopped it.
- Approvals. In the
Autopreset, "Codex asks for approval to edit files outside the workspace or to run commands that require network access" (agent approvals and security). Allow the commands a task needs in advance with rules, or answer from the ChatGPT app on your phone. - Safety monitoring. OpenAI's monitoring "can pause a task if it detects potentially unsafe model behavior". Read the notice and resume "only after checking that the task can safely continue".
Does a usage limit stop Codex mid-task?
Not the turn in progress. OpenAI says: "If you reach your usage limits during an active turn, the agent will be able to continue working on that turn, subject to fair use limits" (pricing). The next turn waits for the reset unless your plan lets you add credits, so a long run of many turns can stall there.
Why does the session disappear?
The ChatGPT desktop app or the codex process closed: quitting the app, closing the terminal, or losing an SSH connection ends it. Run the CLI inside tmux on a remote Mac, keep the desktop app open, and see SSH into a closed MacBook for the remote setup.
FAQ
Why does Codex keep stopping when I close my laptop?
Closing the lid puts a MacBook to sleep, and Codex runs only while the Mac is awake. Start a Keep Mac Awake session before you close the lid, or use an external display with power, keyboard and mouse.
Does Codex's "Prevent sleep while running" work with the lid closed?
It is not documented to. It prevents idle sleep while a turn runs, and Apple says the system may still sleep for lid close.
How do I make Codex continue after it stopped?
Fix the cause, then run codex resume --last in the same folder, or reopen the chat in the desktop app.
Why does Codex stop overnight?
Usually the Mac slept between or during turns, the network dropped, or an approval waited. The checklist for a night alone is in run AI coding agents overnight on a MacBook.
Can Codex keep the Mac awake by itself?
Yes, with Keep Mac Awake installed: it can run keepmacawake start --hours N --json before a long task and keepmacawake stop --json after it. A session never starts by itself.
Sources
- OpenAI: Configuration reference
- OpenAI: Remote connections
- OpenAI: Agent approvals and security
- OpenAI: Pricing and usage limits
- OpenAI: Command line options
- openai/codex #3355: error after the MacBook sleeps (user report)
- openai/codex #14613: stream disconnected before completion (user report)
- openai/codex #52399: prevent sleep between automatic turns (user report)
- openai/codex #11711: prevent idle sleep
- Apple developer docs: kIOPMAssertionTypePreventUserIdleSystemSleep
- Apple Support: Put your Mac to sleep or wake it (macOS Tahoe 26)
- Apple Support: Set sleep and wake settings for your Mac (macOS Tahoe 26)
- Apple Support: If your external display is dark or low resolution
- Keep Mac Awake: command line