AwakeMate on Product Hunt

Guide

The caffeinate command: keep your Mac awake from the Terminal

A practical guide to macOS's built-in caffeinate command - every flag, the best way to wrap a long-running command, and when a keep-awake app is the better call.

Your Mac ships with a built-in way to stop it going to sleep, and most people never learn it. It is a command called caffeinate, it needs no install, and it is the same power-assertion mechanism that dedicated keep-awake apps (AwakeMate included) use under the hood.

Here is how to use it well, every flag worth knowing, and the point where reaching for the Terminal stops being worth it.

The one-line answer

Open Terminal and run:

caffeinate

As long as that command is running, your Mac will not fall asleep on its own. Press Control-C to stop it and let normal sleep resume. That is the whole idea. Everything else is refinement.

The pattern that actually matters: wrap a command

Typing caffeinate and remembering to Control-C later is easy to forget. The far better pattern is to hand caffeinate the command you want to protect. It keeps the Mac awake for exactly as long as that command runs, then releases:

caffeinate -i make
caffeinate -i npm run build
caffeinate -i ffmpeg -i in.mov out.mp4

When the build or render finishes, the assertion is dropped automatically and your Mac can sleep again. No cleanup, no forgetting. This is the single most useful thing to know about caffeinate.

Every flag worth knowing

caffeinate takes a set of flags that decide which kind of sleep it blocks:

FlagWhat it prevents
-dDisplay sleep (the screen staying on)
-iSystem idle sleep (the usual one you want)
-mDisk idle sleep
-sSystem sleep - only effective when on AC power
-uDeclares user activity (wakes the display), pair with -t
-t NTimeout in seconds before the assertion is released
-w PIDWait for the process with this PID to exit, then release

A few real-world combinations:

# Keep the whole system awake for one hour, then stop
caffeinate -i -t 3600

# Keep the display on too (good for a dashboard or presentation)
caffeinate -d

# Stay awake until an already-running job (PID 4823) finishes
caffeinate -w 4823

# Keep going even with heavy work, on AC power
caffeinate -is

If you run caffeinate with no flags, it behaves as -di in most cases, preventing idle sleep while it runs.

Checking what is keeping your Mac awake

Curious what already holds an assertion? This lists every active one, including the ones caffeinate creates:

pmset -g assertions

You will see entries like PreventUserIdleSystemSleep when something (a download, a caffeinate, or an app) is holding the Mac awake.

Where caffeinate stops being enough

caffeinate is excellent and honest, but it has real limits:

  • It is manual. You have to remember to run it, and remember what to wrap. For a quick one-off command that is fine. For a day of context-switching between builds, agents, and renders, it becomes book-keeping.
  • It lives in the Terminal. Not every task you want to protect starts from a shell. A Finder copy, an app export, a GUI backup - there is no command to wrap.
  • It has no idea what “done” means for a GUI app. -w PID helps for a known process, but you have to find the PID first.
  • Closing the lid still sleeps the Mac. caffeinate blocks idle sleep; it does not override clamshell sleep. See how to keep your Mac awake with the lid closed for the real rules there.

When an app is the better call

If you find yourself typing caffeinate several times a day, the job you actually want is: stay awake while the tools I care about are running, then sleep. That is automation, and it is what AwakeMate does. It watches the apps and command-line tools you choose (including npm- and pip-installed AI agents like Claude Code and Codex that show up as node or python), holds the Mac awake only while they run, can sleep when they go idle, and shows live status in the notch - no commands to start or stop.

It uses the same underlying power assertion as caffeinate, so it is just as reliable and never touches your saved Energy Saver settings. If you want the full trade-off, see AwakeMate vs the built-in caffeinate.

For most people the honest recommendation is simple: learn caffeinate -i <command> for one-off jobs, and reach for an automatic app once keeping your Mac awake becomes a daily chore.

Let your Mac stay awake on its own

AwakeMate keeps your Mac awake only while the tools you care about are running - builds, AI agents, renders, downloads - then lets it sleep. No commands to remember. Free 14-day trial.