Your Mac went to sleep mid-run and Codex CLI stopped with it — that's macOS, not Codex. The fix is to stop the Mac from sleeping while Codex is actually working, then let it sleep again shortly after it goes quiet — within your grace window, 90 seconds by default.
To keep your Mac awake while Codex CLI runs:
the free way is macOS's built-in caffeinate -i — run it in Terminal before you start,
and stop it yourself when the run ends. The automatic way is AgentBarista (14-day free trial,
then $19 one-time), which detects Codex working and lets your Mac sleep when the run finishes.
Codex CLI spends a lot of its time waiting on a model response, not burning CPU. macOS only looks at activity like keyboard input, mouse movement, and CPU load to decide whether to sleep — a quiet terminal sitting on a long Codex run looks exactly like an idle one. So your default sleep timer (or just closing the lid) cuts the process off mid-task, and you come back to a half-finished run or a dead SSH session.
This isn't a Codex bug. The same thing happens with Claude Code, Cursor, and any CLI agent that runs long and quiet. The fix has nothing to do with Codex itself — it's about keeping the Mac awake for the duration of the run, then giving sleep back immediately after.
If you only run Codex overnight occasionally, a free tool is a completely reasonable choice — no need to install anything else.
caffeinate -i alongside Codex — macOS's own built-in command. Open a
second terminal tab and run caffeinate -i before you start your Codex session; it
blocks idle sleep until you stop it (Ctrl+C) or close the tab.The catch with all three: none of them know what Codex CLI is. They keep the Mac awake whether or not anything is actually happening, and you have to remember to turn them off — or your battery pays for it overnight.
Codex CLI is one of the agents AgentBarista watches for out of the box. Instead of a blanket "stay awake" switch, it tracks whether Codex is actually doing something — CPU use from the Codex process and what's showing on screen — and only holds sleep off for that.
Detects the Codex CLI process directly, not "any terminal with activity" — so it doesn't keep your Mac awake for an unrelated tab.
Codex waiting on a model response looks idle to macOS. AgentBarista still counts that as "working" and keeps sleep off through it.
When the run finishes, normal sleep comes back within your grace window — 90 seconds by default — so your Mac isn't held awake all night for no reason.
It also won't run your battery dead while you're not looking:
a battery cutoff stops keep-awake below a threshold you set, and there's a one-command emergency
restore (./reset-sleep.sh equivalent in the app) if anything ever gets stuck. Free
tools don't do that part — that's the part you're paying for.
Not live yet — leave your email and we'll ping you the moment it is.
Same Mac-goes-to-sleep problem, different tool. Each of these guides covers the fix for that agent specifically: