How to keep a MacBook awake with the lid closed, on battery
Close a MacBook that runs on battery and it goes to sleep, almost whatever you have set. Here is why, and the four ways around it, from free to paid.
Short answer. Apple only supports a closed lid with power, an external display and a keyboard (“closed-display mode”). On battery, without a display, you need either the unofficial sudo pmset -a disablesleep 1 (remember to undo it) or a menu bar app that does it for you. caffeinate and the Energy settings don’t cover the lid.
Why the lid wins over your settings
macOS has two separate kinds of sleep. Idle sleep happens when nobody touches the Mac for a while; the Energy settings, caffeinate and most “keep awake” apps prevent it by holding a power assertion. Lid sleep happens the moment you close a MacBook, and it doesn’t care about those assertions. That’s why a Mac that stays awake for hours on your desk falls asleep as soon as it goes into your bag.
The one exception Apple supports is closed-display mode (also called clamshell mode): with the power adapter connected, an external display and an external keyboard and mouse, you can close the lid and keep working on the big screen (step-by-step in OWC’s guide). It’s great at a desk. It doesn’t help on a train.
Option 1: closed-display mode (free, official)
Connect power, an external display and a keyboard or mouse, then close the lid. Nothing to install. It needs all three things, so it is a desk setup, not a travel one. Some owners report that the external display goes dark when they unplug power with the lid closed (Apple Community).
Option 2: caffeinate (free, built in)
caffeinate is perfect while the lid is open: caffeinate -i -w <pid> keeps the Mac awake until a process ends. With the lid closed on battery it doesn’t help: even its -s flag, the one that prevents system sleep, “is valid only when system is running on AC power” according to its manual. The details are in why caffeinate doesn’t work with the lid closed.
Option 3: pmset disablesleep (free, unofficial)
This Terminal command switches sleep off for the whole system, lid included:
sudo pmset -a disablesleep 1 # sleep off
sudo pmset -a disablesleep 0 # back to normal
It works on most Macs, but it isn’t in Apple’s pmset manual, it needs your password, and above all it stays on until you turn it off, through restarts too. A Mac that never sleeps, in a closed bag, is exactly the situation you want to avoid. Read pmset disablesleep: what it does and how to undo it before you use it.
Option 4: a menu bar app (free or paid)
Several apps wrap one of the methods above and add the safety you would otherwise have to remember yourself:
- Amphetamine (free, Mac App Store) has a Closed-Display Mode. On Apple silicon its developer offers an extra script, installed with your admin password, to keep it holding when you plug or unplug power. Results vary by Mac and macOS version, so test it.
- Clamshell (clamshell.dev, $9.99 once, Apple silicon) and Vigil (appsbymo.app/vigil, paid, a helper installed once with your password) are built for AI coding agents.
- Hibernot, the app on this site: no password, a time limit, a stop at the battery temperature you choose and phone notifications. More on the home page.
- Open-source tools on GitHub (Sleepless, LidAwake, StayAwake and others) mostly use
pmsetwith a one-timesudoersrule.
Whatever you pick, look for these four things: a time limit, a battery floor, a heat stop, and normal sleep coming back by itself if the app quits, crashes or the Mac restarts.
| Option | Lid closed on battery | Password | Undoes itself | Cost |
|---|---|---|---|---|
| Closed-display mode | No (needs power and a display) | No | Yes | Free |
caffeinate | No | No | Yes | Free |
pmset disablesleep | Yes, on most Macs | Yes | No | Free |
| Menu bar apps | Yes | Depends on the app | Usually | Free to ~€10 |
Before you close the lid
- Keep it online. A Mac that is awake but offline can’t finish a download or a Claude Code run. When you leave, switch to your phone’s hotspot first.
- Check the battery. A closed Mac still uses power. Know how many minutes you have.
- Mind the heat. A bag holds heat. Measured numbers in is it safe to put a running MacBook in a backpack?
- Test once. Close the lid for ten minutes, then check with pmset -g log whether it really stayed awake.