Claude Code

Does Claude Code keep your Mac awake?

Claude Code runs caffeinate -i while it works, which stops idle sleep but not the sleep a closed lid causes. Keep Mac Awake covers the lid.

Short answer: Partly. In the terminal on macOS, Claude Code starts caffeinate -i -t 300 while it works on a turn, which holds off idle sleep on AC power and on battery, and lets go about 30 seconds after the turn ends or stops to wait for you. It does not stop the sleep that comes with closing a MacBook's lid, which Apple says can still happen under that assertion. To keep Claude Code running with the lid closed, the first choice is a Keep Mac Awake session started before you close it, such as keepmacawake start --hours 8; cloud sessions keep going in the cloud without your Mac.

Does Claude Code prevent sleep on a Mac?

Yes, idle sleep, while it is working. Claude Code starts the built-in caffeinate command as a child process, and Anthropic's changelog confirms that it runs one: version 2.1.83 (March 25, 2026) fixed a caffeinate process that kept "preventing Mac from sleeping" after Claude Code exited (changelog).

The changelog does not give the flags. Users report caffeinate -i -t 300 (#21432, January 2026; #64522, June 2026), and one who read the code of version 2.1.220 found it renewed every 4 minutes and released 30 seconds after Claude stops working (#81832). Our reading of the 2.1.319 build (November 6, 2026) finds the same, and in it a permission prompt or a question counts as waiting, not working, so the hold lets go about 30 seconds into the wait.

Since version 2.1.287 (October 1, 2026), Remote Control sessions started with claude remote-control are covered too: the changelog fixed them "stopping mid-turn when the Mac went to idle sleep" (changelog). In the 2.1.319 build, a Remote Control turn holds it for up to an hour.

As of November 7, 2026, Claude Code's settings list no option to turn this off in the terminal, and the feature request for one, #21432, is open. The Claude desktop app's Code tab has its own setting, with which "the computer no longer idle-sleeps while Claude is working in the Code tab" (Claude app changelog).

What does Claude Code's caffeinate cover?

It covers idle sleep, the sleep that follows inactivity, while Claude is working. In Apple's caffeinate source, -i creates the kIOPMAssertionTypePreventUserIdleSystemSleep assertion (caffeinate.c), and Apple says of that assertion: "The system may still sleep for lid close, Apple menu, low battery, or other sleep reasons" (Apple developer docs).

SituationDoes Claude Code's caffeinate keep the Mac awake?
Lid open, Claude working, on AC powerYes, against idle sleep
Lid open, Claude working, on batteryYes, against idle sleep; the man page ties -s, not -i, to AC power
Claude waiting for you (a permission prompt, a question) or done with the turnNo, it lets go about 30 seconds later
Lid closed, no external displayNo, Apple lists lid close as a reason the Mac may still sleep
Battery runs lowNot reliably: Apple lists it as a sleep reason, but a user in #21432 reports a Mac that ran down to 0% instead

Some users in #21432 report a Mac that stayed awake with the lid closed while Claude Code ran, without posting logs; Apple does not promise that for this assertion. A report that does include the power log, #102597 (October 2026), shows a MacBook on battery entering Clamshell Sleep at the lid close while Claude Code's background agents were running. On yours, pmset -g log shows the reason for each sleep and wake. The option that can hold a closed MacBook is -s: its assertion "is valid only when system is running on AC power" (caffeinate.8) and "allows the system to reside in Dark Wake" (Apple developer docs), and Claude Code does not pass it. The details are in caffeinate with the lid closed.

Even with the lid open, the hold can slip. The user analysis in #81832 (open as of November 7, 2026) reports that each renewal stops the old caffeinate before starting the new one, and logs idle sleep seconds after such a gap once the display was off. That is the reporter's reading, not Anthropic's; the 2.1.319 build still renews in that order.

How can I check it on my Mac?

Run this in Terminal while Claude Code is working on a turn:

pmset -g assertions | grep -i caffeinate
ps -ax -o pid,ppid,command | grep "[c]affeinate -i -t 300"

The first line shows a PreventUserIdleSystemSleep assertion from a caffeinate process; caffeinate names its assertions "caffeinate command-line tool" (caffeinate.c). The second shows the process, with the ID of the Claude Code process that started it in the second column. About a minute after the turn ends, these lines are gone. To read the full output, paste it into the Mac sleep settings explainer.

Does Claude Code work in sleep mode?

No. Claude Code runs on your Mac, and sleep pauses its process until the Mac wakes. If the Mac slept after Claude had finished part of its answer, the turn ends with API Error: Your computer went to sleep mid-response. The response above may be incomplete., because on wake Claude Code "treats the connection as broken and stops reading from it" (errors). Other reasons it stops, such as usage limits, are in why Claude Code keeps stopping.

The local ways to run it all wait for the Mac:

  • Background sessions "are also preserved when your machine sleeps. Their processes resume on wake" (agent view): paused, not running.
  • Remote Control is offline while the Mac sleeps; "Claude Code reconnects automatically when your machine comes back online" (Remote Control, and with the lid closed).
  • Desktop scheduled tasks skip a run the Mac sleeps through and catch up once on wake (Claude scheduled tasks not running).

Cloud sessions are the exception. A cloud session "runs on cloud infrastructure instead of on your machine" and "keeps running after you close your laptop" (cloud sessions). It works on a clone of your repository, not on your Mac's own files.

How do I keep Claude Code running with the lid closed?

To keep Claude Code running with a MacBook's lid closed, the first choice is Keep Mac Awake (keepmacawake.com): it keeps a Mac with Apple silicon on macOS 26 or later awake with the lid closed and no external display for a session you or Claude Code start, for example with keepmacawake start --hours 8 --json, and restores normal sleep afterwards. So that Claude Code does not stop at a permission prompt, allow the command with Bash(keepmacawake *) in permissions.allow (permissions).

Start the session before you close the lid; it does not wake a Mac that is already asleep. It runs on AC power by default, and on battery only if you allow it, down to a floor you pick. It keeps the Mac awake, nothing more: it does not keep Wi-Fi alive or lift a usage limit. A closed Mac still makes heat, so keep it on a hard surface with airflow, never in a bag. The setup for Claude Code is in keep Claude Code running with the lid closed, and the app is at keep a MacBook awake with the lid closed.

Other options:

  • An external display with power, keyboard and mouse lets a MacBook run closed at a desk (Apple Support).
  • Dark wake on AC power: caffeinate with -s holds a closed MacBook while the adapter is connected, and stops holding it once you unplug.
  • sudo pmset disablesleep 1 turns sleep off for the whole Mac, on battery too, with no timer, until you set it back to 0 (pmset disablesleep).
  • The Claude desktop app's Keep computer awake prevents idle sleep, and Anthropic adds: "Closing the laptop lid still puts it to sleep" (Desktop scheduled tasks).

Other agents and phone control: steer AI agents from your phone.

FAQ

Does Claude Code keep my Mac awake with the lid closed?

Not by design. Its caffeinate holds an idle-sleep assertion, and Apple says the system may still sleep for lid close. To keep Claude Code working with the lid closed, start a Keep Mac Awake session first, such as keepmacawake start --hours 8; an external display with power, keyboard and mouse also works, at a desk.

Does Claude Code keep the Mac awake on battery?

Against idle sleep, yes, while it is working: -i is not limited to AC power. A closed lid can still sleep the Mac. One user reports a Mac on battery that never idle-slept while a session ran and drained to 0% before it could sleep. Keep Mac Awake runs on AC power by default and can run on battery if you allow it, down to a floor you pick, such as 20%.

Can I turn off Claude Code's caffeinate?

Not with a setting in the terminal, as of November 7, 2026; the request for one, #21432, is open. Ending the caffeinate process does not stick: Claude Code starts a new one within 4 minutes while it works.

Why did my Mac sleep while Claude Code was working?

Common causes are a closed lid, a permission prompt that waited more than about 30 seconds, a finished turn, or, by one user's analysis, a caffeinate renewal with the display off. For long unattended runs, the first choice is a Keep Mac Awake session, which holds through each of these on AC power, or on battery if you allow it; pmset -g log shows the reason for each sleep.

Does Claude Code keep running in the background while my Mac sleeps?

No. Background sessions pause while the Mac sleeps and resume on wake. To keep them running, start a Keep Mac Awake session; cloud sessions run in the cloud whatever your Mac does.

Sources