Only while the lid is open. Claude Code in Terminal runs caffeinate -i while it works, and the Claude desktop app's Keep computer awake setting prevents idle sleep. Both cover idle sleep only; Anthropic's docs add that closing the laptop lid still puts the Mac to sleep. To keep a local session running lid-closed without a monitor, arm Clamshell for Mac before you close it.
An animated MacBook with a coding agent deploying a website from its terminal. The Option key is held and the lid closes: the display goes black, but the Mac stays awake, so a dimmed copy of the terminal keeps working above the closed laptop while its front edge fills with light. When the deploy is done, a pointer shows how to lift the lid. Opening it wakes the Mac to its lock screen, which unlocks to the finished run: deployed, with the live address. The lid can then be opened and closed freely.
Clamshell for Mac keeps the Mac awake with the lid closed while armed, so Claude Code keeps working. Free for 7 days.
Apple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or install with Homebrew: brew install --cask clamshell.
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.
Cloud or local: which sessions survive a closed lid?
It depends on where the session runs. The full walkthrough, with a test you can run, is in does Claude Code keep running when you close your laptop.
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.
- External displays can stay connected. Clamshell arms with or without one.
- 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 with a lid angle sensor (the 14-inch and 16-inch MacBook Pro from 2021 on, and some newer MacBook Air models). Right-click and Shortcuts 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 Agent Screen module on (off by 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 covered. It works on battery, and the Disarm on low battery setting (on by default) lets the Mac sleep when the battery reaches 20%.
- 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's core does not know about Claude Code; its optional Agent Status, Agent Notifications and Finish Work, Then Sleep modules show what Claude Code and Codex agents are doing, notify you, and can let them finish before the Mac sleeps. It does not 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.
Apple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or install with Homebrew: brew install --cask clamshell. Also on Setapp.
Other 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?
Not by default. Clamshell's core does not detect running agents; its optional Agent Status, Agent Notifications and Finish Work, Then Sleep modules show what Claude Code and Codex agents are doing, notify you, and can let them finish before the Mac sleeps. 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
- What keeps running in Claude Desktop when you close the lid
- Claude Dispatch and Cowork with the lid closed
- Does Claude keep running if you lock your laptop?
- Claude Code Remote Control keeps disconnecting?
- Does Mac sleep burn your Claude Code usage limit?
- Arm Clamshell from Claude Code hooks
- How to keep a MacBook awake with the lid closed
- Claude Code Remote Control with the lid closed
- 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.