Mac caffeinate Command: Every Flag, Examples, How to Stop
Short answer: Mac caffeinate is the built-in macOS Terminal command that stops a Mac from sleeping. Type caffeinate and press Return (Control-C stops it). Use caffeinate -d to keep the screen on, caffeinate -t 3600 for one hour, or caffeinate -i npm run build to stay awake only while a command runs. man caffeinate documents seven flags.
TL;DR
- No flags means
-i: caffeinate blocks idle sleep and still lets the screen turn off. -dkeeps the display on.-sonly works on AC power; on battery it does nothing.- Stop it with Control-C, or
killall caffeinatefrom any Terminal window. - Wrap a command (
caffeinate -i make) and the assertion lasts exactly as long as the command. Leave-toff when you do: despite the man page, it still cuts the assertion short. - It can’t keep a closed MacBook awake and can’t keep Slack or Teams showing you as active.
caffeinate lives at /usr/bin/caffeinate on every Mac, Intel or Apple silicon (M1 and later), and needs no install, no admin password and no download. Everything below was checked against man caffeinate and live pmset output on macOS 27.2.1 in November 2026.
What does the Mac caffeinate command do?
caffeinate tells macOS not to sleep for as long as it runs, by creating a power management assertion. The man page describes it in one line: “prevent the system from sleeping on behalf of a utility.” When caffeinate exits (timeout, Control-C, or the wrapped command finishing), macOS goes back to your normal sleep settings straight away.
Under the hood it uses the same IOPMAssertionCreateWithName API that apps such as Xcode and Safari use to hold off sleep during active work. caffeinate just exposes it on the command line. It has shipped with macOS since OS X Mountain Lion in 2012 (the man page is dated November 9, 2012), so it is on every Mac you are likely to meet.
How do I use caffeinate in Terminal?
Open Terminal (Applications › Utilities › Terminal, or Spotlight with Command-Space and type “Terminal”), then run one of these:
- Stay awake until you stop it:
caffeinate - Stay awake for a set time (seconds, so 3600 is one hour):
caffeinate -t 3600 - Keep the screen on too:
caffeinate -d - Stay awake only while a command runs:
caffeinate -i npm run build
The prompt appears to hang while caffeinate runs. That is normal: it is holding the assertion. Open a new Terminal tab (Command-T) to keep working.
What do the caffeinate flags mean? (man caffeinate, explained)
man caffeinate lists seven flags. Five choose which kind of sleep to block (-d, -i, -m, -s, -u) and two control how long the assertion lasts (-t, -w). With no flags, caffeinate prevents idle sleep. Flags combine, for example caffeinate -dims. The synopsis is caffeinate [-disu] [-t timeout] [-w pid] [utility arguments...].
| Flag | What the man page says | pmset shows | Best for | Example |
|---|---|---|---|---|
-d | Prevents the display from sleeping | PreventUserIdleDisplaySleep | Dashboards, demos, watching output | caffeinate -d |
-i | Prevents the system from idle sleeping (the default) | PreventUserIdleSystemSleep | Builds, downloads, agent runs | caffeinate -i |
-m | Prevents the disk from idle sleeping | PreventDiskIdle | External spinning drives | caffeinate -m |
-s | Prevents the system from sleeping; valid only on AC power | PreventSystemSleep | Plugged-in servers and long jobs | caffeinate -s |
-u | Declares the user is active; turns the display on; 5-second default timeout | UserIsActive | Waking the screen from a script | caffeinate -u -t 60 |
-t N | Drops the assertion after N seconds (man page: “not used” with a command, but see below) | Timeout will fire in N secs | Auto-stop after a fixed time | caffeinate -t 3600 |
-w PID | Releases the assertion when process PID exits; ignored with a command | Stay awake until a running job ends | caffeinate -w 12345 |
-d (display). Keeps the screen on regardless of your “Turn display off” setting in System Settings › Lock Screen. Without it, the screen can go dark while the system stays awake.
-i (idle sleep). The one developers need most. It stops idle-triggered sleep but lets the display dim and turn off, so a long build finishes in the background with the screen dark.
-m (disk). Keeps disks from idle sleeping. With an internal SSD it rarely matters; it is for external hard drives that spin down mid-job.
-s (system sleep). The strongest assertion, but the man page says it “is valid only when system is running on AC power”. Unplugged, it has no effect, so use caffeinate -is if the Mac might go on battery.
-u (user active). Declares that someone is using the Mac right now. If the display is off, it turns it on. Without -t, it lasts only 5 seconds, so scripts use it to wake the screen, not to hold the Mac awake.
-t (timeout). caffeinate -t 7200 keeps the Mac awake for exactly two hours, then exits. Use it when you can estimate the duration; a forgotten caffeinate means your Mac never sleeps. The man page says the timeout is not used when caffeinate wraps a command, but that is out of date. On macOS 27.2.1, caffeinate -i -t 3 sleep 9 shows Timeout will fire in 2 secs in pmset and the assertion disappears after 3 seconds while sleep keeps running. Apple’s caffeinate source passes the timeout to every assertion it creates.
-w (wait for PID). Ties the assertion to a process that is already running. caffeinate -i -w 12345 stays awake until PID 12345 exits. Unlike -t, it really is ignored when caffeinate wraps a command. Find a PID with pgrep -f name.
How do I stop caffeinate?
Press Control-C in the Terminal window where caffeinate is running. That ends the process and releases the assertion immediately.
If it runs in the background or you can’t find the window:
killall caffeinate
Closing the Terminal window also ends it (it sends a hangup signal), and a -t timer or a wrapped command finishing ends it on its own. To confirm nothing is left (read-only):
pmset -g assertions | grep caffeinate
No output means no caffeinate is holding your Mac awake. If your Mac still refuses to sleep, another app is the cause: see what’s keeping your Mac awake.
How do I check that caffeinate is working?
Run pmset -g assertions | grep -A3 caffeinate in a second Terminal tab. While caffeinate runs you will see its PID and the assertion it holds, named “caffeinate command-line tool”:
pid 44368(caffeinate): [0x00022ebd00018d23] 00:00:00 PreventUserIdleSystemSleep named: "caffeinate command-line tool"
Details: caffeinate asserting on behalf of 'sleep' (pid 44366)
Localized=THE CAFFEINATE TOOL IS PREVENTING SLEEP.
Timeout will fire in 2 secs Action=TimeoutActionRelease
PreventUserIdleSystemSleep is the -i assertion, PreventUserIdleDisplaySleep is -d, and PreventSystemSleep is -s. “asserting on behalf of” means you wrapped a command; “asserting for N secs” means a plain -t run; a “Timeout will fire” line means a countdown is running. Run pmset -g assertions without grep to see every app holding your Mac awake.
What are the best caffeinate examples for developers?
The most useful pattern is wrapping the command you want to protect, so sleep prevention starts and stops with it and you can’t forget to turn it off.
Keep awake during a build:
caffeinate -i npm run build
caffeinate -i cargo build --release
caffeinate -i xcodebuild -scheme MyApp -configuration Release
When the build exits (success or failure), caffeinate exits too.
Keep awake while an AI coding agent works:
caffeinate -i claude # Claude Code: awake until you exit the session
caffeinate -i codex # the same for OpenAI's Codex CLI
caffeinate -i -w 48213 # an agent that is already running (find its PID with pgrep -f)
Long agent runs are where idle sleep bites: the Mac sleeps, the network drops and the run stalls. Add -d if you want to keep watching the output.
Screen on for a fixed time (presentations, demos):
caffeinate -d -t 3600
Large downloads:
caffeinate -i curl -O https://example.com/large-dataset.tar.gz
Remote jobs over SSH:
caffeinate -i ssh user@server 'long-running-script.sh'
If your Mac sleeps, the SSH connection can drop and the remote job may die (unless it runs inside tmux or screen on the server).
Tie it to the current shell:
caffeinate -i -w $$ &
Runs in the background and ends when this shell exits, so you can keep using the same window.
Inside tmux:
tmux new-session -d -s build 'caffeinate -i make all'
Put caffeinate inside the session. tmux new-session -d returns at once, so wrapping tmux itself would release the assertion almost immediately.
In cron:
0 2 * * * caffeinate -i /path/to/nightly-backup.sh
This holds the Mac awake for as long as the backup runs, but only if the Mac is already awake at 2 AM: caffeinate cannot wake a sleeping Mac. Use pmset schedule wake for that.
A chain of commands:
caffeinate -i bash -c 'npm install && npm run build && npm run lint'
The whole chain runs under one assertion, and caffeinate exits when the chain stops.
Why isn’t caffeinate keeping my Mac awake?
It is almost always one of four things: -s on battery, a -t timeout on a wrapped command, a caffeinate process that has already ended, or a closed lid. Check with pmset -g assertions | grep -A3 caffeinate first.
-s on battery. The -s assertion is valid only on AC power. Unplugged, the Mac idle-sleeps as normal. Use caffeinate -is.
-t on a wrapped command. caffeinate -i -t 600 ./long-job.sh releases the assertion after 10 minutes even if the job is still running, while caffeinate itself stays in the process list, so it looks as if it still works. Drop -t and let the command decide.
caffeinate already ended. Control-C, killall caffeinate, quitting Terminal or closing its window all release the assertion, and a wrapped command that exits early takes caffeinate with it. Run it inside tmux to outlive the window.
The lid is closed. Closing a MacBook’s lid is a separate sleep trigger. Apple’s IOKit header says that with the idle-sleep assertion caffeinate creates, “the system may still sleep for lid close”, and no flag is documented to change that. For clamshell mode and the pmset options, see how to keep a Mac awake with the lid closed.
What can’t caffeinate do?
caffeinate manages power only. It can’t simulate user activity, wake a sleeping Mac, survive a restart, or keep a closed MacBook awake without clamshell mode.
- No Slack or Teams “active” status. Those apps watch for mouse and keyboard input, not sleep state, so an awake but idle Mac still shows you as away. Before reaching for a mouse jiggler, read what IT can see.
- No waking from sleep. It prevents sleep; it can’t undo it.
- No persistence. It is a process. A restart, a Terminal crash or a closed window ends it, and there is no daemon mode.
- No menu bar toggle. You need Terminal open every time.
Is caffeinate the same as the Caffeine app?
No. caffeinate (with an “ate”) is Apple’s command-line tool. Caffeine is a separate third-party menu bar app with a coffee cup icon you click on and off. Many people search “caffeine for Mac” when they want either one. If you want a click toggle instead of Terminal, see our guide to the Caffeine app for Mac and its alternatives, or KeepingYouAwake, a free open-source menu bar toggle.
caffeinate vs Amphetamine vs a menu bar app: which should you use?
Use caffeinate to protect one command or script; use a menu bar app when you want an all-day toggle or need features caffeinate lacks. Amphetamine is free on the Mac App Store as of November 2026 (version 5.3.2, last updated November 2023) and adds triggers (running apps, connected devices, network), a Closed-Display Mode for lid-closed use and optional cursor movement.
We make FavTray, so weigh our take accordingly. FavTray is a macOS menu bar app that bundles developer and productivity tools, free with daily limits, $4.99 once for Lifetime. Its Keep Alive tool keeps the Mac awake by moving the cursor slightly (unlike caffeinate, which only holds a power assertion), so chat apps keep reporting you as active, with a work-hours schedule and auto-pause on battery. It is free for 3 hours of running time a day.
| Need | Best choice | Cost (Nov 2026) | Why |
|---|---|---|---|
| Stay awake during one build or script | caffeinate -i command | Free, built in | Ends when the command ends |
| Long AI agent session | caffeinate -i claude (or codex) | Free, built in | Awake for exactly the session |
| Screen on for a demo | caffeinate -d -t 3600 | Free, built in | Fixed time, then normal sleep |
| One-click toggle, no Terminal | Caffeine-style menu bar app | Usually free | Compare keep-awake apps |
| Lid closed, no external display | Amphetamine | Free | Closed-Display Mode |
| Slack or Teams showing active | FavTray Keep Alive | Free 3 h/day, $4.99 once unlimited | Simulates input, not just power |
For the full list of options, from System Settings to apps, see our guide to keep mac awake methods, or FavTray vs Amphetamine. Pricing for every FavTray tool is on the pricing page.
Sources (checked 14 November 2026): man caffeinate and pmset -g assertions output on a MacBook running macOS 27.2.1; Apple’s caffeinate source and IOPMLib.h; the Amphetamine App Store listing.
Frequently Asked Questions
How do I use caffeinate on a Mac?
Open Terminal and type caffeinate, then press Return. Your Mac won't idle-sleep until you press Control-C. Add -d to keep the screen on, -t 3600 to stop after one hour, or put a command after it, like caffeinate -i npm run build, to stay awake only while that command runs. It is built into macOS, so there is nothing to install.
How do I stop caffeinate on a Mac?
Press Control-C in the Terminal window where caffeinate is running. If it runs in the background or in another window, type killall caffeinate in any Terminal window. Closing the Terminal window also ends it. To confirm it is gone, run pmset -g assertions | grep caffeinate; if nothing prints, your Mac follows its normal sleep settings again.
What is the difference between caffeinate -d and caffeinate -i?
caffeinate -d keeps the display from sleeping, so the screen stays on. caffeinate -i keeps the system from idle sleeping but lets the screen turn off on its normal timer. Use -d for dashboards, demos and watching output. Use -i for builds, downloads and AI agent runs that only need the Mac to keep working. You can combine them as caffeinate -di.
Is caffeinate the same as the Caffeine app for Mac?
No. caffeinate is a command-line tool Apple ships in every copy of macOS at /usr/bin/caffeinate. Caffeine is a separate third-party menu bar app with an on/off icon. Both keep a Mac from sleeping, but caffeinate needs Terminal and no download, while a menu bar app gives you a click toggle. Several menu bar apps use the same power assertions underneath.
Does caffeinate -t work when you wrap a command?
Yes, even though the man page says the timeout is not used with a command. On macOS 27.2.1, caffeinate -i -t 600 ./job.sh drops the assertion after 10 minutes while the job keeps running. The -w flag, by contrast, really is ignored with a command. To stay awake exactly as long as the command runs, leave -t off.
Can caffeinate keep a MacBook awake with the lid closed?
Not on its own. Closing the lid is a separate sleep trigger, and Apple's IOKit documentation says the idle-sleep assertion caffeinate creates still lets the system sleep on lid close. The supported way is clamshell mode: plug in power, an external display and a keyboard or mouse. A menu bar app like Amphetamine also offers a Closed-Display Mode.