← All posts

Keep Mac Awake With the Lid Closed: Claude Code, Downloads, No Terminal

There are three ways to keep a Mac awake: a setting in System Settings that only works on power, the built-in caffeinate terminal command, and a menu-bar app that does it in one click. Which one you want depends on whether you are waiting on a download, running a Claude Code session overnight, or trying to use a MacBook with the lid closed.

This guide covers all three, including the exact caffeinate flags, what clamshell mode actually requires, and why "keep my Mac awake when the lid is closed" is usually a question about hardware rather than software.

Option 1: System Settings (power adapter only)

macOS has one built-in switch for this, and it only applies when the Mac is plugged in.

  1. Open System Settings.
  2. On a MacBook, go to Battery and click Options. On a desktop Mac, go to Energy.
  3. Turn on Prevent automatic sleeping on power adapter when the display is off.
  4. Optionally set Turn display off on power adapter (under Lock Screen) to a long interval or Never.

Right for a Mac that lives on a charger; wrong for a one-off, because you will forget it is on. There is no battery equivalent: Apple does not let you disable sleep on battery from Settings.

Option 2: The caffeinate terminal command

Every Mac ships with caffeinate. Open Terminal and run:

caffeinate -d -i -t 3600

The flags, explained:

  • -d: prevent the display from sleeping.
  • -i: prevent the system from idle sleeping (the Mac itself stays on even if the screen dims).
  • -s: prevent system sleep only while on AC power. Add it if you want the assertion to vanish when you unplug.
  • -t 3600: timeout in seconds. 3600 is one hour; 28800 is eight hours. Without -t, it runs until you press Control-C or close the Terminal window.

The most useful variant for long jobs is to wrap the command itself:

caffeinate -i npm run build

The Mac stays awake exactly as long as that command runs, then returns to normal. The downside is that caffeinate lives in a Terminal window: close the tab and it stops, and nothing on screen tells you it is active.

Option 3: A one-click menu-bar app (no Terminal)

If you do this more than once a week, a menu-bar toggle is simpler. Caffeine was the classic app; it has been abandoned and revived a few times, which is why "caffeine mac alternative" is such a common search. Korinotch Keep Awake is a free mini app that does the same job on current macOS:

  • One click in the menu bar to turn sleep prevention on or off, with a clear icon state so you always know.
  • Timed sessions (30 minutes, 1 hour, until a set time) so you cannot forget it overnight by accident.
  • Works on battery and on power.
  • Supports lid-closed use when the Mac is on power with an external display (see below).
  • Free with a Korinotch account; runs on macOS 14 Sonoma, 15 Sequoia and 26 Tahoe.

If you use the full Korinotch app, Keep Awake is also built into the notch, so you can toggle it from the island without touching the menu bar. Our earlier post, Keep Awake from the Mac notch, shows that flow.

This is also the simplest answer to "keep Mac awake while downloading". Browser and torrent downloads do not count as activity, so a two-hour download pauses when the Mac sleeps on battery. Turn on Keep Awake with a timer slightly longer than the download, and pair it with the free Usage mini app to watch network speed in the menu bar.

Keep a Mac awake with the lid closed (clamshell mode)

This is the one case software cannot fix on its own. When you close a MacBook lid, macOS sleeps unless the machine is in clamshell mode, which requires all three of:

  1. Power. The MacBook must be connected to a charger (MagSafe or USB-C).
  2. An external display. Connected over HDMI, Thunderbolt or USB-C.
  3. An external keyboard or mouse. Bluetooth or USB, so you can wake it.

With all three present, closing the lid moves everything to the external display and the Mac keeps running. Add the System Settings toggle from Option 1, or turn on Keep Awake, and it stays running indefinitely. Without an external display there is no supported way to keep a MacBook awake with the lid shut: the lid sensor triggers sleep, and tools that override it risk overheating because the keyboard area is part of the cooling design. For a headless MacBook running downloads or a server, leave the lid slightly open and use Keep Awake or caffeinate.

Keep Claude Code running with the lid closed (Codex and Cursor agents too)

AI coding agents changed what "keep my Mac awake" means. A Claude Code refactor, a Codex run through a test suite, or a Cursor background agent can take 20 to 90 minutes with no keyboard input from you. If the Mac sleeps mid-run, the process is suspended, network calls time out and you come back to a half-finished change.

Three approaches that work:

  • Wrap the agent in caffeinate. caffeinate -i claude (or codex, or whatever launches your agent) keeps the Mac awake for exactly the length of the session. Cleanest if you start agents from Terminal anyway.
  • Turn on Keep Awake before you walk away. One click with a four-hour timer, so the Mac can sleep once the agent is long finished. Best when the agent runs inside an IDE rather than a shell you control.
  • Plug in and use the System Settings toggle if you run agents daily on a desk-bound Mac.

Whichever you pick, let the display sleep (-i without -d) so the screen is not lit for an hour while nobody looks at it. The agent needs CPU and network, not the backlight.

Which method should you use?

SituationBest optionWhy
Mac on a desk, always plugged inSystem Settings toggleSet once, never think about it
One long command or buildcaffeinate -i <command>Ends automatically with the job
Download, call or presentation on batteryKeep Awake with a timerOne click, visible, cannot be forgotten
AI agent running in an IDEKeep Awake, 2 to 4 hour timerNo Terminal needed, auto-expires
Lid closedClamshell mode + any of the aboveNeeds power, external display and input device

FAQ

Does caffeinate keep a Mac awake with the lid closed?

No. caffeinate prevents idle sleep only. Closing the lid is an event, not idle time, and it sleeps the Mac unless you are in clamshell mode (power plus an external monitor) or have run sudo pmset -a disablesleep 1.

MacBook Pro sleeps when the lid is closed even with an external monitor. Why?

Clamshell mode needs three things: the power adapter connected, the external display attached and awake, and an external keyboard or mouse. Miss one and macOS sleeps on lid close. There is no "close lid settings" toggle in System Settings; the trio is the setting.

How do I keep my Mac awake when the lid is closed?

Only in clamshell mode: power, external display and an external keyboard or mouse. Then enable the System Settings toggle or Keep Awake. Without an external display, closing the lid always sleeps the Mac.

What is the terminal command to keep a Mac awake?

caffeinate -d -i -t 3600 for one hour of display and system wakefulness, or caffeinate -i <command> to stay awake while a command runs.

Can I keep my Mac awake on battery?

Yes, with caffeinate or Keep Awake. System Settings only offers the option for power adapter. Use a timer so a drained battery does not shut the Mac down mid-task.

Is there a Caffeine alternative for Mac that still works?

Korinotch Keep Awake is free, runs on macOS 14 and later, and adds timed sessions. It is one of eleven free mini apps from Korinotch.

Keep Awake, free, one click

Stop your Mac sleeping during downloads, calls and long AI sessions. Timed sessions, lid-closed support on power, no Terminal.

Get Keep Awake free