How to Keep Your MacBook Awake While the Lid is Closed Using Terminal

The Problem with Clamshell Mode

By default, macOS is aggressively programmed to enter sleep mode the instant you close the lid of your MacBook. This is a vital feature for saving battery life when you throw the laptop into a backpack. However, it becomes highly restrictive if you are trying to render a massive video file overnight, download a 100GB video game, or run a local web server, and you simply want to close the lid to keep dust off the keyboard and turn off the bright screen. While Apple officially supports “clamshell mode,” it requires the laptop to be plugged into power and connected to an external monitor. If you want to close the lid without an external display while forcing the Mac to stay awake and process background tasks, you must use a specific Terminal command.

How to Use the caffeinate Command

macOS includes a brilliant, built-in command-line utility called caffeinate. Just like it sounds, this command feeds your Mac digital caffeine, overriding all system sleep settings until you explicitly tell it to stop.

  1. Open the Terminal application on your Mac (Applications > Utilities > Terminal).
  2. To force the Mac to stay awake even when the lid is closed, you must use the -i flag (which prevents idle sleep) and the -s flag (which prevents the machine from sleeping when plugged into AC power).
  3. Type the following command:
  4. caffeinate -is
  5. Press Enter.

What Happens Next?

Once you press Enter, the Terminal cursor will drop to a new blank line and simply sit there. This indicates the caffeinate process is actively running. As long as this specific Terminal window remains open and active, your Mac will never go to sleep. You can now close the lid of your MacBook. The screen will turn off, but your downloads, renders, and background scripts will continue running at full speed.

How to Stop the Command

When your tasks are finished and you want your Mac to behave normally again, you must kill the digital caffeine.

  1. Open the lid of your MacBook.
  2. Return to the active Terminal window where the command is running.
  3. Press Control + C on your keyboard.
  4. The process will immediately terminate, returning you to the standard Terminal prompt, and macOS will resume its normal sleep behaviors.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.