The setting was never meant to cover a closed lid: OpenAI's own docs say a closed MacBook also needs an external display. To keep Codex running lid-closed without a monitor, arm Clamshell for Mac before you close the lid.
Clamshell for Mac keeps the Mac awake with the lid closed while armed, so Codex keeps working. Free for 7 days.
Download free trialApple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or buy now, $9.99
The Codex desktop app's Keep this Mac awake setting lives under its remote connection settings and exists so the ChatGPT phone app can keep reaching your Mac. It is designed for a lid that stays open. Close the lid without a display attached and the Mac goes to sleep anyway, local Codex work stops making progress, and remote access from your phone stops until the Mac wakes. This guide shows which of three cases you hit and how to fix each one.
Why the Mac still sleeps: three cases
You closed the lid with no display attached
Expected behavior. OpenAI's remote connections docs say a Mac laptop stays available with the lid open and power connected, and that with the lid closed you should connect an external display as well. Lid-close sleep is separate from idle sleep, and the setting does not block it.
The Mac was on battery
OpenAI describes the setting as preventing sleep when the computer is plugged in and remote access is enabled. Unplugged, it does not apply, lid open or closed.
Lid open, plugged in, and it still slept
That matches openai/codex issue #23294, open as of October 2026: a Mac on power with an external monitor slept despite the setting. One commenter posted macOS logs showing Codex briefly releasing its sleep assertion right before the Mac began to sleep.
Codex disconnects on a hotspot with the lid closed
Issue #21703 reports the desktop app's separate Prevent sleep while running setting failing in that setup, also open as of October 2026. Closed-lid sleep is the first thing to rule out.
Keep Codex running with the lid closed
Use an Apple Silicon MacBook on macOS 14 or later, on a ventilated desk, preferably on power. Leave Keep this Mac awake on: it still covers idle sleep while the lid is open.
- Install Clamshell and open it once. It sits in the menu bar. No sudo, admin password, kernel extension or privileged helper is involved.
- Disconnect external displays. With a display connected, Clamshell pauses (yellow menu bar icon) instead of arming. It arms automatically once displays disconnect.
- Arm it. Choose arm from the menu bar menu, which covers the next close only. Or hold Option while you close the lid, on a MacBook Air M2 (2022) or later or a 14-inch or 16-inch MacBook Pro (2021) or later. Shortcuts and right-click arming stay active across reopenings until you disarm.
- Confirm the armed state, then close the lid. Open the menu and look for the Armed row before the lid goes down. A paused state is not armed.
If you start Codex jobs from a script, open "clamshell://arm" requests arming and open "clamshell://disarm" ends it. The request is asynchronous, so check the menu bar before closing the lid. The Codex lid-closed guide has a full codex exec wrapper.
What happens while the lid is closed
- The Mac stays online. Codex Remote, SSH and screen sharing can keep reaching it, as long as the network itself holds up.
- Agents can still use the screen. With the Let agents use the screen while the lid is closed setting on, which is the default, computer use and the iOS Simulator keep working in an armed lid-closed session while the built-in display stays black. Turn it off to sleep the display instead.
- Heat is watched. At serious or critical macOS thermal pressure, Clamshell disarms toward normal lid sleep and blocks arming until the Mac cools. It does not replace airflow, so do not run it in a bag.
- Battery has a cutoff if you want one. Clamshell works on battery, and the optional Disarm on low battery setting (off by default) lets the Mac sleep below a level you choose.
- Opening the lid locks the Mac. The display stays dark until the lock is confirmed. If Clamshell cannot confirm it, it restores the display and asks you to lock manually.
Clamshell does not know about Codex. It does not detect when a task ends, answer approval prompts, or keep a flaky connection alive. Before a long run, do the two-minute timestamp check in the Codex lid-closed guide.
Clamshell keeps your Mac awake with the lid closed. Free for 7 days, then $9.99 once for one Mac. 14-day money-back guarantee.
Download free trialOther ways to fix it
Connect an external display
OpenAI's documented setup for a closed lid. Apple's closed-display mode needs the Mac on power with an external keyboard and mouse as well. The better fit if you work at a desk with that hardware anyway.
Leave the lid open on power
Free and fully supported by OpenAI's docs: lid open, plugged in, Keep this Mac awake on. Fine at home, less so in a bag or on a shared desk.
Send the task to Codex Cloud
OpenAI says each cloud task has its own workspace and can keep working while your computer is asleep. The best fit when the job does not need your local files, tools or credentials.
Use sudo pmset -a disablesleep 1
Works with the lid closed, but it is a global admin switch with no timer, on battery too. See what pmset disablesleep does and how to undo it.
caffeinate and most keep-awake menu bar apps do not help here: they hold off idle sleep, not lid-close sleep. Why caffeinate does not work with the lid closed explains the difference.
Frequently asked questions
Why does my Mac still sleep with Codex Keep this Mac awake turned on?
The most common reason is a closed lid. OpenAI describes the setting as preventing sleep when the computer is plugged in and remote access is enabled, and its docs say a Mac laptop with the lid closed also needs an external display. On battery the setting does not apply. If the Mac sleeps with the lid open and power connected, that matches an open bug report on the openai/codex GitHub repository.
Does Codex keep running if I close my laptop?
Codex Cloud tasks do, because they run in OpenAI's cloud. Local Codex work in the desktop app or CLI stops making progress when a closed lid puts the Mac to sleep, unless an external display setup, pmset disablesleep, or a lid-sleep tool such as Clamshell for Mac keeps the Mac awake.
Can I keep Codex running with the lid closed without an external display?
Yes. Clamshell for Mac is a menu bar app that keeps an Apple Silicon MacBook awake with the lid closed and the built-in display black, without a monitor, sudo or admin rights. Arm it, confirm the armed state in the menu bar, then close the lid.
Should I turn off Keep this Mac awake if I use Clamshell?
No need. The two do not conflict. Keep this Mac awake covers idle sleep while the lid is open and the Mac is plugged in; Clamshell covers lid-close sleep while it is armed.
Does Clamshell detect Codex or start automatically?
No. Clamshell has no Codex integration and does not detect running agents. You arm it from the menu bar, with Option held while closing the lid on supported models, with Shortcuts actions, or with the clamshell://arm URL.
Will Codex Remote on my phone keep working with the lid closed?
Remote needs the host Mac awake and online. With Clamshell armed the Mac stays awake and on the network with the lid closed, so Remote can keep reaching it. Clamshell does not repair a dropped network connection or answer Codex approval prompts.
Related guides
- Keep Codex running when you close your MacBook lid
- Keep Claude Code running with the lid closed
- Run AI coding agents overnight on a MacBook
- Keep a MacBook awake with the lid closed on battery
- Clamshell mode without an external display
Sources checked October 5, 2026: OpenAI's Remote connections and Codex Cloud docs, openai/codex issues #23294 and #21703, and Apple's closed-display guidance. Clamshell behavior is described from its changelog and FAQ. Clamshell is an independent app, not affiliated with or endorsed by OpenAI. Codex is a trademark of its owner.