Not with the lid closed. Claude Code's built-in keep-awake runs caffeinate -i, which holds off idle sleep while the lid is open. Closing the lid is a separate sleep path. To keep a local session running lid-closed without a monitor, arm Clamshell for Mac before you close it.
Clamshell for Mac keeps the Mac awake with the lid closed while armed, so Claude Code keeps working. Free for 7 days.
Download free trialApple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or buy now, $9.99
People search for "Claude Code caffeinate" and "Claude Code sleep mode Mac" for two opposite reasons. Some notice a caffeinate process they never started and wonder why their Mac stays up. Others close the lid on a long task and come back to find it stopped hours ago. Both come from the same built-in keep-awake, and both make sense once you split Mac sleep into its two causes.
What Claude Code does to prevent sleep
On macOS, the Claude Code CLI starts caffeinate while a session is working. Anthropic does not document the details on a docs page, but its changelog confirms the process: version 2.1.83 (March 25, 2026) fixed a caffeinate process that kept running after Claude Code exited and stopped the Mac from sleeping. The finer details come from users who read the shipped code, as of October 2026:
- The command is
caffeinate -i -t 300.-iasks macOS not to idle-sleep, and-t 300ends the assertion after five minutes. Issue #81832 and issue #21432 both describe it. - It is a relay. Every four minutes Claude Code kills the running
caffeinateand starts a new one. Issue #81832, open as of October 5, 2026 and reported as still present in 2.1.280, says the kill comes before the new process starts, which leaves a moment with no sleep assertion at all. - It follows the busy state. The same report says protection ends about 30 seconds after the session stops being busy, so a long wait for your answer is unprotected.
- There is no off switch yet. Issue #21432 asks for a setting to disable it, and commenters there describe the process keeping a Mac on battery from idle-sleeping.
The Claude desktop app has a separate control. Anthropic's scheduled tasks docs say Keep computer awake in Settings, This computer, System prevents idle sleep, and add plainly: "Closing the laptop lid still puts it to sleep."
Idle sleep vs lid sleep: why closing the laptop stops Claude Code
macOS puts a MacBook to sleep for two different reasons. Idle sleep happens after a period without input. Apps can veto it with an assertion, and that is all caffeinate -i does. Lid sleep happens when you close the lid, and an idle assertion does not stop it. Apple's closed-display mode keeps a closed laptop running only with power, an external display, and an external keyboard and mouse.
When the Mac sleeps, the whole claude process tree is suspended. Nothing is lost on disk, but nothing runs either: tests stop mid-way, in-flight API responses fail, and Claude Code may later report that your computer went to sleep mid-response.
When the built-in keep-awake is enough
If you leave the lid open, you do not need anything extra for most sessions. To close the handoff gap from issue #81832 for a long unattended run, use one of these free options:
- Wrap the session:
caffeinate -i claudeholds one idle-sleep assertion for as long as Claude Code runs, including while it waits for your answer. - On power, change one setting: Apple's sleep settings guide describes System Settings, Battery, Options, Prevent automatic sleeping on power adapter when the display is off.
- In the desktop app: turn on Keep computer awake, which Anthropic documents for idle sleep.
None of these survive a closed lid. If the job has to keep going on a sofa, on a train, or overnight with the lid shut, you need a lid-sleep fix.
Does Claude Code keep running when the laptop is closed?
It depends on where the session runs:
Cloud session: yes
Anthropic's cloud docs say a cloud session runs on cloud infrastructure and "keeps running after you close your laptop". It clones from GitHub into a Linux VM, so it cannot use files or apps that only exist on your Mac. See cloud vs local.
Local CLI or desktop session: no
It runs on your Mac, so it stops when a closed lid puts the Mac to sleep. It picks up again when the Mac wakes, minus anything that timed out.
Remote Control from your phone: only if the Mac stays awake
Anthropic's Remote Control docs say the phone is a window into the local session, so "your computer has to stay on and the claude process has to keep running".
Local session with Clamshell armed: yes
The Mac stays awake and on the network with the lid closed and the built-in display black, so the local session and Remote Control keep working.
Keep Claude Code running with the lid closed
Use an Apple Silicon MacBook on macOS 14 or later, on a ventilated surface, preferably on power. Leave Claude Code's own keep-awake alone; it does not conflict.
- Install Clamshell and open it once. It sits in the menu bar. No sudo, admin password, kernel extension or privileged helper is involved.
- Disconnect external displays. With a display connected, Clamshell pauses (yellow menu bar icon) instead of arming, and arms automatically once displays disconnect.
- Start the Claude Code task. If you want to follow along from your phone, start Remote Control with
/remote-controlfirst. - Arm, check, then close. Arm from the menu bar menu, which covers the next close only, or hold Option while you close the lid on a MacBook Air M2 (2022) or later or a 14-inch or 16-inch MacBook Pro (2021) or later. Shortcuts and right-click arming stay active across reopenings until you disarm. Look for the armed state before the lid goes down.
To arm from a script before a long run, open "clamshell://arm" requests arming and open "clamshell://disarm" ends it. The Claude Code lid-closed guide covers a full phone setup and a timestamp check that proves work continued.
- The display stays black while the lid is closed, and with the Let agents use the screen setting on (the default) agents can still use the screen, so computer use and the iOS Simulator keep working.
- Heat is watched. At serious or critical macOS thermal pressure, Clamshell disarms toward normal lid sleep and blocks arming until the Mac cools. It does not replace airflow, so do not run it in a bag.
- Battery is your call. It works on battery, and the optional Disarm on low battery setting (off by default) lets the Mac sleep below a level you choose.
- Opening the lid locks the Mac. The display stays dark until the lock is confirmed. If Clamshell cannot confirm it, it restores the display and asks you to lock manually.
Clamshell does not know about Claude Code. It does not detect when a task ends, answer permission prompts, or keep a flaky network alive.
Clamshell keeps your Mac awake with the lid closed. Free for 7 days, then $9.99 once for one Mac. 14-day money-back guarantee.
Download free trialOther ways to keep Claude Code running lid-closed
Send the task to a cloud session
The best fit when the job only needs a GitHub repo and common Linux tooling. Start one with claude --cloud "task", per Anthropic's docs.
Use an external display
Apple's supported closed-display setup, with power, a display, and a keyboard and mouse. Ideal if you work at a desk with that hardware anyway.
Leave the lid open
Free and reliable with one of the idle-sleep fixes above. Fine on a desk at home.
Run sudo pmset -a disablesleep 1
Keeps a closed Mac awake, but it is a global admin switch with no timer, on battery too. See what pmset disablesleep does and how to undo it.
Frequently asked questions
Does Claude Code use caffeinate on a Mac?
Yes. Anthropic's changelog refers to the caffeinate process Claude Code starts on macOS, and GitHub reports describe it as caffeinate -i -t 300, restarted every four minutes while a session is busy. The -i flag holds off idle sleep only. It does not stop the sleep that happens when you close a MacBook lid.
Does Claude Code keep running when the laptop is closed?
A local session does not, unless something keeps the Mac awake with the lid shut, such as an external display setup, sudo pmset -a disablesleep 1, or a lid-sleep app like Clamshell for Mac. Claude Code cloud sessions do keep running, because they run on Anthropic's infrastructure instead of your Mac.
Why did my Mac sleep mid-task with Claude Code running and the lid open?
An open GitHub issue, anthropics/claude-code #81832, reports that the built-in caffeinate relay briefly drops its sleep assertion every four minutes. Once the display has been off long enough, macOS can idle-sleep in that gap. Starting Claude Code as caffeinate -i claude, or turning on Prevent automatic sleeping on power adapter when the display is off, holds the Mac awake for the whole run.
Does Claude Code Remote Control work with the MacBook lid closed?
Only while the Mac stays awake. Anthropic's docs say a Remote Control session runs on your machine, so the computer has to stay on and the claude process has to keep running. With the lid closed and nothing keeping the Mac awake, the phone loses the session until the Mac wakes.
Does Clamshell detect Claude Code or start automatically?
No. Clamshell has no Claude Code integration and does not detect running agents. You arm it from the menu bar, by holding Option while closing the lid on supported models, with Shortcuts actions, or with the clamshell://arm URL.
Related guides
- Keep Claude Code running with the lid closed
- Claude Code cloud sessions vs running locally on your Mac
- Let agents use the screen with the MacBook lid closed
- Run AI coding agents overnight on a MacBook
- Keep Codex running when you close your MacBook lid
- Codex Keep this Mac awake not working with the lid closed
Sources checked October 5, 2026: Anthropic's Claude Code changelog, cloud sessions, Remote Control and desktop scheduled tasks docs; anthropics/claude-code issues #81832 and #21432; Apple's closed-display and sleep settings guides. Clamshell behavior is described from its changelog and FAQ. Clamshell is an independent app, not affiliated with or endorsed by Anthropic. Claude and Claude Code are trademarks of Anthropic.