Guide · October 2026

Keep your Mac awake while Codex CLI runs

Hand Codex a long task and walk away — even with the lid closed — and let the Mac sleep when it's done.

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.

Do it yourself

For a single run, wrap it: caffeinate -i codex exec "…" blocks idle sleep until the command exits. Closing the lid needs sudo pmset -a disablesleep 1, and you must set it back to 0 afterwards (it survives a restart).

With Lidnight

Turn on Codex in Settings › Agents 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.

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 7-day trial of everything in Pro, no payment details needed. Pro is a one-time payment (1 Mac $9.99 · 3 Macs $14.99, 50% off through Oct 31) with a 14-day refund.

Homebrew: brew install whereisdw/tap/lidnight