Skip to content

How to prevent a MacBook from sleeping

pmset alone is not enough on a MacBook — the system still sleeps on lid-close or idle user-session timeouts. You need pmset (persistent settings) and a long-running caffeinate -simdu (active sleep assertion).

Terminal window
sudo pmset -a sleep 0 disksleep 0 hibernatemode 0 standby 0 autopoweroff 0 powernap 0
sudo pmset -a disablesleep 1
brew install tmux
tmux new -d -s caffeinate 'caffeinate -simdu'

Read on for what each piece does and alternatives to tmux.

Plug in AC power, then:

Terminal window
sudo pmset -a sleep 0 disksleep 0 hibernatemode 0 standby 0 autopoweroff 0 powernap 0
sudo pmset -a disablesleep 1 # allow lid-closed operation without an external display

Verify:

Terminal window
pmset -g | grep -E 'sleep|hibernatemode|standby'

Keep a caffeinate process running for as long as you want the Mac awake:

Terminal window
caffeinate -simdu

Flags:

FlagPrevents
-ssystem sleep (AC)
-iidle sleep
-mdisk sleep
-ddisplay sleep
-udeclares user activity

Pick whichever way keeps it running long enough for your use case.

Open a new Terminal/iTerm/Ghostty window and run:

Terminal window
caffeinate -simdu

Leave the window open. Closing the window or pressing Ctrl-C stops it.

Option B: nohup (background, survives logout)

Section titled “Option B: nohup (background, survives logout)”
Terminal window
nohup caffeinate -simdu >/dev/null 2>&1 &
disown

Check it is running:

Terminal window
pgrep -fl caffeinate

Stop it:

Terminal window
pkill caffeinate
Terminal window
brew install tmux # if not installed
tmux new -d -s caffeinate 'caffeinate -simdu'

Reattach to inspect:

Terminal window
tmux attach -t caffeinate

Stop it:

Terminal window
tmux kill-session -t caffeinate
Terminal window
screen -dmS caffeinate caffeinate -simdu

Reattach:

Terminal window
screen -r caffeinate

Stop it:

Terminal window
screen -S caffeinate -X quit
Terminal window
pmset -g assertions

You should see PreventUserIdleSystemSleep and PreventSystemSleep held by caffeinate.

Terminal window
pkill caffeinate
sudo pmset -a restoredefaults
  • Still sleeps on lid close: confirm disablesleep is 1 in pmset -g.
  • Docker hangs after wake: disksleep must be 0; restart Docker Desktop.
  • Something else forces sleep: check pmset -g assertions for other processes (backup tools, VPNs) holding conflicting assertions.