# Keep your Mac awake while a coding agent runs

Source: https://ryansam.com/agent-auto-continue/keep-mac-awake/
Published: 2026-10-02 Updated: 2026-10-02

You leave Claude Code halfway through a migration and go to make dinner.
You come back to a sleeping Mac and an agent that stopped 40 minutes ago.

For one terminal command, the fix is free and already on your Mac: `caffeinate -i claude` keeps it awake while that command runs.
The real catch is the lid.
Closing a laptop lid forces sleep, and no ordinary app can stop that, unless you're in closed-display mode (power, an external display and an external keyboard and mouse).

## What keeps running

With the Mac held awake, by `caffeinate` or the app below (adapted from the app's README):

| Your Mac | Agent keeps running? |
| --- | --- |
| Desktop Mac | Yes |
| Laptop, lid open | Yes (the app stops at your battery floor) |
| Laptop, lid open, screen locked or display asleep | Yes, but Claude Desktop and ChatGPT app sends wait for the unlock |
| Laptop, lid closed, in closed-display mode | Yes |
| Laptop, lid closed, no external display, or on battery only | No, it sleeps |

The last row is the one that gets people.

## One command: caffeinate

Put it in front of any command (`caffeinate -i claude`, `caffeinate -i codex`) and the assertion lasts until that command exits.

From `man caffeinate`:

- `-i` stops idle sleep, and it's the default if you give no flag.
- `-d` keeps the display on too.
- `-s` stops system sleep, but only on AC power.

![A terminal runs caffeinate -i sleep 600 in the background, then pmset -g assertions filtered to caffeinate, which shows a PreventUserIdleSystemSleep assertion named caffeinate command-line tool, held on behalf of sleep. A blue box marks the assertion type and name.](https://ryansam.com/_astro/platform-caffeinate-light.BbMseBUI.png)

*pmset showing the assertion caffeinate -i holds, on macOS 26.5.1, 2 October 2026.*

One agent, one terminal, lid open?
That's all you need.

It covers Claude Code's own [usage-limit wait](https://code.claude.com/docs/en/interactive-mode#wait-for-a-usage-limit-to-reset) too, which runs in that same session.
That matters: if the Mac sleeps more than about 30 minutes through the reset, Claude Code waits for Enter ([more](https://ryansam.com/agent-auto-continue/claude-code/)).

## The lid always wins

Apple's [QA1340](https://developer.apple.com/library/archive/qa/qa1340/_index.html) is blunt: "it is not possible to prevent forced sleep, only delay it".
Closing the lid or choosing Sleep from the Apple menu are both forced sleep, so `caffeinate -s` won't save you.

Closed-display mode is the exception: with an external display, [Apple says](https://support.apple.com/en-us/102501) a closed laptop needs power and an external keyboard and mouse.

You'll see `sudo pmset disablesleep 1` suggested.
It's a system setting, not something a process holds, so it survives a crash, and a MacBook in a bag with sleep disabled can overheat ([details](https://github.com/VelvetAcorn/agent-auto-continue/blob/main/docs/keep-awake-investigation.md)).
Not worth it.

## What the app adds

[Agent Auto-Continue](https://ryansam.com/agent-auto-continue/) schedules messages into agent conversations ("Continue" at 03:00, after the reset), and its keep-awake follows that work rather than one command.

- **Opt-in.** Off by default.
- **Only while work waits or runs.** One assertion covers pending schedules, continuations waiting for the limit or the next turn, sends in flight, and the turn a send started.
- **Display can sleep** unless you tick **Keep the display on too**.
  Claude Desktop and ChatGPT app work keeps it on.
- **Lets go.** When the work's done, at the battery floor, at the time limit, on **Let Mac sleep**, and on quit.
  Even on a crash (tested).
- **No admin rights.** Never `sudo`, never changes a system setting.
- **Tells you.** The menu-bar icon and a notice show when the Mac's kept awake, why, and until when.

![The Keep the Mac awake section of Agent Auto-Continue Settings, switched on and waiting for 2 scheduled tasks, with Keep the display on too unticked, Keep awake on battery too, a 20 percent battery floor, a 12 hour time limit and a note on lid, lock screen and sleep.](https://ryansam.com/_astro/keep-awake-light.D-kwwTf8.png)

*Keep-awake in Settings, with the battery floor and time limit beside it.*

Hook-based tools keep the Mac awake while an agent's busy: [nosleep-claude](https://github.com/FabianGenell/nosleep-claude) wraps `caffeinate` in a Claude Code plugin.
[Agents Sleep Preventer](https://github.com/CharlonTank/agents-sleep-preventer) survives a closed lid by flipping that same `pmset disablesleep` through a passwordless sudo rule.
The app also covers the quiet hours before a reset, when nothing's working yet but a send is due.

## Set it up

1. [Install the app](https://ryansam.com/agent-auto-continue/install/).
2. Turn keep-awake on with the laptop toggle in the header, or in Settings > Keep the Mac awake.
3. On a laptop, set a battery floor (or power only) and a time limit.
4. Schedule something.

## The honest limits

- **It can't stop lid-close sleep.** Nothing without root can.
  Missed schedules catch up after the Mac wakes.
- **It can't unlock your screen.** Claude Desktop and ChatGPT app sends wait for the unlock (one-off messages for up to six hours).
- **On battery, it stops at your floor.** macOS still sleeps at a critically low battery.
