Guide
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.
Updated by Pulkit
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.
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.
caffeinate -i claudecaffeinate -dis claudecaffeinate -i -w 12345pmset -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 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 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 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 1keeps 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 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 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.
From the terminal
Every step above also has a command, handy for a script:
ed lid-awake battery 20ed lid-awake on --until-lid-reopens --yesed lid-awake statused lid-awake offed agents background statusWatch the limits while it runs
A Mac that stays awake all night can also use a whole session window. Edith's 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 explains the windows.
Which tool for which job
- Lid open, one session:
caffeinate -i claudeis 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 disablesleepif 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 goes deeper on closed-display mode and pmset, and 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. When you are ready, see Edith's pricing: one purchase covers every extension on this page.