Skip to content
86% off$349 $48.86code BF2026

Guides

caffeinate Command on Mac: Every Flag With Examples

How to use caffeinate on Mac: what -d, -i, -m, -s, -u, -t and -w do, copy-ready examples, how to check it with pmset, and why your Mac may still sleep.

GuideUpdated 8 min read

On this page

To keep a Mac awake from Terminal, run caffeinate. It stops idle sleep until you press ⌃C (Control-C). Add -d to keep the screen on too, add -t 3600 to stop after an hour, or put a command after it (caffeinate -i make) to stay awake only while that command runs.

What the caffeinate command does on a Mac

caffeinate is built into macOS at /usr/bin/caffeinate. It creates a power assertion, a request that tells macOS not to sleep for a reason right now. It doesn't change your sleep settings. When caffeinate exits, the assertion goes away and your Mac sleeps on its normal schedule again, so there's nothing to undo.

Before you start:

  • It doesn't need sudo or an admin password.
  • With no flags, it prevents idle system sleep only. The display can still turn off, which often makes it look like the Mac went to sleep when it didn't.
  • The common flags only prevent idle sleep. They don't stop sleep you trigger yourself, and you shouldn't rely on them to keep a MacBook awake with the lid closed (more on that below).

The full reference is the manual page. Run man caffeinate in Terminal to read it.

Keep your Mac awake until you press Control-C

  1. Open Terminal (in Applications ▸ Utilities, or search for it with Spotlight).

  2. Run one of these:

    bash
    caffeinate -d

    -d keeps the display on, which also keeps the Mac awake. Use plain caffeinate (or caffeinate -i) if the screen may turn off but the Mac should keep working, for example during a download.

  3. Leave the Terminal window open. The prompt doesn't come back while caffeinate runs.

  4. Press ⌃C in that window when you're done.

Run it in the background instead

To get your prompt back, add &:

bash
caffeinate -i &

This starts caffeinate as a background job in the current shell. To stop it, run kill %1 in the same window (if it's your only background job there), or end every running copy:

bash
killall caffeinate

This ends all caffeinate processes, including any that a script started. Closing the Terminal window normally ends a background caffeinate started from it as well.

What -d, -i, -m, -s and -u mean

You can combine flags in one command, for example caffeinate -di.

FlagAssertion it createsWhat it doesWatch out for
-dPreventUserIdleDisplaySleepKeeps the display from sleeping (and so keeps the Mac awake)Uses more power, since the screen stays on
-iPreventUserIdleSystemSleepKeeps the Mac from idle sleeping; the display may still sleepUsed when you give no assertion flag
-mPreventDiskIdleKeeps the disk from idle sleepingDoesn't stop the system or display from sleeping
-sPreventSystemSleepKeeps the system from sleepingOnly valid on AC power; has no effect on battery
-uUserIsActiveDeclares the user active: turns the display on if it's off and keeps it from idle sleepingLasts 5 seconds unless you add -t
-t <seconds>(timer)Releases the assertion after that many secondsIgnored when you run a command with caffeinate
-w <pid>(watch)Releases the assertion when that process exitsIgnored when you run a command with caffeinate

Copy-ready versions:

bash
caffeinate -d          # keep the screen on until Control-C
caffeinate -i          # keep the Mac awake, let the screen turn off
caffeinate -m          # keep the disk from idle sleeping
caffeinate -s          # keep the system awake while on AC power
caffeinate -u -t 1     # wake the display now, as if you touched the keyboard
caffeinate -di         # keep both the Mac and the screen awake

Use -i for long jobs where nobody watches the screen (downloads, backups, builds). Use -d for presentations, dashboards or anything you need to see.

Keep it awake for a set time with -t

-t takes seconds, not minutes:

bash
caffeinate -d -t 3600

This keeps the screen on for one hour, then lets the Mac sleep as usual. Without -d or another assertion flag, -t uses the default idle-sleep assertion.

You wantSecondsCommand
30 minutes1800caffeinate -t 1800
1 hour3600caffeinate -t 3600
2 hours7200caffeinate -t 7200
8 hours28800caffeinate -t 28800

If you'd rather think in minutes, let the shell do the arithmetic. This works in zsh, the default shell on current macOS:

bash
caffeinate -i -t $((90 * 60))

That's 90 minutes. Add & at the end to get the prompt back while the timer runs.

Stay awake while a command or process runs

Wrap a command

Put the command after caffeinate. The assertion lasts exactly as long as the command:

bash
caffeinate -i make
caffeinate -i ./render.sh
caffeinate -i rsync -a ~/Projects/ /Volumes/Backup/Projects/

When the command finishes, caffeinate exits and the Mac can sleep again. You don't need -t here, and it's ignored with a command anyway.

Watch a process that's already running (-w)

If the job is already going, give caffeinate its process ID (PID):

  1. Find the PID. Activity Monitor shows it in the PID column, or run this in Terminal:

    bash
    pgrep -x ffmpeg

    This prints the PID of every process named exactly ffmpeg.

  2. Start caffeinate with that PID:

    bash
    caffeinate -i -w 4321

    Replace 4321 with the real number. The assertion ends when that process exits.

Two useful variations:

bash
caffeinate -i -w $(pgrep -n ffmpeg)   # watch the newest process matching ffmpeg
caffeinate -i -w $$ &                 # stay awake while this shell is open

If pgrep finds nothing, the first one fails with an error because -w gets no PID.

Check that caffeinate is working

macOS lists every active assertion with pmset. This only reads information and changes nothing:

bash
pmset -g assertions

The top part shows each assertion type with a 1 if something holds it (for example PreventUserIdleSystemSleep 1 while caffeinate -i runs). Below that, assertions are listed by the process that owns them. To see only caffeinate's:

bash
pmset -g assertions | grep -i caffeinate

If nothing comes back, caffeinate isn't running. If you expected -d and only see the system assertion, check the flags you typed.

The same list helps the other way round: when your Mac won't sleep, it shows which process is holding it awake. A forgotten background caffeinate shows up here, and killall caffeinate clears it. Our guide to finding what keeps a Mac awake covers the other usual suspects.

Why your Mac still sleeps with caffeinate running

You closed the lid. Closing a MacBook's lid puts it to sleep unless it's connected to power and an external display (clamshell mode). Don't count on any caffeinate flag to keep a MacBook awake with the lid closed and no external display. See clamshell mode on Mac for the built-in way.

You put it to sleep yourself. The idle assertions (-i, -d) only stop idle sleep. Choosing Sleep from the Apple menu still puts the Mac to sleep.

Only the screen turned off. With plain caffeinate or -i, the display sleeps on its normal timer and the screen may lock, but the Mac keeps running. Use -d if you need the screen on.

caffeinate already exited. It stops when you press ⌃C, when you close its Terminal window, when the -t time runs out, when the wrapped command or watched PID finishes, or after 5 seconds for -u without -t. Run the pmset check above to confirm it's still there.

You're on battery with -s. -s only applies on AC power. Use -i on battery.

Something else is scheduled. Don't expect caffeinate to override a scheduled sleep or shutdown, or automatic log-out after inactivity. List scheduled power events with:

bash
pmset -g sched

For automatic log-out, open System Settings and search for "log out". For the sleep timers themselves, see Mac sleep settings explained.

When a menu bar app or glowmoth run fits better

caffeinate is enough when you're already in Terminal and the job has a clear end: one download, one build, one render. It's free, built in and leaves no settings behind.

It gets awkward when:

  • You forget it's running. A background caffeinate gives no visible sign.
  • You want keep-awake to start on its own, for example while an app is open, during work hours, or while a coding agent is busy.
  • You're on a laptop and want it to pause if the battery gets low or the Mac runs hot.

For those, a menu bar app does the job better. We make Glowmoth, a keep-awake app that includes a glowmoth command-line tool with close equivalents to most caffeinate uses:

caffeinateGlowmoth equivalent
caffeinate -iglowmoth on --no-display
caffeinate -dglowmoth on --display
caffeinate -t 7200glowmoth for 2h
(no equivalent)glowmoth until 18:00
caffeinate -w 4321glowmoth wait 4321
caffeinate -i makeglowmoth run -- make
-s, -m, -uNo equivalent

glowmoth on uses the default duration from Glowmoth's settings, which is Indefinitely unless you change it.

Differences that matter in practice:

  • glowmoth run returns the command's exit code and passes ⌃C to it. If the Glowmoth app isn't running, run and wait hold their own power assertion, so a script still works.
  • Durations are written the way you'd say them (90, 1h30, 2h 15m), not in seconds.
  • The menu bar icon and panel show that the Mac is being kept awake and why. In pmset -g assertions, Glowmoth's assertion is named after its reason, such as "Glowmoth: Session for 1 hour".
  • The app can pause keep-awake below a battery level or when the Mac runs hot, and runs rules such as "on AC power and external display connected". MacBooks also get an optional closed-lid mode, which installs a small helper you approve in System Settings.
  • The panel's Show More section lists other apps holding the Mac awake, and labels a running caffeinate as "caffeinate".

Trade-offs: Glowmoth has no equivalent of -s, -m or -u (for external drives it writes a small hidden file instead of using a disk-idle assertion). You install the command-line tool first from Settings ▸ Advanced ▸ Command Line with Install, which places it in ~/.local/bin. You may need to add that folder to your shell's PATH. The app needs an active trial or license to keep the Mac awake. The glowmoth command-line docs list every command and exit code.

Glowmoth is part of MacSuite; you can try it free for 7 days.

To compare free menu bar apps, see Caffeine for Mac alternatives. For every way to stop sleep, including System Settings, see how to stop your Mac from going to sleep.

FAQ

Does caffeinate need sudo?

No. Any user can run it, and the assertion is released when the process ends.

Is caffeinate safe to use?

Yes. It doesn't change system settings and only holds an assertion while it runs. The main risk is battery drain or heat if you forget it on a laptop, so prefer -t or a wrapped command over an open-ended caffeinate.

Does caffeinate work on battery?

-i, -d and -m work on battery. -s only applies on AC power.

How do I stop a caffeinate I started in the background?

Run killall caffeinate, or kill %1 in the Terminal window that started it. Then run pmset -g assertions | grep -i caffeinate to confirm it's gone.

Every app.
One purchase.