Keep your Mac awake — including with the lid closed — but only while a Claude Code or Codex agent turn is actively running. When the agent is idle, your Mac sleeps normally.
Existing keep-awake tools either don't work with the lid closed
(caffeinate, KeepingYouAwake) or trigger on "app is running" — which keeps you
awake all day just because the editor is open. agentawake hooks into the
agent's turn lifecycle, so wakefulness tracks actual work.
UserPromptSubmithook → a turn starts → a token is written.Stophook → the turn ends → the token is removed.- An idempotent
reconcile(run from every hook and from a ~60s launchd agent) prunes dead/abandoned tokens and togglespmset disablesleepthrough a tiny passwordless-sudo root wrapper.
A dead, crashed, or interrupted turn is cleaned up automatically (process-liveness check + a max-age cap), so sleep is never left disabled indefinitely.
brew install meshulga/tap/agentawake
agentawake install # wires hooks + the privileged toggle; asks for your password onceRestart any running Claude Code / Codex sessions afterwards so they pick up the hooks.
go build -o agentawake .
./agentawake help
./agentawake version
go test ./...
go test ./internal/reconcile/ -v
go test ./internal/reconcile/ -run TestDecide -v
go vet ./...To try a command without writing a local binary:
go run . status
go run . version| Command | Purpose |
|---|---|
agentawake install / uninstall |
Set up / remove everything (one password prompt) |
agentawake status |
Show active sessions and current sleep state |
agentawake off |
Emergency reset: clear state, restore normal sleep |
agentawake reconcile |
Re-sync (used by the launchd agent) |
agentawake version |
Print the installed version |
The pmset disablesleep mechanism is undocumented by Apple. It was verified on
Apple M4 Pro, macOS 26.5. agentawake install runs a self-check and refuses
to proceed if the mechanism does not behave as expected on your machine.
MIT