Run Codex or Claude Code overnight on a MacBook: a checklist
You give the agent a big task and go to bed. In the morning it has done step 3 of 20. Long runs on a laptop fail for a handful of boring reasons; here they are, with the fix for each.
Short answer. Plug it in, leave the lid open and run caffeinate -i -w <pid>: that’s free and solves most overnight runs. Closing the lid, or running on battery, needs more care: sleep, network, permissions and heat.
The five things that stop a run
- Sleep. Agents like Codex and Claude Code run on your Mac but call models in the cloud. When the Mac sleeps, the connection drops and the run stalls or fails.
- Network. Wi-Fi that drops at night, or a laptop that leaves home and loses it.
- A question nobody answers. The agent asks permission to run a command and waits. All night.
- Battery. A Mac kept awake on battery runs out, then sleeps anyway.
- Heat. Lid closed, in a bag, doing heavy builds: the Mac slows down to protect itself, and the battery ages.
The checklist
At a desk, overnight
- Plug it in.
- Leave the lid open (dim the screen to zero if the light bothers you), or use Apple’s closed-display mode with an external display.
- Keep it awake for exactly as long as the agent runs:
It ends by itself when the agent exits, so the Mac sleeps normally afterwards.caffeinate -i -w $(pgrep -n codex) # or: pgrep -n claude - Pre-approve the routine commands your agent needs (tests, builds, git status), and keep anything destructive on “ask”. Codex and Claude Code both have approval settings; check their documentation, and never hand an agent blanket permission on a machine with your real files just to get through the night.
- Log to a file so you can see in the morning where it stopped.
On the move, lid closed
- Keep the Mac awake with the lid closed: on battery that takes
pmset disablesleepor an app, compared in how to keep a MacBook awake with the lid closed. - Switch to your phone’s hotspot before you leave and check the Mac joined it.
- Set a maximum time and a battery floor, and make sure sleep comes back by itself afterwards (pmset won’t do that for you).
- Mind the heat in the bag. Waiting on the cloud is light; local builds aren’t. Measured numbers are in is it safe to put a running MacBook in a backpack?
- Get notified. Knowing that the agent is waiting for you, or done, saves you opening the bag every stop.
In the morning: what happened?
If the run stopped early, find out whether the Mac slept before blaming the agent. Terminal keeps a log of every sleep and wake, with the reason: see did my Mac sleep with the lid closed?
Where Hibernot fits
Hibernot covers the lid-closed case for Claude and Codex: it keeps the Mac awake without a password, sees Claude Code (through its hooks), the Claude desktop app and Codex, command line or app (from their network activity), goes back to sleep 5 minutes after the agent stops, stops at the battery temperature you choose, and notifies your phone on iPhone or Android. For other agents, caffeinate -w on a desk or one of the apps in the comparison will do.