Mac won't sleep after Claude Code
If the work is done but your Mac won't sleep, or the battery dropped overnight, first find out what's holding it awake.
Find what's holding it awake
Run pmset -g assertions in Terminal to see which processes are blocking sleep. If caffeinate shows up next to PreventUserIdleSystemSleep, something started it; pgrep -fl caffeinate shows the exact command.
While a session is active, Claude Code repeatedly starts caffeinate -i -t 300 to block idle sleep. It respawns every five minutes, so killall caffeinate doesn't stick, and there's no setting to turn it off yet (issue #21432).
Fixing it yourself
The surest fix is to close finished sessions (/exit, or close the terminal window). If you ever ran sudo pmset -a disablesleep 1, check whether SleepDisabled is 1 in pmset -g and undo it with sudo pmset -a disablesleep 0; it survives restarts.
To sleep as soon as work ends with the lid closed, a Stop hook can check the lid and call pmset sleepnow (no sudo). The catch: with several sessions open, it sleeps when any one of them finishes.
With Lidnight
Lidnight watches every Claude Code and Codex session's hooks and sleeps the Mac 10 minutes after the last one goes quiet. With the lid closed it doesn't stay up once the work is done, and while work runs it keeps going lid-closed. It also sleeps at your battery floor or at 45°C. Ways to keep a Mac awake compared
Try Lidnight free
Apple Silicon Macs · macOS 13 or later. Every download includes a 7-day trial of everything in Pro, no payment details needed. Pro is a one-time payment (1 Mac $9.99 · 3 Macs $14.99, 50% off through Oct 31) with a 14-day refund.