A Mac goes to sleep for two different reasons, and almost every “how to keep my Mac awake” answer only covers the first one. Knowing which one you're fighting saves a lot of frustration.
- Idle sleep. Nobody has touched the keyboard or trackpad for a while, so macOS turns off the display and then sleeps the system. Settings,
caffeinateand most keep-awake apps handle this. - Lid-close sleep. You shut a MacBook's lid. macOS sleeps right away, regardless of idle timers — unless you're in clamshell mode with an external display, or the
disablesleepswitch is on.
If your Mac is a desktop, or your MacBook stays open, methods 1 and 2 are all you need. If the lid will be closed, skip to method 3.
1. System Settings (no Terminal)
macOS has a checkbox that stops the system from sleeping on its own while the display is off. Where it lives depends on the Mac and the macOS version:
- MacBook (macOS Ventura and later): System Settings → Battery → Options… → Prevent automatic sleeping on power adapter when the display is off. As the name says, it only applies on the charger.
- iMac, Mac mini, Mac Studio: System Settings → Energy (called Energy Saver on Ventura) → Prevent automatic sleeping when the display is off.
- Display timeout: System Settings → Lock Screen controls when the screen turns off. A longer timeout keeps the screen on but doesn't by itself keep the system awake.
This is the right fix for a desktop Mac that serves files, runs a media server or takes remote logins. It does nothing for a closed MacBook lid. We cover the desktop case in detail in how to stop an iMac or Mac mini from sleeping.
2. caffeinate (built in, temporary)
caffeinate is a command-line tool that ships with every Mac. It holds a “power assertion” — a polite request to macOS not to sleep — for as long as it runs. Open Terminal and type:
caffeinate -i
Your Mac now won't idle-sleep until you press Control-C or close the window. Two variations people actually use:
# stay awake only while a command runs
caffeinate -i npm run build
# stay awake for two hours (7,200 seconds)
caffeinate -i -t 7200
Because it's temporary, caffeinate is the safest method: when the process ends, normal sleep returns automatically. Every flag is explained in our caffeinate guide, and the caffeinate command builder writes the command for you.
caffeinate prevents idle sleep. Close a MacBook's lid without an external display and it sleeps anyway, assertion or not.3. pmset disablesleep (works with the lid closed)
There is one switch that overrides lid-close sleep: disablesleep in pmset, the power-management tool. It needs administrator rights:
# turn sleep off entirely — lid closed included
sudo pmset -a disablesleep 1
# check: "SleepDisabled 1" means sleep is off
pmset -g | grep SleepDisabled
# IMPORTANT: turn normal sleep back on afterwards
sudo pmset -a disablesleep 0
It works, and it's free. The danger is that it's persistent: nothing turns it back off for you. Forget the last command, close the lid and put the Mac in a bag, and it stays awake until the battery is empty — while running warm with no airflow. If you use this method, make the undo command a habit, and run pmset -g before you pack up.
4. Clamshell mode (Apple's official lid-closed setup)
Apple supports running a MacBook with the lid closed when it's connected to power, an external display, and an external keyboard and mouse or trackpad. If your Mac lives on a desk with a monitor, this is the cleanest way — no tools, no settings. It doesn't help when you want to unplug and walk away. See clamshell mode without an external display for what changes when the monitor isn't there.
5. A keep-awake app
Apps wrap the methods above in a menu-bar toggle. The important question is which method they wrap:
- Idle-only apps (KeepingYouAwake and other
caffeinatewrappers) are free and harmless, but they stop at the lid. - Lid-closed apps use the
disablesleepswitch or a related private mechanism. Here, the thing to check is what happens when the app quits or crashes: does sleep come back, or is your Mac left awake like in method 3?
That last point is why we built Lidwork: it keeps the Mac awake with the lid closed from the menu bar, without sudo, and a small background part turns normal sleep back on if the app crashes, when your battery reaches 10, 20 or 30%, or when the Mac gets too hot. We compare the options honestly in Lidwork vs the rest.
Which method should you use?
| Situation | Best method | Reverts by itself? |
|---|---|---|
| Long download, lid open | caffeinate -i | Yes, when it exits |
| Desktop Mac that should never sleep | System Settings → Energy | No — it's a setting |
| MacBook on a desk with a monitor | Clamshell mode | Yes, unplug and it sleeps |
| MacBook closed, no monitor, short task | pmset disablesleep 1 + undo | No — you must undo |
| MacBook closed in a bag, regularly | A lid-closed app with crash recovery | Depends on the app |
How to check what's keeping your Mac awake
If your Mac won't sleep when you want it to, two commands tell you why:
# is the global switch on?
pmset -g | grep SleepDisabled
# which apps hold assertions right now?
pmset -g assertions
If SleepDisabled shows 1 and you don't know why, a tool (or an earlier you) left it on: sudo pmset -a disablesleep 0 fixes it.