The macOS caffeinate command
Apple’s built-in caffeinate tool can temporarily prevent sleep without changing permanent settings. These examples cover the most useful everyday patterns.
Quick answer
Open Terminal, enter caffeinate, and keep the process running. macOS will create a sleep-prevention assertion until you press Control-C or close that Terminal process. For a timed session, use caffeinate -t 3600, where 3600 is one hour in seconds.
What caffeinate actually does
caffeinate uses macOS power-management assertions. An assertion tells the operating system that a particular kind of idle sleep should be delayed while work is in progress. It does not simulate keyboard input or move the pointer.
With no options, caffeinate creates an assertion for the lifetime of the command. It is temporary: your regular energy settings take over again after the process ends.
Useful examples
Prevent idle system sleep until you stop it
caffeinate
Leave Terminal open and press Control-C when finished.
Prevent idle sleep for one hour
caffeinate -t 3600
The -t timeout is in seconds. Two hours would be 7200 seconds.
Keep the display awake
caffeinate -d
The -d flag creates a display-sleep assertion. This consumes more energy than allowing the display to turn off, so use it only when the screen must remain visible.
Prevent idle system sleep explicitly
caffeinate -i
The -i option targets idle system sleep.
Run a command while preventing sleep
caffeinate -i your-command
The assertion remains while the child command runs. This is useful for a script, export, or other Terminal job. Use the real command and its arguments in place of your-command.
Choosing flags carefully
Other assertion types exist, and behavior can vary with power source, hardware, lid state, and system policy. Run man caffeinate in Terminal to read the manual installed with your version of macOS. That local manual is the best reference for the exact flags available on your Mac.
caffeinate does not keep every website, VPN, chat app, or remote session active. It addresses macOS sleep behavior; third-party services set their own idle and authentication rules.When an app is easier
The command is excellent for technical users and one-off jobs. A menu bar app is easier when you want a visible on/off state, frequent sessions, a countdown, or mouse movement. Mouse Sentinel adds periodic cursor movement and restarts its movement countdown around real activity.
How to confirm the session ended
If the Terminal prompt has returned after Control-C or the timeout has elapsed, that caffeinate process is no longer holding its assertion. You can also use Activity Monitor to look for a running caffeinate process. Normal macOS settings then apply again.
Prefer a visible Mac utility?
Mouse Sentinel gives you one-click controls, a configurable 5–60 second movement timer, and a clear running state.
Get Mouse Sentinel — $9.99