# How to Keep Your Mac Awake While Claude Code Runs

> Why long Claude Code runs stop when the Mac sleeps, what caffeinate covers, and what to use once the lid closes.

- Canonical URL: https://getedith.pro/guides/keep-mac-awake-claude-code
- Published: 2026-12-03
- Updated: 2026-12-03

## The short answer

With the lid open, start Claude Code under `caffeinate`, for example `caffeinate -i claude`, and the Mac will not idle to sleep until that session exits. With the lid closed, caffeinate is not enough: a MacBook without an external display sleeps when you shut it, whatever is running. For that case you need closed-display mode or a tool that turns lid-close sleep off for a while, such as Edith's [Lid Awake](https://getedith.pro/extensions/lid-awake).

If the work does not have to happen on your Mac at all, Claude Code's cloud sessions are the other honest answer: Anthropic runs them, and they keep going with your computer off. This guide is about the cases where the agent needs your local files, tools or network.

## Why Claude Code stops when the Mac sleeps

A sleeping Mac pauses every process, so a Claude Code turn in progress simply stops until you wake the machine. Three different things can put it to sleep, and each needs a different fix:

- **Idle sleep.** No keyboard or trackpad input for the time set in System Settings. This is what usually ends a long agent run while you are in a meeting.
- **Display sleep.** The screen turns off but the Mac keeps running. Harmless for the agent, annoying if you want to watch it.
- **Lid-close sleep.** Closing a MacBook sleeps it unless it is on power with an external display and keyboard attached. Power assertions such as caffeinate do not stop it.

## Method 1: run Claude Code under caffeinate

Built into macOS

### Wrap the session in caffeinate

`caffeinate` ships with macOS. Given a command, it holds a power assertion until that command exits, so the Mac stays awake for exactly as long as Claude Code is open.

Terminal

Shell

```
caffeinate -i claude
caffeinate -dis claude
caffeinate -i -w 12345
pmset -g assertions
```

`-i` stops idle sleep, `-d` keeps the display on, and `-s` stops system sleep while on AC power. `-w` waits for an existing process id instead of starting a new one, which helps when Claude Code is already running. `pmset -g assertions` shows who is holding the Mac awake.

## Method 2: let hooks start and stop it

Claude Code runs [hooks](https://code.claude.com/docs/en/hooks) on events such as a prompt being submitted and a turn stopping. Some people use a hook to start `caffeinate` when work begins and end it when Claude stops, so the Mac only stays awake while a turn is actually running. The open source [caffeinate-claude](https://github.com/bmoeskau/caffeinate-claude) project packages that idea. It is neat, but it is one more script to maintain per machine, and it still does nothing for a closed lid.

## Method 3: a keep-awake app

Menu bar apps such as Amphetamine do the same job as caffeinate with a switch and timers, and the cmux terminal has its own keep-awake setting aimed at handing work to an agent. They are good options with the lid open. Our [Amphetamine comparison](https://getedith.pro/alternatives/amphetamine) covers what it does that Edith does not.

## Where these fall short

- **The lid.** Every method above holds the Mac awake only while the lid is open. Close a MacBook with no external display and the agent stops mid-turn.
- **One terminal at a time.** A caffeinate wrapper covers the session it started. Agents in other tabs, or a Codex session next to Claude, each need their own.
- **No safety net.** The undocumented `sudo pmset -a disablesleep 1` keeps a closed MacBook running, but it has no timer and no battery floor. Forget to undo it and the Mac cannot sleep in your bag.
- **You still have to check.** Staying awake is half the job. The other half is knowing when the agent finished, got stuck or stopped to ask you something.

## The Edith way: Keep Awake, Lid Awake and Agents

Edith splits the problem the same way macOS does. [Keep Awake](https://getedith.pro/extensions/keep-awake) is one switch on Home or in the notch that stops idle and display sleep while the lid is open, and lets go when you turn it off. Lid Awake keeps the Mac running with the lid closed, for a set time or until you reopen it, and pauses itself below a battery floor you choose. It needs a MacBook on macOS 14 or later with Apple silicon, and a one-time approval of Edith's background helper in Login Items.

1. **Install Lid Awake and Keep Awake**
   Open Library in Edith's sidebar, find Lid Awake and press Install. Do the same for Keep Awake. Each one adds a card to Home.
2. **Approve the helper once**
   The first time you turn Lid Awake on, macOS asks you to allow Edith's background helper in System Settings, under Login Items. Do this before you leave, not at the door.
3. **Choose how long and a battery floor**
   In Lid Awake's settings, pick How long: Indefinitely, 15 minutes, 30 minutes, 1 hour, 2 hours or Until lid reopens. Then set Auto-pause below to 10%, 20% or 30% battery, so a forgotten session cannot drain the Mac.
4. **Press Keep awake before you close the lid**
   The Lid Awake card on Home shows Lid sleep and Battery floor, with a Keep awake button. The same switch is Keep running with lid closed in its settings. When you are back, the card's Restore sleep button puts normal lid-close sleep back.
5. **Keep agent sessions alive if Edith quits**
   Agents started from Edith's [Agents](https://getedith.pro/extensions/coding-agents) board run in herdr, a separate open source terminal manager. In the Agents settings, under Background, Keep sessions running after Edith quits is on by default.
6. **Check on them later**
   The Agents board lists every agent as blocked, working, done or idle, and its Notifications settings can tell you when an agent needs you, finishes or hits an error.

While the lid is still open and you are watching the first few turns, press Turn on on the Keep Awake card, or use its switch in the notch. Quitting Edith restores lid-close sleep unless you turn off Restore normal sleep when Edith quits.

Mind the heat

A closed MacBook running an agent and a build still makes heat. Leave it on a hard surface with air around it, never in a closed bag, and plug it in for runs longer than an hour or two.

### From the terminal

Every step above also has a command, handy for a script:

Terminal

Shell

```
ed lid-awake battery 20
ed lid-awake on --until-lid-reopens --yes
ed lid-awake status
ed lid-awake off
ed agents background status
```

## Watch the limits while it runs

A Mac that stays awake all night can also use a whole session window. Edith's [Usage](https://getedith.pro/extensions/claude-code-usage) extension keeps your Claude Code session and weekly limits in the menu bar and can alert you before a window runs out. Turn on Enable alerts in Usage's settings before you leave. The [Claude Code usage limits guide](https://getedith.pro/guides/check-claude-code-usage-limits) explains the windows.

## Which tool for which job

- **Lid open, one session:** `caffeinate -i claude` is free and enough.
- **Lid open, several agents:** Keep Awake, Amphetamine or a cmux setting, so one switch covers all of them.
- **Lid closed, at a desk:** closed-display mode with power, a display and a keyboard.
- **Lid closed, away from a desk:** Lid Awake, or `pmset disablesleep` if you trust yourself to undo it.
- **No need for your Mac:** a Claude Code cloud session.

## Common questions

### Does Claude Code keep the Mac awake by itself?

Do not count on it. Anthropic does not document Claude Code holding the Mac awake, and nothing in Claude Code stops lid-close sleep. Wrap it in caffeinate or use a keep-awake tool if a run must finish.

### Do Claude Code background sessions survive sleep?

Sleep pauses every process on the Mac, background or not. Whether a session picks up cleanly after waking depends on what it was doing, so the safer plan is to keep the Mac awake for the length of the run.

### Does the screen stay on with Lid Awake?

No. The built-in display turns off when the lid closes, and the Mac keeps running. Network connections, builds and agent sessions continue.

### Is Edith free?

No. Edith is a one-time purchase, and Keep Awake, Lid Awake, Agents and Usage all come with the license. caffeinate is free and built in, and for a single open-lid session it is all you need.

## Go further

The [lid-closed guide](https://getedith.pro/guides/keep-macbook-awake-lid-closed) goes deeper on closed-display mode and `pmset`, and [run coding agents overnight](https://getedith.pro/use-cases/run-coding-agents-overnight) puts the whole evening routine in one script. To get pinged the moment an agent needs you, read [how to get notified when Claude Code needs input](https://getedith.pro/guides/claude-code-notifications-mac). When you are ready, see [Edith's pricing](https://getedith.pro/pricing): one purchase covers every extension on this page.

## Edith extensions used

- [Keep MacBook Awake With the Lid Closed](https://getedith.pro/extensions/lid-awake): Keep your Mac running with the lid closed.
- [Keep Mac Awake: Stop Sleep While You Work](https://getedith.pro/extensions/keep-awake): Stop your Mac and display from going to sleep while you work.
- [Run Multiple Claude Code and Codex Agents on Mac](https://getedith.pro/extensions/coding-agents): See every coding agent on your Macs in one board, and step in when one needs you.
- [Claude Code Usage Tracker for Mac: Codex, Cursor](https://getedith.pro/extensions/claude-code-usage): See what your coding agents cost and how close you are to their limits.

## Related guides

- [How to Keep a MacBook Awake With the Lid Closed](https://getedith.pro/guides/keep-macbook-awake-lid-closed): Keep a MacBook awake with the lid closed on macOS: closed-display mode, caffeinate, pmset disablesleep, and Lid Awake with timers and a battery floor.
- [How to Run Multiple Claude Code Agents on Mac](https://getedith.pro/guides/run-multiple-claude-code-agents-mac): Run several Claude Code agents in parallel on a Mac with git worktrees and agent view, then watch every agent on one board and answer the blocked ones.

## Get Edith

Edith is a native Mac app for macOS 14 or later on Apple silicon with 100+ extensions, the `ed` command line and an MCP server. $35 once for one Mac, plus $7 for each additional Mac, with no subscription and a 30-day refund.

- [Buy Edith](https://getedith.pro/pricing): $35 once for one Mac, plus $7 for each additional Mac
- [Download Edith](https://getedith.pro/download): the installer, or Homebrew
