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):
-iprevents idle system sleep. This is the default when you pass no flags.-dprevents the display from sleeping.-sprevents system sleep, but only on AC power.-t secondsreleases the assertion after a timeout.-w PIDreleases it when a given process exits.
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:
- 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.
pmset disablesleep. Many people runsudo pmset -a disablesleep 1so the Mac stays awake with the lid closed, thensudo pmset -a disablesleep 0to undo it. This option is not listed in thepmsetman 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:
- Linux. On a server or an always-on dev box this usually is not an issue. On a laptop, wrap the agent with
systemd-inhibit(for examplesystemd-inhibit --what=sleep:handle-lid-switch claude) or change the lid behavior in logind's configuration. Desktop environments have their own power settings, so check your distribution's documentation. - Windows. PowerToys Awake keeps the PC awake for a set time or indefinitely without touching your power plan. Lid behavior is separate: change it under Control Panel › Power Options › "Choose what closing the lid does", or with
powercfgandLIDACTION. Per Microsoft's docs, Awake only requests that the system stay awake, so set the lid action to "Do nothing" separately if you need it.
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:
- The computer shows as offline. Once the relay sees the connection drop, the phone marks that computer offline and its tasks become read-only.
- Synced content stays readable. Tasks and conversations that reached your phone before the Mac slept are still there to scroll through.
- Actions are disabled. Approving, following up, starting and stopping tasks all need the computer online. The app says the device is offline instead of letting you tap and wait.
- No completion notifications. A sleeping computer means a paused agent, so there is no "finished" or "needs you" push. If you are expecting a notification that never arrives, check whether the Mac fell asleep. More on how notifications work in this post.
- It reconnects on wake. When the computer wakes and gets back online, BotBus reconnects and resends its full state, and the phone shows it online again. BotBus does not touch the agent's child processes when it disconnects, so a brief network drop does not kill a running turn.
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
- BotBus neither prevents sleep nor wakes the computer remotely. Everything on the phone waits until the computer is awake and online.
- Every keep-awake method has a cost. Staying awake uses power, a closed laptop runs hot, and
pmset disablesleepis undocumented and behaves differently across machines. - Waking up is not the same as resuming. Network requests can time out while the agent is suspended, so the turn may fail after wake. Send a follow-up from your phone to get it going again.
- Queued commands expire. The phone already disables actions for an offline computer. Commands queued during a short disconnect are dropped if the computer has not received them within 10 minutes.
- Content is encrypted; metadata is not. Conversations, commands and results are encrypted on your devices before they reach the relay, so it cannot read them. It can still see device IDs, online status, update times and data sizes, which means the relay knows whether your computer is online. Details are in the security overview.
- Platforms. The desktop side runs on macOS (a menu bar app, macOS 26 or later), Linux and Windows. The iPhone and Apple Watch apps are on the App Store (iOS 26 / watchOS 26 or later), and the Android app needs Android 8.0 or later and is available from the download section of the website.
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.