caffeinate and closed-lid MacBook
caffeinate helps idle sleep. Closed-lid work is a separate host mode.
For Claude Code, Codex, tmux, and local LLM jobs, separate open-lid idle sleep from lid-close sleep before trusting an unattended run.
Use caffeinate for open-lid idle
caffeinate can prevent idle sleep while the Mac is open or locked. Do not treat that as proof a closed lid will keep local work running.
Check the lid-close path
For a moving MacBook, test pmset, power source, network reachability, and whether timestamps keep changing after the lid closes.
Make it temporary
Closed-lid awake mode needs a clear off step. Restore defaults after the agent run and check heat before bag transport.
Receipt command
Prove the process kept moving after the lid closed.
Use this alongside any caffeinate and closed-lid MacBook script so you can tell whether the host actually stayed alive during the window.
while true; do date >> ~/caffeinate-closed-lid-test.log; sleep 30; done
The minimum closed-lid checklist.
- Idle vs lid-close: know which failure you are testing.
- Battery and heat: closed-lid battery runs can drain and warm up fast.
- Network: SSH, Mosh, Agent View, and notifications still need a reachable host.
- Receipt: timestamps, files changed, commands run, failures, and restored sleep defaults. For scheduled runs, use the Claude Code usage-window checklist.
Record the baseline
Write battery percent, power source, temperature/heat feel, network status, and the exact awake mode you enabled before closing the lid.
Keep proof outside Claude
A timestamp loop outside the agent tells you whether the Mac stayed awake or only resumed later with the terminal still open.
Restore before transport
Recheck battery and heat, stop awake mode, restore normal sleep settings, then leave the receipt before putting the MacBook in a bag.
Make the battery-lid test auditable.
Use this before trusting a MacBook to keep a local agent alive with the lid closed.
Run a closed-lid battery acceptance test for this Mac. Record start time, battery percent, power source, thermal state, Wi-Fi/SSH reachability, pmset assertions, and a heartbeat file outside the agent. Close the lid for a short window, reopen, confirm heartbeat timestamps kept moving, record end battery and heat, restore normal sleep settings, and leave a receipt. Stop if the machine gets hot, battery drops too fast, network dies, or restore is unclear.
Want Codex to handle the closed-lid mode?
Take A Coffee gives Codex a temporary awake mode, host checks, restore step, and receipt for local macOS and Windows agent work.
Does caffeinate work with the lid closed?
It prevents idle sleep in normal open-lid use. Lid-close behavior depends on macOS power settings, power source, thermal state, and hardware policy.
Why test with timestamps?
They prove the process kept moving during the closed-lid window, instead of only proving the session still exists after wake.
What should restore do?
Turn temporary awake settings off, report battery and heat state, and leave a short receipt so the next run starts from a known baseline.