BOTBUS / BLOG

Keep your Mac awake while Claude Code or Codex runs

Local Claude Code and Codex runs stop when your Mac sleeps. What caffeinate, pmset and Codex's toggle cover, and what your phone shows meanwhile.

Short answer

No, a local coding agent does not keep running while your Mac sleeps. Claude Code and Codex run as processes on your machine; when macOS goes to sleep they are suspended mid-turn. They may pick up again after wake, or the turn may fail because a network request timed out. Closing a MacBook lid puts it to sleep by default, and even with the lid open the system can idle-sleep after a while.

There are two different problems here. With the lid open, you are fighting idle sleep, and caffeinate or a system setting is enough. With the lid closed, you are fighting lid-close sleep, which is a separate and stricter path that caffeinate cannot override. For that you need clamshell mode with an external display, or an undocumented pmset option.

Below is what each approach actually covers and what it costs. At the end: what you see on your phone in BotBus while the computer is asleep. To be clear up front, BotBus does not prevent sleep. It can tell you the computer went to sleep; it cannot wake it up.

Lid open: stopping idle sleep

System Settings

On a MacBook, System Settings › Battery › Options has a toggle that prevents automatic sleep on power adapter when the display is off; desktop Macs have a similar option under Energy (the exact wording varies by macOS version). Turn it on and the screen can go dark while the system stays awake on AC power. It is set-and-forget, which is also its downside: the Mac stays awake when no agent is running, too.

caffeinate

The built-in caffeinate command is the cleanest option because it only holds a "don't sleep" assertion while you need it. The flags that matter (check man caffeinate on your machine):

The easiest pattern is to wrap the agent itself:

caffeinate -i claude

When claude exits, the assertion goes away with it, so there is nothing to forget. If the agent is already running, caffeinate -i -w <pid> attaches to it. To see what is currently holding the Mac awake, run pmset -g assertions.

Codex's built-in toggle

As of 2026-10-08, OpenAI's documentation lists a Prevent sleep while running setting under Settings › General in the Codex app, available on macOS and Linux. In the Codex CLI, the same thing is an experimental feature you can enable through /experimental. It only applies while a turn is actively running. Between turns, or once a task is done, the Mac sleeps on its normal schedule, and the setting does nothing about a closed lid.

For Claude Code, we did not find a documented sleep setting in Anthropic's docs or changelog. Claims about its internal behavior come from third-party teardowns, so we are not treating them as fact here. Wrapping it in caffeinate yourself is the reliable route.

Menu bar utilities

Tools like Amphetamine do essentially what caffeinate does, with a UI and triggers such as "while this app is running" or "for the next three hours". If you prefer clicking to typing, they are a fine choice.

Lid closed: stopping lid-close sleep

Lid-close sleep ignores caffeinate-style assertions. Two approaches are common:

  1. Clamshell mode. Apple's support documentation says that when you use a closed MacBook with an external display, the Mac should be connected to power and use an external keyboard and mouse. Set up that way, it keeps working with the lid shut. Some users report Apple silicon models doing this on battery, but Apple does not document it, so test it before you depend on it. If you power the Mac through a dock, check that macOS actually reports it is on AC power.
  2. pmset disablesleep. Many people run sudo pmset -a disablesleep 1 so the Mac stays awake with the lid closed, then sudo pmset -a disablesleep 0 to undo it. This option is not listed in the pmset man page, so Apple makes no promises about it, and people report different results across models and macOS versions. Test it on your own machine before an overnight run.

Forcing a closed laptop to stay awake has real costs. Closed in a bag it gets hot. On battery it can drain overnight. If you forget to undo it, the next time you close the lid the Mac will not sleep. The safer setup is plugged in, lid open, with only the display turned off.

Linux and Windows

BotBus also has a Linux host and a Windows host. Neither one prevents sleep either, so use the operating system's tools:

What your phone shows while the computer sleeps

BotBus runs on your computer and syncs your local agents' tasks to your phone and Apple Watch through an end-to-end encrypted relay. When the computer sleeps or loses its network:

In short, BotBus handles "you are away from the computer", not "the computer is asleep". Use the methods above to keep the machine awake, then use your phone to watch progress, approve requests, continue the session, or stop a runaway task.

Limits

FAQ

Does caffeinate keep a MacBook running with the lid closed?

No. caffeinate blocks idle sleep, and lid-close sleep is a separate path. With the lid closed you need clamshell mode (external display plus power) or an undocumented option such as pmset disablesleep.

I turned on Codex's "Prevent sleep while running". Why did my Mac still sleep?

That setting only applies while a turn is actively running. Once the task finishes, or while it waits for your reply, the Mac can sleep normally, and the setting does not cover a closed lid. If the Mac sleeps while an approval is pending, you cannot approve it from your phone. Use caffeinate or the system setting to cover the waiting time too.

Can I still see my tasks in BotBus while the Mac is asleep?

You can read everything that was already synced, but that computer shows as offline and approving, following up, starting and stopping are disabled until it wakes and reconnects.

Can BotBus wake my computer remotely?

No. BotBus has no remote wake feature; it only works while the computer is awake and online.

How do I get started?

Keep the computer awake using one of the methods above, install the latest BotBus on it, and scan the pairing QR code with your phone. Downloads are on the home page.

← All posts