widgetful Try 7 days free Buy

How-to Awake

Keep a Mac awake while a command runs

Updated 16 November 2026

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

OptionWhat it stops
-iIdle sleep of the system
-dSleep of the display
-sSleep of the system, only on AC power
-t 3600Ends 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 claude or go 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.

Widgetful also does this