It depends on where Codex runs: the CLI and desktop-app chats stop when the lid sleeps the Mac, while Codex Cloud keeps going. For local runs, Clamshell, a Mac menu bar app, keeps the Mac awake with the lid closed, with no sudo and no external display.
An animated MacBook with a coding agent deploying a website from its terminal. The Option key is held and the lid closes: the display goes black, but the Mac stays awake, so a dimmed copy of the terminal keeps working above the closed laptop while its front edge fills with light. When the deploy is done, a pointer shows how to lift the lid. Opening it wakes the Mac to its lock screen, which unlocks to the finished run: deployed, with the live address. The lid can then be opened and closed freely.
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.
Apple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or install with Homebrew: brew install --cask clamshell. On your phone? Send the Mac download link to yourself.
Does Codex keep running if I close my laptop?
Only Codex Cloud tasks do, because they run on OpenAI's servers. Codex CLI and desktop app runs happen on your Mac, so closing the lid sleeps the Mac and pauses them. To keep a local run going with the lid shut, keep the Mac awake with an external display setup, sudo pmset -a disablesleep 1, or a lid-sleep app such as Clamshell. The Codex "Keep this Mac awake" setting does not cover a closed lid.
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.
Keep a local Codex run going with Clamshell for Mac in three steps
- Install Clamshell for Mac. Download the free trial from clamshell.dev, or run
brew install --cask clamshell, then open it once. It runs in the menu bar. - Arm it. Right-click the menu bar icon to arm until you turn it off, or press both Option keys to arm for the next close only. Open the menu and check that it says Armed or Armed for Next Close. A next-close session ends when you open the lid, so after the two-minute check below, arm again before the real run.
- Start the Codex run, then close the lid. Start
codexorcodex execin Terminal, or a local chat in the desktop app, and approve what it needs while you can see the screen. Then close the lid. The run continues on this Mac with the built-in display black. Disarm when it finishes.
Clamshell for Mac is an app, not Apple's clamshell mode (which needs an external display); it is closed source and costs $9.99 once after a 7-day trial. Clamshell for Mac is available only from clamshell.dev, on Setapp and through Homebrew. It is not on the Mac App Store; App Store apps named Clamshell are from other developers.
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.
For local work, OpenAI's long-running work docs point to a second setting, Prevent sleep while running in Settings, General, which the app describes as keeping the computer awake while it is running a task. It holds off idle sleep with the lid open; like any app's keep-awake, it cannot stop the sleep a closing lid causes. More on goals and scheduled tasks in Codex Goal mode with the lid closed.
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 keeps the Mac awake with the lid closed only while armed. No sudo, no admin rights, no kernel extension, no privileged helper. Normal lid sleep returns when you disarm or quit, and a restart does the same.
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.
Apple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or install with Homebrew: brew install --cask clamshell. Also on Setapp.
Wrap 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
open only sends a request, so check the menu bar shows armed before the lid goes down.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. 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. Its core does not detect when an agent finishes; that takes an optional agent module. 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 stays armed when you plug in or unplug. Disarm on low battery is on by default and acts at 20%.
Does not manage Codex
Its core does not detect Codex or stop when a task finishes, and it does not keep the network up, or move work to the cloud.
Arming with Option held while you close the lid needs a lid angle sensor, which the 14-inch and 16-inch MacBook Pro (2021 and later) and some newer MacBook Air models have; the M1 MacBook Air and the 13-inch MacBook Pro don't. Any supported MacBook can arm by pressing both Option keys or from the menu bar. Option-close and menu bar menu arming cover the next lid close only; right-click and Shortcuts arming stay 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?
Not by default. Clamshell's core does not detect Codex or any other agent; its optional Finish Work, Then Sleep module lets agents finish before the Mac sleeps. 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 Disarm on low battery, on by default, sends the Mac back to normal sleep when the battery reaches 20%. For long runs, plug in and keep the Mac on a ventilated surface.
Related guides
- Clamshell vs Macchiato
- Does Codex Goal mode keep running with the lid closed?
- Codex Locked use with the lid closed
- Arm Clamshell from Claude Code hooks
- How to keep a MacBook awake with the lid closed
- Best apps to keep a MacBook awake, lid closed or open
- Use Codex from your phone with the lid closed
- Run AI coding agents overnight on a MacBook
- Keep Claude Code running with the lid closed
- Keep a Cursor agent 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
- Why Codex "Keep this Mac awake" stops at a closed lid
- Claude Code cloud vs local on your Mac
- Computer use and iOS Simulator with the lid closed
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.