Disable macOS system sleep while local coding agents are running, while leaving display sleep unchanged.
The watcher runs every 10 minutes through launchd. If it finds an agy, codex, or claude process, it runs:
pmset -a disablesleep 1If none of those processes are running, it runs:
pmset -a disablesleep 0chmod +x agent-sleep-guard.zsh
sudo ./agent-sleep-guard.zsh installThe installer writes a root LaunchDaemon to:
/Library/LaunchDaemons/com.local.agent-sleep-guard.plist
The daemon starts immediately, runs every 10 minutes, and starts again after reboot.
./agent-sleep-guard.zsh statusExample:
agent_process_running=yes
launchdaemon_loaded=yes
SleepDisabled=1
sudo ./agent-sleep-guard.zsh uninstallUninstalling removes the LaunchDaemon and resets disablesleep to 0.
- This is for macOS.
- The script must be installed with
sudobecausepmset disablesleepand system LaunchDaemons require root. - The script detects agent processes by process name and command line.
- The script intentionally does not change
displaysleep. - If a stale
agy,codex, orclaudeprocess is still running, sleep remains disabled until that process exits or is killed.