It depends on where Codex runs: the CLI and desktop-app chats stop when the lid sleeps the Mac, while Codex Cloud keeps going.
Clamshell for Mac keeps the Mac awake with the lid closed while armed. No sudo, no monitor. Free for 7 days, then $9.99 once.
Download free trialIt depends on where Codex is running. The Codex CLI and Codex chats in OpenAI's desktop app work on your Mac, so they stop making progress when a closed lid puts the Mac to sleep. Codex Cloud tasks run in OpenAI's cloud and keep working while your computer sleeps, so they need nothing from your Mac. To keep a local Codex run going with the lid closed and no external monitor, use Clamshell for Mac, a menu bar app that keeps an Apple Silicon MacBook awake with the lid shut and restores normal lid sleep when you disarm it.
Quick answer
Codex CLI
OpenAI describes it as a coding agent that runs locally on your computer. Lid sleep pauses it, including codex exec scripts.
Codex in the desktop app, and Remote from your phone
The work runs on the host computer. OpenAI's docs say remote access stops if that computer sleeps or loses network access.
Codex Cloud
Each task has its own cloud workspace and, per OpenAI, can keep working while your computer is asleep. Closing the lid does not affect it.
Local run, lid closed, no monitor
Arm Clamshell before you close the lid, or use sudo pmset -a disablesleep 1 and remember to undo it.
Which Codex are you running?
"Codex" covers several products that execute in different places. Only the ones that execute on your Mac care about the lid.
| Surface | Runs on | Stops on sleep? | What to do |
|---|---|---|---|
Codex CLI: codex, codex exec |
Your Mac | Yes | Keep the Mac awake with the lid closed |
| Codex in the desktop app, local project | Your Mac | Yes | Same as the CLI |
| Remote from the ChatGPT phone app | The connected host computer | Yes, remote access stops until the host is available again | Keep the host awake and online |
| Codex Cloud | A cloud workspace per task | No | Nothing on the Mac; review the result later |
If your repository is already set up for Codex Cloud, sending the overnight task there is the simplest fix: nothing on your laptop has to stay awake. Keep reading if the job needs your local files, tools, credentials or hardware.
Why a local Codex run stops at lid close
- You close the lidmacOS starts lid sleep, separate from idle sleep.
- Nothing blocks itA busy agent does not, and neither does
caffeinate. - Codex stops making progressChild processes, test runners and connections stop too.
Closing a MacBook lid triggers lid sleep, which is separate from idle sleep. An agent that is busy writing code or running tests does not block lid sleep, and neither does caffeinate: it only holds off idle sleep. Once the Mac is asleep, Codex, its child processes, test runners and network connections all stop making progress. Whether the session resumes cleanly on wake depends on what it was doing; the hours in between are lost either way.
OpenAI's desktop app has a Keep this Mac awake setting for Remote hosts, which it describes as preventing sleep when the computer is plugged in and remote access is enabled. OpenAI's own guidance is that a Mac laptop host stays available with the lid open and power connected, and that with the lid closed you should connect an external display as well. That leaves one case uncovered: lid closed, no monitor.
Ways to run Codex locally with the lid closed
- Apple's closed-display mode. Connect an external display, keyboard and mouse, and power. Apple's instructions for a closed-lid laptop say it must be connected to power and using an external keyboard and mouse. Reliable if you own the hardware and stay at your desk.
sudo pmset -a disablesleep 1. Keeps the Mac awake with the lid closed, but it is a global, admin-level switch with no timer that also applies on battery. See what pmset disablesleep does and how to undo it.- Clamshell. A menu bar app that overrides lid sleep only while armed. No sudo, no admin rights, no kernel extension, no privileged helper. It uses the unprivileged IOKit clamshell sleep control rather than
pmset, and the setting never survives a restart.
Clamshell for Mac keeps an Apple Silicon MacBook awake with the lid closed, no monitor needed. Free for 7 days, then $9.99 once for one Mac.
Download free trialWrap a Codex CLI run so it arms and disarms Clamshell
Clamshell accepts clamshell://arm, clamshell://disarm and clamshell://toggle URLs. This wrapper requests arming before a non-interactive Codex run and requests disarming when the shell exits, so normal lid sleep comes back when the job ends.
set -e
open "clamshell://arm"
trap 'open "clamshell://disarm" || true' EXIT
# codex exec is read-only by default; allow edits in the workspace
codex exec --sandbox workspace-write "run the test suite and fix the failures" \
2>> codex-progress.log | tee codex-result.md
Read the caveats before you rely on it:
openonly delivers a request. A successful exit does not prove Clamshell armed. It can refuse, for example under serious thermal pressure, or pause while an external display is connected. Check the menu bar state before closing the lid.- The EXIT trap is best effort. It does not run if the shell is killed or crashes. Disarm from the menu if in doubt.
- Clamshell does not know about Codex. It has no Codex integration and does not detect when an agent finishes. The script is what ends the session.
- Permissions still apply. OpenAI documents that
codex execruns in a read-only sandbox unless you choose a wider one. Pick the least access the job needs; keeping the Mac awake does not approve anything. - Setapp edition. The Setapp build uses the
clamshell-setapp://scheme instead.
Clamshell also adds Arm, Disarm, Toggle and Status actions to Shortcuts, which you can combine in a shortcut of your own.
Prove that Codex keeps working with the lid closed
Before trusting a long run, spend two minutes on a harmless check.
- In an interactive Codex session, with the lid open, ask Codex to run this command and approve it:
for i in {1..12}; do date -u '+%Y-%m-%dT%H:%M:%SZ' >> lid-check.txt sleep 10 done - Confirm Clamshell is armed and close the lid for the two minutes.
- Open it and run
cat lid-check.txt. Pass: twelve timestamps about ten seconds apart with no gap while the lid was shut.
Fail: a long gap means the run was interrupted; it does not tell you why. Check Clamshell's state, the terminal, and whether Codex was waiting for an approval, fix it with the lid open, and repeat.
If you use Remote from the ChatGPT phone app, do the same check from your phone: after two minutes with the lid closed, ask Codex for the file contents and one fresh timestamp. A connected indicator on its own is not a pass.
Steering a local Codex run from your phone
OpenAI's Remote feature lets the ChatGPT app on iOS or Android control Codex chats on a connected Mac or Windows computer running the ChatGPT desktop app. You set it up from the desktop app, not from the Codex CLI or IDE extension. From the phone you can start or continue chats, answer questions, approve commands and review diffs and test results. The host must stay awake, online and signed in.
Clamshell's part is narrow: with the lid closed, it keeps the host Mac from lid sleep so Remote has something to connect to. It does not make a sleeping Mac reachable, repair a dropped connection, or answer approval prompts on your behalf.
What Clamshell does and does not do
Keeps the lid from sleeping
Keeps an Apple Silicon MacBook on macOS 14 or later awake with the lid closed, with the built-in display dark, and locks the Mac when you open the lid.
Watches heat
Watches macOS thermal pressure at all times. At serious or critical pressure it disarms toward normal lid sleep and blocks arming until the Mac cools.
Handles power changes
Works on battery and on power, and re-applies itself when you plug in or unplug. An optional Disarm on low battery threshold is off by default.
Does not manage Codex
It does not detect Codex, stop when a task finishes, keep the network up, or move work to the cloud.
Arming with Option held while you close the lid needs the lid angle sensor in a MacBook Air M2 (2022) or later or a 14-inch or 16-inch MacBook Pro (2021) or later; other Apple Silicon laptops arm from the menu bar. Option-close sessions end when you open the lid; menu and URL arming stays on until you disarm.
Frequently asked questions
Does Codex keep running when I close my MacBook lid?
Codex Cloud tasks do, because they run in OpenAI's cloud. Codex CLI and local desktop app runs do not: closing the lid puts the Mac to sleep and pauses them, unless an external display setup, pmset disablesleep, or a lid-sleep tool such as Clamshell keeps the Mac awake.
Does caffeinate keep Codex running with the lid closed?
No. caffeinate prevents idle sleep only. Lid-close sleep is a separate path that caffeinate does not block, so a local Codex run still pauses when the lid closes.
Does the Keep this Mac awake setting in the ChatGPT desktop app cover a closed lid?
Not on its own. OpenAI describes that setting as preventing sleep when the computer is plugged in and remote access is enabled, and its docs say that with a Mac laptop lid closed you should also connect an external display.
Do I need to keep my Mac awake for Codex Cloud tasks?
No. OpenAI says each Codex Cloud task has its own workspace and can keep working while your computer is asleep. You only need the Mac to review or pull the result later.
Does Clamshell stop automatically when Codex finishes?
No. Clamshell does not detect Codex or any other agent. To end the session when a job ends, wrap the job in a script that opens clamshell://disarm on exit, or disarm from the menu bar.
Can Codex keep running on battery with the lid closed?
Yes, if the Mac stays awake. Clamshell works on battery, and you can enable Disarm on low battery so the Mac goes back to normal sleep below a charge level you choose. For long runs, plug in and keep the Mac on a ventilated surface.
Related guides
- Run AI coding agents overnight on a MacBook
- Keep Claude Code running with the lid closed
- Keep a MacBook awake with the lid closed on battery
- Why caffeinate does not work with the lid closed
- Compare Clamshell, Amphetamine, pmset and Apple's setup
Sources checked September 29, 2026: the openai/codex README, OpenAI's Codex Cloud, Remote connections and non-interactive mode docs, and Apple's external display guidance for a closed laptop. Clamshell behavior is described from its app source and FAQ. No new hardware testing was done for this page. Clamshell is an independent app, not affiliated with or endorsed by OpenAI. Codex is a trademark of its owner.