How to keep Codex CLI running overnight on a Mac

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.

Why this happens

macOS doesn't know Codex is still working.

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.

The free way

You can fix this for free right now.

If you only run Codex overnight occasionally, a free tool is a completely reasonable choice — no need to install anything else.

  1. Run 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.
  2. Or install Amphetamine from the Mac App Store — free, lets you trigger keep-awake when a process is running, with a manual allowlist you set up yourself.
  3. Turn off "Prevent automatic sleeping" in Energy Saver settings — works, but it also keeps the Mac awake when Codex isn't running at all, which is worse for your battery and your fans than either option above.

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.

If you run Codex a lot

What AgentBarista does differently for Codex CLI.

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.

Knows it's Codex, specifically

Detects the Codex CLI process directly, not "any terminal with activity" — so it doesn't keep your Mac awake for an unrelated tab.

Stays awake through thinking time

Codex waiting on a model response looks idle to macOS. AgentBarista still counts that as "working" and keeps sleep off through it.

Lets go when it's done

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.

Private by design

What it actually looks at.

Pricing

14-day free trial, then keep it for good.

One-time purchase
$19 once
  • 14-day free trial, no card needed
  • Codex CLI + every other supported agent
  • 1 year of updates included
  • Lifetime option: $39 once, updates forever
Get notified at launch

Not live yet — leave your email and we'll ping you the moment it is.

See full pricing, including Team plans →

More agents

Also running Cursor, Gemini CLI, or another agent?

Same Mac-goes-to-sleep problem, different tool. Each of these guides covers the fix for that agent specifically: