You leave Claude Code running, lock the screen, and go to lunch. Later you check in from your phone, and the session doesn't answer: the Mac went to sleep. Locking wasn't the problem. Locked, the Mac keeps running everything. Idle sleep is what s the agent.
Each agent keeps the Mac awake only while it's working on a turn:
caffeinate -i while a turn is running. It lets go while it waits for your approval and after the turn ends./experimental. It also covers only a running turn. sleep_prevention, on by default) and releases it when the turn ends.
No. Locking the screen, or letting the display turn off, leaves every process running. An agent halfway through a task carries on.
Sleep is different. When the Mac sleeps, processes and the network goes down. A request that was on its way to the model can fail, and anything that connects to the Mac from outside can't reach it: Claude Code's remote control from the phone app, an SSH session, a tunnel. When the Mac wakes, the agent picks up where it d, and you may need to tell it to continue if a request failed.
So the question isn't whether the screen is locked. It's whether the Mac is allowed to go to sleep while you're away.
Only while a turn is running.
Claude Code starts caffeinate -i when it begins working and stops it when the turn ends or when it stops to ask for your approval. So if it's waiting on a permission prompt, the Mac can fall asleep.
Codex has the same idea as an experimental feature, off by default. Type /experimental and turn on Prevent sleep while running, or set it in ~/.codex/config.toml:
[features]
prevent_idle_sleep = true
Grok Build keeps the display awake while the agent works and releases it when the turn ends. It's on by default; to turn it off, set this in ~/.grok/config.toml:
[ui.notifications]
sleep_prevention = false
None of them keep the Mac awake between turns. That's exactly when you're waiting to send the next message, from the keyboard or from your phone.
Use caffeinate, which ships with macOS. -i stops idle sleep and lets the display sleep and lock as usual:
caffeinate -i claude
caffeinate -i -t 7200 &
The first form lasts exactly as long as the agent: when you quit Claude Code, normal sleep comes back. The same works with codex or grok.
To keep a MacBook awake whenever it's plugged in, open System Settings → Battery → Options and turn on Prevent automatic sleeping on power adapter when the display is off. That's a standing change, so remember to undo it if you only needed it for one evening.
Run:
pmset -g
The sleep line names the apps holding the Mac awake right now, for example sleep prevented by caffeinate. For the full list, with what each one is preventing, run pmset -g assertions.
This is a quick way to check before you leave. If the line doesn't name anything and the agent is between turns, the Mac will sleep on its normal schedule.
Closing the lid puts a MacBook to sleep, whatever caffeinate, the agents, or the power settings say. Choosing Sleep from the Apple menu does the same.
The exception is running with the lid closed on purpose: with the Mac on power and connected to an external display, keyboard, and mouse, closing the lid keeps it awake. Without that setup, keep the lid open while you need the agent reachable.
Yes. In PonyMux, click the coffee cup at the bottom of the sidebar. It turns accent-colored, and its tooltip reads Keep Awake (On).
The bottom of PonyMux's sidebar with Keep Awake on: the coffee cup is highlighted.
While it's on, PonyMux keeps the Mac from idle sleep, including between turns and while an agent waits for you. The display can still turn off and lock. It doesn't override closing the lid or choosing Sleep, and it has no timer: it stays on until you click the cup again. Turn it off when you're done so the Mac can go back to saving energy.
For the rest of PonyMux's power settings, see Settings and Accessibility.
Originally published on ponymux.com, where the demos are interactive.