# How to use caffeinate to keep your Mac awake

Canonical: https://www.getwarden.org/blog/caffeinate-mac-keep-awake

Published: 2026-09-28 · Warden

Updated: 2026-09-28

Use caffeinate -i to prevent idle system sleep, or caffeinate -di to keep the display awake too. This built-in macOS command does not block keyboard or mouse input.

## Keep your Mac awake for one hour

Open Terminal and run the command below. The -i flag prevents idle system sleep, -d prevents display sleep, and -t sets a timeout in seconds. Here, 3600 means one hour. Keep this Terminal session open while you work.

To end the assertion early, press Control-C in that terminal. After it exits, your normal sleep settings apply again. This is useful for a bounded task because you do not have to remember to undo a permanent settings change.

```sh
caffeinate -di -t 3600
```

## Keep a single build awake until it finishes

For command-line work, wrap the actual command. In the example below, caffeinate prevents idle system sleep for the lifetime of make. Replace make with the command your project uses.

This form is usually better than guessing how long a build will take. The sleep assertion ends when the command exits, whether it succeeds or fails. It does not repair failures, keep an app from crashing, or confirm that the output is correct.

```sh
caffeinate -i make
```

## Choose the flags you actually need

Check man caffeinate on your Mac for the options supported by your installed macOS version. Timers and the -w option do not control the lifetime when you wrap a command; the command does.

- -i: prevent idle system sleep. Use this when the job matters but you do not need the screen lit.
- -d: prevent display sleep. Combine it with -i when you want to watch progress.
- -t 3600: end after 3,600 seconds when running without a wrapped command.
- -w PID: hold the assertion until an existing process exits. Replace PID with its numeric process ID.
- -s: a system sleep assertion that applies on AC power. Do not treat it as a universal closed-lid guarantee.

## Awake, visible, and input-locked are different states

A Mac can be awake with its display off. A screen can be visible while its keyboard is still accepting input. caffeinate changes sleep behavior; it does not make accidental keystrokes harmless.

If you only need a build to continue and want to hide your desktop, use the macOS screen lock with suitable sleep settings. If you want to watch output while preventing local keyboard, mouse, and trackpad input, Warden adds that input lock and offers optional sleep prevention.

## Test the setup before a long job

Warden is useful when input protection is part of this workflow. You do not need to buy it just to run caffeinate. Try the input lock during a short task first, then decide whether watching progress hands-free is useful for your desk.

- Start a short representative job and confirm that progress continues during the idle period.
- Leave the lid open unless you have separately verified a supported closed-display setup.
- Check power and network access for the full run. Sleep prevention is not a substitute for either.
- When the job finishes, stop a manually started caffeinate session and check the output.

## Keep your Mac awake and protect its inputs with Warden

caffeinate handles sleep prevention, but your keyboard and trackpad still accept input. Warden lets you watch the same build or download with keyboard, mouse, and trackpad input locked. Enable its optional sleep prevention when you want Warden to handle both parts of that desk workflow.

[See how Warden locks Mac input](https://www.getwarden.org/lock-mac-keyboard)

## Sources

- [caffeinate manual (available in Terminal)](https://github.com/apple-oss-distributions/PowerManagement/blob/main/caffeinate/caffeinate.8)

- [Apple: set sleep and wake settings](https://support.apple.com/guide/mac-help/set-sleep-and-wake-settings-mchle41a6ccd/mac)

## Related guides

- https://www.getwarden.org/for-claude-code

- https://www.getwarden.org/blog/tmux-mac-sleep-terminal-sessions

- https://www.getwarden.org/warden-vs-macos-screen-lock

## Try Warden

7-day free trial. $8.99 once. Up to 3 Macs per license. Requires macOS 15.2 or later.

https://www.getwarden.org/download