Sleep and power

Keep a Mac awake from Terminal with caffeinate

The caffeinate command stops a Mac from sleeping while a task runs. It is part of macOS and changes no settings.

Applies to: All current macOS versions. The System Settings paths are for macOS 13 Ventura and later.Checked: 29 October 2026

Symptoms

  • A download, build or script stops when the Mac goes to sleep.
  • A remote session or SSH connection drops after some minutes with no input.
  • You want the Mac to stay awake for one task, but you do not want to change the sleep settings.

Likely causes

  • Idle sleep. macOS puts the Mac to sleep after a time with no keyboard or mouse input. Network activity alone does not always stop this.
  • Display sleep. The display turns off on its own timer. On some Macs, the system then sleeps too.
  • The lid. Closing the lid of a Mac laptop puts it to sleep. caffeinate does not change this. See Keep a Mac laptop working with the lid closed.

How to check

  1. Open Terminal. See which processes now prevent sleep.

    pmset -g assertions

    Output A list of assertions such as PreventUserIdleSystemSleep, with the process that holds each one.

  2. See the sleep settings that are in use now.

    pmset -g

How to fix it

  1. To keep the Mac awake while one command runs, put caffeinate -i before the command. The assertion stops when the command stops.

    caffeinate -i make
  2. To keep the Mac awake for a fixed time, give the time in seconds with -t. This example is two hours.

    caffeinate -i -t 7200
  3. To keep the Mac awake until a process stops, give its process ID with -w.

    caffeinate -i -w 12345
  4. To keep the display on too, add -d.

    caffeinate -d -i
  5. To stop caffeinate that you started with no command, press Control-C.

  6. To stop automatic sleep while the display is off, change the setting. On a Mac laptop, choose Apple menu > System Settings > Battery > Options. Turn on “Prevent automatic sleeping on power adapter when the display is off”.

  7. On a Mac desktop, choose Apple menu > System Settings > Energy. Turn on “Prevent automatic sleeping when the display is off”.

With Kilobat

  1. Kilobat can keep the Mac awake until a download goes quiet, then let it sleep. Open Kilobat from the menu bar. Click the teacup and choose Until Downloads Finish.

  2. The CLI does the same. It stops after 3 minutes below 16 KB/s.

    kilobat awake --until-quiet
  3. To keep the Mac awake while one command runs, and to see the data it moved, use awake --.

    kilobat awake -- make release
  4. These features are free. See the recipe for the app, CLI and MCP steps.

Questions

Does caffeinate keep the Mac awake with the lid closed?

No. caffeinate stops idle sleep. Closing the lid still puts a Mac laptop to sleep, unless the Mac uses an external display, keyboard and power. See Keep a Mac laptop working with the lid closed.

What does the -s option do?

-s stops system sleep. The man page says that it works only when the Mac is on AC power.

Does caffeinate change my settings?

No. It creates power assertions. They stop when caffeinate stops.

Sources

Sources checked on 29 October 2026. Man pages are the ones installed with macOS; open one with man <name> in Terminal.