How to keep your Mac from going to sleep, lid closed too
· Updated · By Mert Duzgun
To keep your Mac from going to sleep, open System Settings > Lock Screen and set both "Turn display off" timers to Never, then turn on "Prevent automatic sleeping" in Battery > Options (laptop, on power) or in Energy (desktop). For one job only, run caffeinate -i in Terminal instead and leave your settings alone. Closing a MacBook's lid is a separate case: it sleeps anyway, unless you use closed-display mode or one of the workarounds below.
The menu names below are from Apple's Mac User Guide for macOS 26 Tahoe, and they are the same in macOS 27 Golden Gate. We checked them on October 29, 2026. Where macOS 13 Ventura or 14 Sonoma differ, we say so.
Pick your method
| What you want | Method | Lid closed? | Undo |
|---|---|---|---|
| Screen stays on | Lock Screen timers to Never | No | Set the timers back |
| Mac stays awake, screen can go dark | Prevent automatic sleeping (Battery or Energy) | No | Turn the option off |
| Awake for one job only | caffeinate -i |
No | Ends with the job |
| Sleep timer off, from Terminal | sudo pmset -a sleep 0 |
No | sudo pmset restoredefaults |
| Laptop awake with lid closed | Closed-display mode, caffeinate -s, or pmset disablesleep |
Yes | See the lid section |
| A click in the menu bar | Amphetamine, KeepingYouAwake, Caffeine | Depends on the app | End the session |
1. Keep the screen on
The display turns off after a set time with no input, and on a laptop the Mac sleeps soon after. To change the timer:
- Choose Apple menu > System Settings.
- Click Lock Screen in the sidebar. You may need to scroll down.
- Set Turn display off on battery when inactive to a longer time, or Never.
- Set Turn display off on power adapter when inactive the same way.
A desktop Mac shows only one display timer. This path is the same on macOS 13 and later. If you also want to stop the screen saver, set Start Screen Saver when inactive on the same page to Never.
2. Keep the Mac awake while the screen turns off
Often you want a dark screen while a download, a backup or a build keeps going. There is one setting for that.
On a laptop (macOS 14 Sonoma and later):
- Choose Apple menu > System Settings.
- Click Battery in the sidebar.
- Click Options.
- Turn on Prevent automatic sleeping on power adapter when the display is off.
It works only on the power adapter. On battery the Mac still sleeps after the display turns off. On macOS 13 Ventura, Apple's guide puts this option in the advanced Displays settings instead.
On a desktop Mac (Mac mini, iMac, Mac Studio, Mac Pro): System Settings > Energy, then turn on Prevent automatic sleeping when the display is off. On macOS 13 and 14 the pane is called Energy Saver.
What Low Power Mode does not do
Some guides tell you to set Low Power Mode (System Settings > Battery) to Never to stop sleep. Low Power Mode lowers energy use; it is not a sleep timer. Leave it as it is, unless you want full speed for other reasons.
3. Turn off sleep from Terminal with pmset
pmset is the command line tool behind these settings. It has a system sleep timer that System Settings does not show on a laptop. Its manual says to "use a minutes argument of 0 to set the idle time to never". You need an administrator password.
Turn off the system sleep timer on the power adapter only:
sudo pmset -c sleep 0
Use -b for battery, or -a for both. To also keep the display on, add displaysleep 0:
sudo pmset -a sleep 0 displaysleep 0
See what is set for each power source:
pmset -g custom
To go back to Apple's defaults, run sudo pmset restoredefaults. The manual says it "restores power management settings to their default values".
Like the settings in section 2, pmset sleep 0 does not stop the sleep that comes from closing the lid.
4. Keep it awake for one job: caffeinate
If you want the Mac awake only while something runs, change nothing. Open Terminal and put caffeinate -i in front of the command:
caffeinate -i ./backup.sh
The Mac does not idle sleep until the command ends. Or keep it awake for a fixed time, in seconds:
caffeinate -i -t 7200
That is two hours. Press Ctrl+C to stop it early. Our guide to the caffeinate command covers every flag.
5. With the lid closed
None of the above stops a MacBook from sleeping when you close the lid. Apple lists closing the display as one of the ways to put a laptop to sleep, so it is not the idle sleep that the timers control. You have three options. Our guide on how to keep a Mac awake with the lid closed has each one with a test.
With an external display: closed-display mode. This is the way Apple supports. Apple's requirement: "If the display is connected to a Mac laptop computer with a closed lid, make sure that the Mac is connected to power and using an external keyboard and mouse." Connect power, the display, a keyboard and a mouse, then close the lid.
On power, without a display: run caffeinate -s. It holds a PreventSystemSleep assertion, which the manual says "is valid only when system is running on AC power". On power, that keeps a closed MacBook running.
On battery: run sudo pmset -a disablesleep 1. It turns sleep off completely, lid closed included. It is widely used, but it is not in the pmset manual, so it is undocumented and could change. pmset -g shows it as SleepDisabled 1. Turn it off when you are done:
sudo pmset -a disablesleep 0
A closed laptop that cannot sleep keeps using power, and in a bag it has little air. Do not put an awake laptop in a bag and forget it.
6. Apps that keep a Mac awake
If you would rather click than type, these menu bar apps do the job.
- Amphetamine. Free on the Mac App Store. Sessions run until you stop them, for a set time, or until a set time, and Triggers start sessions for you, for example while an app runs. It has a closed-display mode; on Apple silicon laptops that mode needs a separate install named Power Protect. See our guide to Amphetamine.
- KeepingYouAwake. A small open source app; its README calls it "a small wrapper around Apple's
caffeinatecommand line utility". Install it withbrew install --cask keepingyouawake. - Caffeine. A coffee cup in the menu bar: click to stay awake, click again to stop. See our guide to Caffeine for Mac.
When Agent Caffeine fits
We make Agent Caffeine, and it fits one case: you run AI coding agents such as Claude Code, Codex or opencode, and you want the Mac awake only while they work.
- It finds more than 40 agents, and reads from Claude Code and Codex whether they work, wait for you or are idle.
- When every agent is done, the Mac sleeps as usual, so you do not have to remember to undo anything.
- A closed lid on power works from the start. On battery it needs a small helper that you allow once in System Settings.
- It lets the Mac sleep when the battery gets low or the Mac gets too hot.
It has a trial and needs macOS 13 or later. If you do not run coding agents, the built-in methods and apps above are the right ones.
Check why your Mac will or will not sleep
To see which apps hold the Mac awake right now:
pmset -g assertions
Look under "Listed by owning process". A browser playing video, a call app, or a forgotten caffeinate often shows up there. pmset -g also lists, next to sleep, the processes that are preventing sleep. For the history of sleeps and wakes, run pmset -g log | grep -i -E "sleep|wake" | tail -20.
Apple also lists common reasons a Mac does not sleep: the prevent automatic sleeping option is on, Wake for network access is on, other people use shared files or printers on your Mac, or a connected device does not work as it should.
Questions
How do I turn off sleep mode on a Mac completely?
On a desktop Mac, turn on "Prevent automatic sleeping when the display is off" in System Settings > Energy. On a laptop, the same option in Battery > Options works only on power. To turn off the sleep timer everywhere, run sudo pmset -a sleep 0 in Terminal, and undo it with sudo pmset restoredefaults.
Why does my Mac go to sleep so fast?
On a laptop, the Mac sleeps soon after the display turns off, and the display timer in System Settings > Lock Screen can be as short as one minute. Set "Turn display off on battery when inactive" and "Turn display off on power adapter when inactive" to a longer time, or Never.
Does Low Power Mode make my Mac sleep?
No. Low Power Mode, in System Settings > Battery, lowers energy use. It is not a sleep setting. Some guides tell you to set it to Never to keep the Mac awake, but the settings that control sleep are the display timers in Lock Screen and the prevent automatic sleeping option.
How do I keep my MacBook awake with the lid closed?
With an external display, connect power, a keyboard and a mouse, then close the lid (Apple calls this closed-display mode). Without a display, caffeinate -s works on power. On battery, only the undocumented sudo pmset -a disablesleep 1 does it, and you must turn it off again.
Is it bad to never let a Mac sleep?
It is not harmful to the hardware, but the Mac uses more power, and a laptop drains its battery and runs warmer. A closed laptop that stays awake in a bag can get hot. Keep it awake only while a job needs it.
Sources
- Apple Support: Set sleep and wake settings for your Mac (macOS 26 Tahoe; also the current version)
- Apple Support: If your external display is dark or low resolution (closed-display mode requirements)
- Apple Support: If your Mac sleeps or wakes unexpectedly
man pmset(pmset(1), macOS) andman caffeinate(caffeinate(8), macOS)- Amphetamine on the Mac App Store
- KeepingYouAwake on GitHub