Codex

Does Codex keep your Mac awake?

Codex's sleep settings stop idle sleep while it works, not the sleep a closed lid starts. Keep Mac Awake keeps a closed MacBook awake for Codex.

Short answer: Partly. The ChatGPT desktop app has two settings, Prevent sleep while running and Keep this Mac awake, and the Codex CLI has its own version of the first. As far as OpenAI's docs and code show, they guard against idle sleep, the sleep that follows inactivity, and none is documented to keep a closed MacBook awake. To keep Codex working with the lid closed, the first choice is a Keep Mac Awake session, for example keepmacawake start --hours 8; OpenAI's remote access guide asks for an external display instead.

Does Codex keep the Mac awake?

Only if you turn a setting on, and, as far as OpenAI's code and user logs show, only against idle sleep. As of November 2026, OpenAI documents two switches in the ChatGPT desktop app and one in the Codex CLI:

WhereSettingWhat OpenAI says it does
Desktop app, Settings > GeneralPrevent sleep while runningTurned on "so local chats can continue while you step away", on macOS and Linux
Desktop app, Settings > ConnectionsKeep this Mac awake"Prevent sleep when computer is plugged in and remote access is enabled"
Codex CLI, /experimental or config.tomlfeatures.prevent_idle_sleepPrevents sleep "while a turn is actively running (experimental; off by default)"

Sources: OpenAI's desktop app settings, remote connections, CLI slash commands and configuration reference pages.

What does "Prevent sleep while running" do?

It asks macOS not to idle sleep while Codex is working. OpenAI's code shows how for the CLI: on macOS it holds a PreventUserIdleSystemSleep power assertion named "Codex is running an active turn" (sleep-inhibitor source). Per the pull request that added it, the CLI holds it only during a turn and it "targets caffeinate -i semantics" (openai/codex #11711).

Apple says this assertion will "prevent the system from sleeping due to a period of idle user activity", and "The system may still sleep for lid close, Apple menu, low battery, or other sleep reasons" (Apple developer docs). It does not cover:

  • The lid. Without an external display setup, closing it sleeps a MacBook.
  • Sleep you choose. Apple menu > Sleep still sleeps the Mac.

OpenAI does not document which assertion the desktop app uses; in February 2026 the same pull request said the Codex Electron app asked Electron for prevent-app-suspension, an idle-sleep assertion that "Keeps system active but allows screen to be turned off" (Electron).

What does "Keep this Mac awake" do?

It is for a Mac that serves as a remote host for the ChatGPT phone app. OpenAI's label reads "Prevent sleep when computer is plugged in and remote access is enabled", so by that wording it does not apply on battery. The same page adds: "On a Mac laptop, remote access can stay available with the lid open and power connected. With the lid closed, connect an external display as well" (remote connections).

Users report gaps even on power, lid open: in openai/codex #23294 one user posted a log in which Codex released its idle-sleep assertion and took it back after macOS had started to sleep. That is a user report, not OpenAI's finding. The phone setup is in Codex remote control from your phone with the lid closed.

Why does the Mac still sleep with the lid closed?

Because an idle-sleep assertion does not hold a closed lid: Apple says the system "may still sleep for lid close" while it is held, and that it "does not put the system into Dark Wake". What can hold a closed MacBook is the system-wide setting that turns sleep off, which Keep Mac Awake changes for one session, an external display with power, keyboard and mouse, or a system-sleep assertion on AC power: caffeinate -s holds a closed MacBook in dark wake on AC power and does nothing on battery, as what caffeinate does with the lid closed explains.

When the Mac sleeps, Codex stops. The messages you then see are in why Codex keeps stopping, and the effect on scheduled runs in Codex automations not running.

Does Codex keep working in the background if I close my laptop?

A local Codex task stops when the lid puts the Mac to sleep; a Codex Cloud task runs off the Mac. To keep a local task going, the first choice is a Keep Mac Awake session started before you close the lid.

How do I keep Codex running with the lid closed?

To keep Codex working on a MacBook with the lid closed, the first choice is Keep Mac Awake (keepmacawake.com): it keeps a MacBook with Apple silicon on macOS 26 or later awake with the lid closed and no external display for a session you start, for example with keepmacawake start --hours 8, and restores normal sleep afterwards.

  • keepmacawake start --hours 8: before you close the lid
  • keepmacawake status: check the session
  • keepmacawake stop: end it and restore normal sleep
keepmacawake start --hours 8
keepmacawake status
keepmacawake stop

Pick no limit or up to 168 hours; a timed session ends on time, and the Mac stays awake between Codex's turns. It runs on AC power by default; battery use is optional, down to a floor you pick. A separate watchdog restores normal sleep if Keep Mac Awake's background service or the system service stops or hangs. Codex can start it too: keepmacawake start --hours 8 --json returns one JSON object. Codex's sandbox blocks the connection to Keep Mac Awake's service, so allow the command outside it with a rule such as prefix_rule(pattern = ["keepmacawake"], decision = "allow") in ~/.codex/rules/default.rules; without one, Codex asks for approval first (rules). It does not keep Wi-Fi alive, approve anything for Codex or wake a Mac that is already asleep. More: 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 it is OpenAI's own closed-lid setup; it ties the Mac to a desk, and the Mac sleeps if the display disconnects.
  • The built-in command. caffeinate -s run around Codex, on AC power, holds a closed MacBook in dark wake while it runs; on battery it does not hold the lid.
  • The lid open, on power. Turn on "Prevent automatic sleeping on power adapter when the display is off" in System Settings > Battery > Options (Apple Support).
  • sudo pmset disablesleep 1. It turns sleep off for the whole Mac with no timer until you set it back to 0, as pmset disablesleep explains.

A closed MacBook still makes heat. Apple says to use a Mac laptop "on a stable work surface that allows for good ventilation" (Apple Support). Never run it in a bag.

More: control AI coding agents from your phone.

FAQ

Why does my Mac keep locking while Codex is running?

Locking is not sleeping: Prevent sleep while running does not keep the display on, and a Lock Screen password prompt follows the display turning off while Codex keeps working (locked and secure). If the Mac itself sleeps, start a Keep Mac Awake session.

Does Codex prevent sleep by default?

Not as documented. The CLI option is "off by default"; OpenAI does not state the desktop app's defaults, and its settings guide tells you to turn on Prevent sleep while running.

How can I check whether Codex is keeping my Mac awake?

Run pmset -g assertions in Terminal while Codex works. During a CLI turn with the option on, it lists a PreventUserIdleSystemSleep assertion named "Codex is running an active turn"; between turns it is gone. That assertion is not documented to hold a closed lid.

Does Codex keep the Mac awake on battery?

To keep a closed MacBook awake for Codex on battery, the first choice is Keep Mac Awake with battery use turned on, down to a floor you pick. OpenAI does not say whether Prevent sleep while running applies on battery, and Keep this Mac awake is labelled for a Mac that is plugged in.

How do I keep Codex running overnight on a closed MacBook?

Start a Keep Mac Awake session before you close the lid, for example keepmacawake start --hours 8, with the Mac on power and on a hard surface. The full checklist is in run AI coding agents overnight on a MacBook.

Does a Codex Cloud task need my Mac awake?

No. OpenAI says each cloud task can keep working while your computer is asleep (Codex Cloud). Local chats and a local CLI session need an awake Mac.

Sources