Lock, display sleep, system sleep: only one kills your agent
A black screen can mean three different things. Two of them are completely safe for a running agent.
Lock without sleeping
Press ⌃⌘Q to lock immediately. Your session stays alive behind the login screen, and so does the agent.
Let the display sleep, not the Mac
In System Settings › Battery › Options, turn on "Prevent automatic sleeping on power adapter when the display is off". Plugged in, the screen can go dark on its normal schedule while the Mac keeps working.
On battery, there's no equivalent setting — the Mac will idle-sleep on its own schedule. Wrap the run in caffeinate -i to hold it off.
The short version
Lock freely. Let the screen sleep. Keep the system awake — and remember that closing the lid on battery is system sleep, no matter what else you've set.
Locked and walked away, there's one thing the built-in tools still can't handle: an agent that stops to ask "allow this command?" sits blocked behind your lock screen until you come back. UnIdle covers the whole routine:
- ⌥⌘L locks the Mac and lets the display sleep, while UnIdle holds system sleep off for the agent.
- It lets go when the agent finishes, so the Mac sleeps normally again.
- When Claude Code needs a yes, you're told right away — on your Mac, or with Pro, on your phone.