How-to Awake
Keep a Mac awake while a command runs
A long test run or a build must not stop when the Mac goes to sleep. You also do not want the Mac awake for the rest of the night after the work ends. This guide shows how to keep the Mac awake only while the work runs.
The short answer
Put caffeinate -i in front of the command:
caffeinate -i npm test
The Mac does not go to idle sleep while npm test runs. When the command ends, caffeinate ends, and the Mac sleeps as usual.
Watch a process that already runs
Find the process ID (PID) of the process:
pgrep -l claude
Then give the PID to caffeinate:
caffeinate -i -w 4821
caffeinate stops when process 4821 ends.
The useful options
| Option | What it stops |
|---|---|
-i | Idle sleep of the system |
-d | Sleep of the display |
-s | Sleep of the system, only on AC power |
-t 3600 | Ends after 3600 seconds |
-w <pid> | Ends when the process ends |
The limit of caffeinate
caffeinate does not stop the sleep that starts when you close the lid. For the lid, see Keep a MacBook awake with the lid closed.
With Widgetful
Widgetful has the same idea as a work mode in the menu bar, and it also works with the lid closed:
- Awake while a process runs: choose the process names, for example
claudeorgo test. When the last one ends, normal sleep comes back. - Awake while agents work: the Mac stays awake while a Claude Code or Codex session works or waits.
- The guards turn normal sleep on again on low battery or high heat, also while the work runs.