Does Claude Code stop your Mac from sleeping?
Short answer
Partly, and it depends where you run it. The Claude Code CLI on macOS runs caffeinate -i while it works, which stops idle sleep but not lid sleep. The VS Code extension held no sleep lock in our test (v2.1.311). The desktop app has a Keep computer awake setting you turn on. None keeps a closed MacBook awake.
Each surface at a glance
| Where Claude Code runs | Holds off idle sleep? | Lid closed | Source |
|---|---|---|---|
| Terminal (CLI) | Yes, with caffeinate -i -t 300 |
Sleeps | Issue reports, code |
| VS Code extension | No lock seen in our test (v2.1.311) | Sleeps | Our test, 27 Oct 2026 |
| Claude desktop app | Only if you turn on Keep computer awake | Sleeps | Anthropic’s docs |
| Remote Control | Runs on your Mac, so your Mac must stay on | Sleeps | Anthropic’s docs |
| Cloud sessions | Not needed: they run on Anthropic’s servers | Keeps going | Anthropic’s docs |
Two kinds of sleep matter here. Idle sleep happens when nobody touches the Mac for a while. Forced sleep happens when you close the lid, choose Sleep from the Apple menu, or the battery runs very low. Apple’s QA1340 says apps can hold off idle sleep, but “it is not possible to prevent forced sleep, only delay it.”
The CLI: caffeinate, with a gap
On macOS, the Claude Code CLI starts Apple’s caffeinate -i -t 300 while it works. The -i flag creates “an
assertion to prevent the system from idle sleeping” (man page), and -t 300
ends it after five minutes, so Claude Code keeps starting a fresh one.
Three things are worth knowing:
- There’s a gap. A reporter who traced the code found it replaces caffeinate every 240 seconds, and kills the old one before starting the new one. For a moment, nothing holds the Mac awake. The reporter says that once the display is off, that’s enough for the Mac to idle-sleep mid-task (#81832, seen on versions 2.1.207 to 2.1.280).
- It keeps going on battery. One user reported an unattended session on battery ran a laptop down to 0% until it shut off (#21432).
- You can’t turn it off. The same issue, open with 38 thumbs-up, asks for a setting. Other users report caffeinate staying around while Claude Code is idle (#64522).
You can see it yourself while Claude Code works in a terminal:
pmset -g assertions | grep -i caffeinate
The VS Code extension: no lock in our test
We checked on 27 October 2026, on macOS 26.4.1 on Apple silicon, while a Claude Code session in the VS Code extension (v2.1.311) was working:
pgrep -lf caffeinate
pmset -g assertions
pgrep found no caffeinate process, and pmset listed no sleep lock owned by Claude or caffeinate. So nothing from
Claude Code stopped the Mac’s idle timer. The extension’s binary does contain caffeinate code, so this could change in
a later version.
The same Mac, over one week (20 to 27 October 2026), shows what that costs. Sleep cut off 15 to 23 Claude Code runs, about two or three a day. Seven to twelve happened on the charger. Most of the rest were idle sleep on battery.
The desktop app: a setting you turn on
Anthropic’s docs: “To prevent idle-sleep, turn on Keep computer awake in Settings > Desktop app or Settings > This computer > System. Closing the laptop lid still puts it to sleep.”
On our Mac, the desktop app’s hold showed up in the power log as an Electron NoIdleSleepAssertion, in holds of about
five minutes, rather than caffeinate.
Remote Control and cloud sessions
Remote Control lets you drive a session on your Mac from your phone or a browser. The docs are plain: “your
computer has to stay on and the claude process has to keep running.” If the laptop sleeps, Claude Code reconnects
when it wakes, but nothing runs in between.
Cloud sessions run on Anthropic’s servers. For a task that must run while your computer is asleep or off, the desktop docs suggest a cloud session.
How to fill the gaps
Start with the free options. They’re enough for many people.
-
On the charger: turn on Prevent automatic sleeping on power adapter when the display is off in System Settings › Battery › Options (Apple). In our week, that alone would have saved seven to twelve runs.
-
In a terminal: start Claude Code inside caffeinate. It holds off idle sleep until you quit, with no gap:
caffeinate -i claudeIt also holds while Claude waits for you, so quit when you’re done.
-
In VS Code: run caffeinate for a set time in any terminal, here two hours:
caffeinate -i -t 7200 -
In the desktop app: turn on Keep computer awake.
None of these help once you close the lid, and none watch the battery. For that, see Can I close my laptop while an agent runs?
Night Crew does this for you. It sees Claude Code in the terminal and in VS Code with no setup, holds one steady lock while a session works, and lets the Mac sleep 60 seconds after it finishes. It adds lid mode and a battery floor at 15%. More on the Claude Code page, or compare it with the free tools on /compare.
Sources
- claude-code #81832: caffeinate -i -t 300 and the 240-second respawn
- claude-code #64522: caffeinate keeps respawning
- claude-code #21432: setting to turn off sleep prevention
- Claude Code docs: desktop scheduled tasks ("Keep computer awake")
- Claude Code docs: Remote Control
- Claude Code docs: desktop app (cloud sessions for work while asleep)
- caffeinate man page (ss64)
- Apple QA1340: idle sleep vs forced sleep
- Apple: set sleep and wake settings for your Mac
Checked 5 November 2026.