Blog · · Dimitris Kyriakakis

Keep your Mac awake while Claude Code, Codex or Cursor runs

A local coding agent is a process on your Mac. When macOS sleeps, that process stops. A long Claude Code turn, a Codex run waiting on a tool, or a Cursor agent halfway through an edit can stall because nobody touched the keyboard, while the agent still had work to do.

There are two kinds of sleep, and they need different answers.

Idle sleep and lid close

Idle sleep. Nothing has used the keyboard or mouse for a while. Any app can hold this off with a macOS power assertion, which is what caffeinate -i does.

Lid close. Closing a MacBook lid takes a separate path, and power assertions don't reliably stop it. Apple's supported clamshell setup is the Mac on power with an external display, usually with a keyboard or mouse attached. Undocumented pmset tricks exist; they are easy to forget, and they leave a laptop that never sleeps in a bag.

This post covers idle sleep while agents run. Overnight runs with the lid closed are a different problem.

The built-in option: caffeinate

caffeinate -i claude
caffeinate -i codex

-i prevents idle system sleep for as long as the wrapped command runs. The display can still turn off. When the agent exits, the assertion goes with it.

If the agent is already running:

caffeinate -i -w <PID>

To see what is holding the Mac awake:

pmset -g assertions

Wrapping one process has limits:

  • A second agent in another terminal isn't covered.
  • The assertion lasts as long as the process. A session you finished at six but left open keeps the Mac awake all night.
  • Closing the lid still puts the Mac to sleep.

You can also write hooks that start caffeinate when you submit a prompt and stop it when the last session ends, which covers several Claude Code windows at once. Read any script before you install it; it runs on your machine.

What AgentNod's Night watch does

Night watch takes one macOS power assertion, the same kind as caffeinate -i. The display can still sleep, and Night watch doesn't stop the sleep that follows closing the lid.

It holds the Mac awake while:

  • an agent is working
  • a decision is waiting on you
  • a scheduled run is going

When none of those is true, it lets go, and the Mac sleeps on its usual timer. Armed with nothing running, it holds nothing.

Turn it on with the switch in the dashboard, with ⌘⇧W in the dashboard window, or from the menu bar. While it holds, pmset -g assertions lists it as AgentNod night watch: agents are working.

Answering from your phone needs the Mac awake, because the page and the buttons on a push talk to the Mac directly. A scheduled run that stops for permission joins the same queue, so Night watch keeps it answerable too.