Keep your Mac awake while Codex CLI runs
Hand Codex a long task and walk away without it stalling. Codex's own setting and the free caffeinate and pmset options, with their limits, come first; letting the Mac sleep when it's done comes after.
Lidnight stops runaway spend, silent approval stalls, and unexpected limit hits while you step away. Track Claude Code, Codex, Antigravity, Gemini and Kiro sessions, limits and cost, approve from your phone, and keep going with the lid closed.
Lidnight is a Mac app, so it can't be installed on this device. Open this address on your Mac to download it.
Copied. Paste it on your Mac to open it.
Couldn't copy. Tap the address below to select it, then copy.
Why it stops
Codex CLI runs in your terminal, so when the Mac sleeps the network drops, model requests fail and the run stalls. Macs sleep after a while without input (idle sleep), and immediately when you close the lid without an external display.
Codex's own setting: prevent sleep while running
Codex has a setting that prevents sleep while a turn is running. The config reference lists features.prevent_idle_sleep as “Prevent the machine from sleeping while a turn is actively running (experimental; off by default)”. Turn it on with codex features enable prevent_idle_sleep (it adds prevent_idle_sleep = true under [features] in ~/.codex/config.toml) and check it with codex features list. The Codex app also has a Prevent sleep while running option under Settings › General on macOS and Linux.
The docs don't say whether it also covers closing the lid. For lid-closed runs, combine it with the options below and test it yourself (check whether pmset -g log shows Clamshell Sleep).
Starting with Codex CLI 0.174.0 (checked 2026-12-04), Codex also includes codex agents (an Agent Command Center to switch sessions), codex queue (queueing follow-ups to a running session), a tabbed /status limit view, and experimental codex remote-control. All of these are Codex-only and do not handle lid-closed battery pmset control, 42°C/45°C thermal or battery cutoffs, or unified tracking alongside Claude Code, Kiro and Gemini.
Do it yourself
For a single run, wrap it: caffeinate -i codex exec "…" blocks idle sleep until the command exits (man caffeinate). Closing the lid needs sudo pmset -a disablesleep 1 (not in man pmset; check it with pmset -g | grep SleepDisabled), and you must set it back to 0 afterwards (it survives a restart).
While a run is going, pmset -g assertions in another terminal lists what is currently holding sleep off.
If you'd rather not toggle it yourself: Lidnight
Turn on Codex in Settings › AI setup and Lidnight adds Codex hooks (~/.codex/hooks.json), so it knows exactly when work starts and ends. The Mac stays awake with the lid closed while Codex works and sleeps 10 minutes after everything goes quiet. Your config is backed up first, and turning it off removes only Lidnight's entries.
Approve from your phone: when Codex asks to run a command or edit files while you're away (lid closed, or no input for 2+ minutes), you can allow or deny it from your phone or a Mac notification (Codex's PermissionRequest hook; risky commands stay Mac-only). Codex waits for approval hooks before showing its terminal prompt, so at the Mac Lidnight steps aside right away and you answer in the terminal as usual.
One more step: Codex doesn't run new or changed hooks until you review them. After connecting, open /hooks in Codex and trust the Lidnight hooks; the same applies to hooks you write yourself (Codex docs, “Review and trust hooks”). Until then Lidnight can only estimate from activity. If Codex hooks don't run
It also shows Codex's 5-hour and weekly limits and tokens in the menu bar, and tracks each session separately alongside Claude Code. It warns if the battery stays above 42°C for over a minute and sleeps at 45°C or at a battery floor you set.
Try Lidnight free
Apple Silicon Macs · macOS 13 or later. Every download includes a free trial of everything in Pro (14 days or 5 lid-closed runs of 10+ minutes, whichever comes first), no payment details needed. Pro is a one-time payment (1 Mac $9.99 · 3 Macs $14.99 USD, plus regional tax) with a 14-day full refund, no questions asked.
Lidnight is a Mac app, so it can't be installed on this device. Open this address on your Mac to download it.
Copied. Paste it on your Mac to open it.
Couldn't copy. Tap the address below to select it, then copy.