Back to Blog
Guide

caffeinate on Mac: Keep Your Mac Awake From Terminal

caffeinate is the built-in macOS command that keeps a Mac awake. Run caffeinate -d to stop the display sleeping, -i to stop idle sleep, add -t for a time limit, and press Ctrl+C to stop. Every flag with examples, and why awake is not active in Slack.

Slack Green Team
September 23, 2026
November 3, 2026
5 min read
Share:
mac
terminal
remote work

Free tool, runs in this tab

Build and check your caffeinate command

Pick what to keep awake and for how long, or paste your own command to see what it really holds. Copy the result into Terminal.

$
Check a line people use:
What this line holds, second by second
-i Mac awake2 h-d Screen on2 h0 s5 s10 s2 hClosing this Terminal window ends every bar.
  • It runs in this Terminal window: Ctrl+C stops it, and so does closing the window.

Keep awake

How long

hmin= -t 7200. caffeinate counts in seconds.

When you close Terminal

Check that it runs

pmset -g assertions | grep -A1 caffeinate

# one caffeinate line per assertion, with its Details:
PreventUserIdleSystemSleep   caffeinate asserting for 7200 secs
PreventUserIdleDisplaySleep  caffeinate asserting for 7200 secs

Stop it

# Ctrl+C in its Terminal window, or from another one:
pkill -f "^caffeinate -di"

Keep it as a word you type

NameThen open a new Terminal window and type awake.
echo "alias awake='caffeinate -di -t 7200'" >> ~/.zshrc

caffeinate keeps the Mac awake, not Slack active. In our test Slack still went away 10 minutes after the last keyboard or mouse input with the screen on: does Caffeine keep Slack active.

Open the full tool page

The caffeinate command keeps a Mac awake from Terminal: run caffeinate -d to keep the display on, or plain caffeinate to block idle sleep, and press Ctrl+C to stop it. caffeinate does not keep Slack green, because it makes no keyboard or mouse input. Slack Green keeps your Slack dot green from a server even with the Mac asleep and the lid closed, free for 7 days with no card.

Add -t 3600 to stop after an hour, or put a command after it, such as caffeinate -i ./backup.sh, to stay awake only while that command runs. It is built into macOS, needs no admin password and no install.

It does not keep Slack active. The Slack desktop app sets you away 10 minutes after your last keyboard or mouse input on the Mac, whether the Mac is awake or not (Slack desktop 4.52.178 code, checked 7 Oct 2026). caffeinate only stops the instant away you get when the Mac sleeps.

We ran every command on this page on a MacBook with macOS 26.5.2 (Apple silicon) on 30 September 2026, and checked each one with pmset -g assertions. The output is below.

caffeinate flags

The meanings come from man caffeinate. The last column is the assertion each flag created on our Mac, as pmset -g assertions listed it.

FlagWhat it doesAssertion we saw
-dPrevents the display from sleepingPreventUserIdleDisplaySleep
-iPrevents the system from idle sleepingPreventUserIdleSystemSleep
noneSame as -iPreventUserIdleSystemSleep
-mPrevents the disk from idle sleepingPreventDiskIdle
-sPrevents the system from sleeping, only on AC powerPreventSystemSleep
-uDeclares that the user is active and turns the display on. Lasts 5 seconds unless you add -tUserIsActive
-t secondsDrops the assertion after that many seconds"caffeinate asserting for 20 secs"
-w PIDKeeps it until the process with that ID exits"asserting on behalf of Process ID 97977"
commandKeeps it while the command runsnone extra

Three traps we found on 7 October on the same Mac. -t reads whole seconds only, so caffeinate -t 2h ran for 2.1 seconds with no error. -u without -t takes -m with it after 5 seconds, so caffeinate -dimsu held 3 of its 5 assertions from then on. And -t in front of a command lets go at that time even while the command still runs. The caffeinate command builder checks any line for these and writes one for a time, a clock time or an app.

caffeinate keeps the Mac awake, but Slack still sets you away 10 minutes after your last keyboard or mouse input. A server-side tool keeps your Slack dot green with no input, even while the laptop sleeps or the lid is closed.

What pmset showed on our Mac

This is caffeinate -dims -t 20 running, one second in:

$ caffeinate -dims -t 20 &
$ pmset -g assertions | grep caffeinate
   pid 97573(caffeinate): [0x0001aacb000197db] 00:00:01 PreventUserIdleSystemSleep named: "caffeinate command-line tool"
	Details: caffeinate asserting for 20 secs
   pid 97573(caffeinate): [0x0001aacb000597dc] 00:00:01 PreventUserIdleDisplaySleep named: "caffeinate command-line tool"
	Details: caffeinate asserting for 20 secs
   pid 97573(caffeinate): [0x0001aacb000797dd] 00:00:01 PreventSystemSleep named: "caffeinate command-line tool"
	Details: caffeinate asserting for 20 secs
   pid 97573(caffeinate): [0x0001aacb000f97de] 00:00:01 PreventDiskIdle named: "caffeinate command-line tool"
	Details: caffeinate asserting for 20 secs

The timed runs ended on their own. caffeinate -t 2 returned after 2.10 seconds, and caffeinate -i sleep 3 after 3.01 seconds, the length of the command it wrapped. With -w, caffeinate exited as soon as the process it watched ended. After caffeinate -u -t 3 finished, pmset -g assertions | grep -c caffeinate printed 0, so nothing is left behind. None of it asked for a password; it ran as our normal user.

caffeinate -i vs -d

  • • caffeinate -i keeps the computer running, but the display can still turn off. Use it for downloads, backups and builds.
  • • caffeinate -d keeps the display on. Use it when you want the screen visible, or to stop the screen saver and the lock that follows it.
  • • caffeinate -di does both. Flags combine, so caffeinate -dims sets four at once.
  • For a permanent change instead of a running command, see how to turn off the screen saver on a Mac.

    caffeinate examples

    # Keep the display on until you press Ctrl+C
    caffeinate -d
    
    # Keep the Mac awake for two hours, then stop
    caffeinate -di -t 7200
    
    # Stay awake only while a command runs
    caffeinate -i rsync -a ~/Projects /Volumes/Backup/
    
    # Stay awake until another app quits (find its PID with pgrep)
    caffeinate -i -w "$(pgrep -x Transmission)"
    
    # Run it in the background and keep using the same Terminal window
    caffeinate -d &

    Check that it is working with pmset -g assertions | grep caffeinate, as in the output above. Without the grep, the same command lists everything else that keeps a Mac awake; on our Mac that included the Amphetamine app and an Electron app. More in why is my Mac not going to sleep.

    How to stop caffeinate

  • • If it runs in the Terminal window, press Ctrl+C.
  • • If you started it in the background, run pgrep -l caffeinate to find its process ID and kill that ID. killall caffeinate also works, but it stops every caffeinate, including ones a script or another app started.
  • • If you used -t, it stops on its own when the time is up.

caffeinate and the MacBook lid

Closing the lid puts a MacBook to sleep even with caffeinate running, unless the Mac is on power with an external display, keyboard and mouse attached. caffeinate keeps an open Mac awake; it does not replace clamshell mode. With no display attached, the admin command pmset disablesleep keeps a closed Mac awake, until you set it back to 0. Lid-closed options for Mac and Windows are in keep a laptop awake with the lid closed.

Does caffeinate keep Slack active?

No. We tested the same thing with the Caffeine app: Slack stayed green until minute 10, then went away with the screen still on. The full test is in does Caffeine keep Slack active.

caffeinate removes one trigger, the Mac sleeping or locking, which sets you away at once. Slack's idle timer reads the Mac's idle time, and caffeinate creates no input. caffeinate -u wakes the display for a few seconds but does not reset the idle counter. The Mac-specific rules are in keep Slack active on Mac, and every method is compared in how to keep Slack active.

If you would rather click a menu bar icon than type a command, we compared Amphetamine, KeepingYouAwake, Caffeine, Lungo and KeepAwake in the best app to keep a Mac awake.

caffeinate on a work Mac

caffeinate is built in and needs no admin rights, so it works on most managed Macs. A screen lock enforced by your company through MDM still applies. Lock Screen settings that stop locks for good are in keep a Mac screen from locking. For Windows and Linux equivalents, see keep a work computer awake without admin rights.

FAQ

Does caffeinate need sudo?

No. It runs as your user. Every command on this page ran without a password.

Does caffeinate survive closing Terminal?

Closing a Terminal window sends a hangup signal to what runs in it. In our test that signal stopped a plain caffeinate at once, while one started with nohup caffeinate -t 60 & kept running. Use nohup if you want to close the window.

Related Articles

Guide

pmset disablesleep: Keep a Mac Awake With the Lid Closed, and Undo It

sudo pmset -a disablesleep 1 stops all system sleep on a Mac, lid closed included, and sudo pmset -a disablesleep 0 turns normal sleep back on. How to check whether it is on, why it outlives a restart, and the pmset and caffeinate commands to use instead.

Slack Green Team
Comparison

Amphetamine Alternatives for Mac, and When to Switch

Amphetamine is free and covers almost every keep-awake case, so switch only for a reason: open source, one click, Shortcuts, a lid-closed setup without Enhancer, or nothing to install. The alternative for each, compared on price and features.

Slack Green Team
Guide

How to Keep a Mac Screen From Locking (Without Breaking IT Rules)

To stop a Mac from locking, open System Settings, Lock Screen, set the screen saver and display-off times to Never or longer, and raise Require password after screen saver begins or display is turned off. Or run caffeinate -d. What a managed Mac allows, and why Slack still shows you away.

Slack Green Team