No. caffeinate only blocks idle sleep; closing the lid triggers a separate sleep path, so the Mac still sleeps. To keep it awake with the lid closed, Clamshell for Mac is a menu bar app that does it while armed, with no sudo and no external display.
An animated MacBook with a coding agent deploying a website from its terminal. The Option key is held and the lid closes: the display goes black, but the Mac stays awake, so a dimmed copy of the terminal keeps working above the closed laptop while its front edge fills with light. When the deploy is done, a pointer shows how to lift the lid. Opening it wakes the Mac to its lock screen, which unlocks to the finished run: deployed, with the live address. The lid can then be opened and closed freely.
Clamshell for Mac keeps the Mac awake with the lid closed while armed. No sudo, no monitor. Free for 7 days, then $9.99 once.
Apple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or install with Homebrew: brew install --cask clamshell. On your phone? Send the Mac download link to yourself.
No. caffeinate only prevents idle sleep, and closing a MacBook lid triggers a separate sleep path that it does not override, so the Mac still sleeps as soon as the lid shuts, even with a busy command and an active assertion. To keep working with the lid closed you need an external display, sudo pmset -a disablesleep 1, or a lid-closed app such as Clamshell for Mac, a menu bar app that needs no sudo.
Keep a closed MacBook awake instead: Clamshell for Mac in three steps
- Install Clamshell for Mac. Download the free trial from clamshell.dev, or run
brew install --cask clamshell, then open it once. It runs in the menu bar. - Arm it. Right-click the menu bar icon to arm until you turn it off, or press both Option keys to arm for the next close only. Open the menu and check that it says Armed or Armed for Next Close.
- Run your command and close the lid. Start the job as you would have with
caffeinate, then close the lid. The Mac keeps running with the built-in display black, and normal lid sleep returns when you disarm or quit.
The free route is sudo pmset -a disablesleep 1, covered under What works instead: it also keeps a closed Mac awake, but it needs admin rights and stays on, on battery too, until you run sudo pmset -a disablesleep 0. Clamshell for Mac is a paid, closed-source app, $9.99 once from clamshell.dev after a 7-day trial and also on Setapp; it is not on the Mac App Store and is not Apple's clamshell mode, which needs an external display.
What caffeinate actually promises
The macOS manual says that running caffeinate with no flags creates an assertion that prevents idle system sleep. The assertion lasts until the process exits. That is useful for a build, download, presentation, or terminal job when the lid stays open.
caffeinate -i make
caffeinate -i -w 12345
caffeinate -i -t 3600
The first command keeps idle sleep away while make runs. The second follows a process ID. The third expires after one hour. None of them changes what macOS does when it detects a closed lid.
caffeinate -i make keeps idle sleep away while the lid is open. Close the lid and the separate lid-sleep path takes over, assertion or not.The flags do not mean closed-lid mode
-iprevents idle system sleep. This is the default assertion and does not override lid-close sleep.-srequests prevention of system sleep and is valid only on AC power. It still does not configure a MacBook for closed-display operation.-dprevents idle display sleep. That is the opposite of the usual lid-closed goal, where the screen should turn off.-mprevents idle disk sleep. It does not affect the lid.-udeclares user activity and can wake the display. It is not a lid override.
How to see the assertion
- Inspect the assertions. While
caffeinateis running, open another Terminal window and inspect the system-wide assertions:pmset -g assertions - Find the caffeinate entry. You will normally see
PreventUserIdleSystemSleepor another assertion owned bycaffeinate. This confirms that the command is working.
It also explains the limitation: power assertions describe kinds of sleep that software would like to avoid, while the lid switch has its own policy.
What works instead
An external display
Apple's supported closed-display setup uses an external display, power, and external input devices.
Apple's display setup explainedsudo pmset -a disablesleep 1
Another workaround, but it is an undocumented, system-wide, admin-level switch that must be undone manually.
The risks and the undo commandA purpose-built app
A purpose-built app can keep the Mac awake only while you have it on and keep the state visible.
What Clamshell for Mac isClamshell for Mac is one such app. While armed, it covers both sleep paths, the lid and idle sleep, and it does not need sudo. Thermal safety is always on, and a restart always brings back normal lid sleep. The keep-awake mechanisms guide compares every route, including which apps need a helper and what each leaves behind after a crash.
Clamshell keeps the Mac awake when the lid closes, then returns normal sleep behavior when you open it. Free for 7 days, then $9.99 once.
Apple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or install with Homebrew: brew install --cask clamshell. Also on Setapp.
The practical rule
The Mac stays open
Use caffeinate when you want a command to survive idle timers.
The lid will close
Use a closed-display solution when the physical lid will close.
For a full comparison, read Clamshell vs Amphetamine vs pmset. For coding sessions, see keeping Claude Code, Codex, and other agents running, keeping Codex running with the lid closed, and running AI agents overnight. For every option in one place, read how to keep a MacBook awake with the lid closed. Other keep-awake apps hit the same wall: see why KeepingYouAwake sleeps with the lid closed and how to fix Amphetamine not working with the lid closed.
Frequently asked questions
Does caffeinate work with the MacBook lid closed?
No. caffeinate prevents idle sleep. Closing the lid triggers a separate sleep path that caffeinate does not override, so the Mac sleeps when the lid shuts unless an external display, pmset disablesleep, or a lid-closed app is in use. Clamshell for Mac is a menu bar app that keeps a MacBook awake with the lid closed while armed, with no sudo and no external display.
Does caffeinate -s keep a Mac awake with the lid closed?
Not on its own. The -s flag requests prevention of system sleep and only applies on AC power; it does not configure a MacBook for closed-display operation. Test your own setup with the lid closed before relying on it.
Why does my Mac still sleep when caffeinate is running?
If the lid is open, check pmset -g assertions to confirm the caffeinate assertion exists and that the command it follows is still running. If the lid is closed, lid-close sleep is the cause: caffeinate does not cover it.
What should I use instead of caffeinate when the lid is closed?
Use Apple's external-display setup at a desk, pmset disablesleep if you will remember to undo it, or a lid-closed app. Clamshell for Mac is a menu bar app that keeps the Mac awake with the lid closed without sudo and restores normal lid sleep when you disarm or quit.
Does Clamshell for Mac use caffeinate?
No. While armed, Clamshell keeps the Mac awake through both lid-close sleep and idle sleep, with no sudo.
Method: checked against the macOS caffeinate(8) and pmset(1) manuals and verified with pmset -g assertions on an Apple Silicon MacBook.