How to keep your Mac awake while Claude Code or Codex runs

Stop your Mac from sleeping in the middle of a long AI task: caffeinate, Energy settings, and a keep-awake rule that follows your AI sessions.

Updated View as Markdown

A long Claude Code or Codex run that stops because the Mac went to idle sleep is one of the more annoying ways to lose an afternoon. The agent isn't moving the mouse, so macOS thinks nobody is there.

Here are the ways to prevent that, from built-in to automatic.

Option 1: caffeinate in Terminal

macOS ships with caffeinate, a command that prevents sleep on behalf of another command. Its manual page (man caffeinate) describes these options:

  • -i prevents idle sleep (the default when you pass no flags).
  • -d keeps the display awake.
  • -s prevents system sleep, but only on AC power.
  • -t sets a timeout in seconds; -w waits for a process ID to exit.

The neat trick is to wrap the agent itself. The assertion lasts exactly as long as the command:

caffeinate -i claude

Or keep an already running process covered until it exits:

caffeinate -i -w <pid>

This is free and precise. The downside: you have to remember it every time, it covers one process, and agents running in a desktop app or several terminals need separate commands.

Option 2: System Settings

Apple's sleep and wake settings include Prevent automatic sleeping on power adapter when the display is off (laptops, System Settings → Battery → Options) and Prevent automatic sleeping when the display is off (desktops, System Settings → Energy).

These are always on, not tied to your AI work. Apple notes that preventing sleep can increase power use.

Option 3: keep-awake that follows your sessions

Void Island has a built-in keep-awake plugin (the coffee cup) with a rule made for this: Keep awake while AI runs.

While any connected AI session is running or waiting for you, the Mac won't idle-sleep. When all sessions stop, it lets go 2 minutes later. It covers every connected agent, in any terminal or desktop app.

Turn it on

The automatic rules only apply in Advanced mode, which is off when you first install.

  1. Open Settings → Keep awake and turn on Advanced mode.
  2. Check that Keep awake while AI runs is on. It is on by default once Advanced mode is on.

The other settings on that page:

  • Display on when kept awake automatically: off by default, so the screen can still dim and sleep while the Mac keeps working.
  • Automatic only on power: pause the automatic rules on battery.
  • Stop below battery: on battery, below this level (10% by default), keep-awake stops and tells you.
  • Keep awake while these apps run: add apps by name or bundle ID, such as Xcode.

Or start a session by hand

With Advanced mode off, just click the cup on the island; an orange cup next to the cat means it's on, until you click it again.

With Advanced mode on, start one from the island's Keep awake tab: 15 minutes, 30 minutes, 1, 2 or 3 hours, indefinitely, until a time today, or until AI sessions end. Manual sessions keep the display on by default, and can keep running with the lid closed (Stay awake with the lid closed during manual sessions). On battery, that keeps draining and the Mac can get warm.

Void Island uses the standard macOS sleep assertion (IOPMAssertion).

Limits

  • Automatic rules, including the AI rule, need Advanced mode.
  • The lid-closed option applies to manual sessions, not the automatic AI rule.
  • Keep-awake prevents idle sleep. It doesn't stop you from putting the Mac to sleep yourself.
  • If you turn off the keep-awake plugin, its rules stop too. At least one of the three built-in plugins has to stay on.

Full details: Keep awake.

Common questions

Does caffeinate stop the display from turning off?

Only with -d. Without flags it prevents idle sleep, so the display can still turn off while the agent keeps running.

Is Void Island's keep-awake available in free mode?

Keep-awake isn't in the list of features that need a license. Free mode limits multiple sessions, approvals, questions, jumping back and action shortcuts. See License.

Why did my Mac still sleep during an AI run?

Check that Advanced mode is on in Settings → Keep awake; without it, the automatic rules don't run. Also check Automatic only on power and Stop below battery if you were on battery.

Do I still need Amphetamine or a similar app?

Not for this. Void Island covers durations, end times, app-based rules and a lid-closed mode. If you already use another keep-awake app, both can run.