How to keep your Mac awake while Claude Code is running
Updated 16 November 2026
Start the agent with caffeinate -i, for example caffeinate -i claude, and the Mac will not idle-sleep until it exits. NotchDaddy does the same thing automatically whenever an agent is working. Closing the lid on battery still puts a MacBook to sleep.
A Mac that is left alone goes to sleep, and a sleeping Mac runs nothing. If you start a long task in Claude Code and walk away, you can come back to find it stopped a few minutes after you left. There are three ways to prevent that, and one situation none of them covers.
Why does the agent stop when I walk away?
macOS has two separate timers. One turns the display off. The other puts the whole computer to sleep when nobody has touched it for a while, which is called idle sleep. The display turning off is harmless: programs keep running behind a dark screen. Idle sleep is the one that pauses your agent, along with everything else.
On a MacBook running on battery, idle sleep comes quickly by default, because Apple tunes it to save power.
How do I use caffeinate?
caffeinate is a small command that ships with macOS. It asks the system not to sleep for as long as it is running. The most useful form wraps another command:
caffeinate -i claude
The Mac will not idle-sleep until that claude session exits, and then normal behaviour returns by itself. The flags that matter, from the command’s own manual page (man caffeinate):
-iprevents the system from idle sleeping. This is the one you want for agents, and it works on battery.-dprevents the display from sleeping. You rarely need it; a dark screen does not stop the agent.-sprevents the system from sleeping at all, but the manual says it is valid only when the Mac is on AC power.-t 3600keeps the assertion for a number of seconds, here one hour.-w <pid>waits for a process that is already running, which helps when you forgot to start withcaffeinate.
For that last case, open a second terminal tab and run:
caffeinate -i -w $(pgrep -n claude)
pgrep -n picks the most recently started process named claude. If you have several sessions open, check the process id with pgrep -l claude first.
Can I change it in System Settings instead?
Yes, if you want the Mac to stay awake all the time and not only for one command.
- On a MacBook, open System Settings, Battery, then Options, and turn on “Prevent automatic sleeping on power adapter when the display is off”. This applies only while plugged in.
- On a desktop Mac, the same kind of switch is under System Settings, Energy.
- Under System Settings, Lock Screen you can set how long the display stays on, separately for battery and power adapter.
The names of these settings have moved between macOS versions, so search for “sleep” in System Settings if yours looks different. The drawback of a global setting is that it stays on after the agent has finished, which costs battery when you forget about it.
What happens when I close the lid?
This is the case to be careful with. Closing the lid puts a MacBook to sleep, and caffeinate -i does not change that. Idle sleep and lid-close sleep are different things.
The exception is what Apple calls closed-display mode. A Mac laptop keeps running with the lid shut when it is connected to power, an external display, and an external keyboard and mouse or trackpad. Apple describes the requirements in its support article on closed-display mode. On battery with the lid closed, it sleeps.
There are tools and pmset settings that force a MacBook to stay awake with the lid closed. Be wary of them. A laptop running hard inside a closed bag has nowhere to send its heat. If you need a task to survive being carried around, a remote machine is the safer answer.
So the practical rule is: leave the lid open, or dock the laptop to power and a display.
How does NotchDaddy handle it?
NotchDaddy has a setting called “Keep the Mac awake while agents work”. With it on, the app holds off idle sleep while any agent it tracks is busy and lets go when they have all finished. It is the same effect as caffeinate -i, without remembering to type it and without leaving the Mac awake afterwards.
What that covers:
- You step away and the Mac would have idled to sleep: the agents keep going.
- You lock the screen: the agents keep going.
- You are on battery with the lid open: the agents keep going, at some cost in battery.
- You close the lid with power and an external display attached: the agents keep going, as macOS allows.
What it does not cover is closing the lid on battery. The Mac sleeps and the agents pause until you open it again. NotchDaddy does not try to override that.
Staying awake is only half of leaving an agent alone. The other half is the agent stopping to ask a question while you are away, which is covered in getting notified when Claude Code is waiting and on the agents page.
Which should I use?
If you run a long task now and then, caffeinate -i claude is free and built in. If your Mac is a desk machine that should never sleep while plugged in, set it once in System Settings. If you run agents most days and do not want to think about it, NotchDaddy does it only while they are working. It is free to try for 3 days.