How do you keep Claude Code running with the MacBook lid closed?

By Matyas Rathonyi. Updated September 29, 2026. Guides

Closing the lid puts a MacBook to sleep, and a sleeping Mac pauses local Claude Code sessions, so you need to stop lid-close sleep, not just idle sleep.

Lid sleepPauses local Claude Code sessions
caffeinateNot enough once the lid closes
No sudoNo monitor or admin rights
$9.99 onceAfter a 7-day free trial

Clamshell for Mac keeps the Mac awake with the lid closed while armed. No sudo, no monitor. Free for 7 days, then $9.99 once.

Download free trial
A phone steers a Claude Code session over Remote Control. The session runs on the closed MacBook, which Clamshell keeps awake. Phone steers Closed Mac does the work
Your phone steers. The closed Mac does the work.Remote Control runs the session on your Mac, so the Mac has to stay awake after the lid closes.

Without an external display, that means sudo pmset -a disablesleep 1 or an app such as Clamshell for Mac, a menu bar app that keeps an Apple Silicon MacBook awake with the lid closed without sudo or admin rights. caffeinate alone is not enough.

You start a long agent run, close the MacBook, and come back to a stalled session. Closing the lid normally puts the Mac to sleep, pausing local work; network connections may also disconnect. This guide covers running lid-closed without an external display or admin rights, and how to tell whether sleep is actually your problem.

Claude Code stops when you switch to your phone?

Anthropic's Remote Control documentation explains that the work still runs on your computer. Your phone controls that local session; it does not move the job to the cloud. Remote Control can reconnect after sleep, but local work cannot progress while the Mac is asleep.

It stops only after you close the lid

Check lid sleep first. A closed-lid keep-awake tool can help if you need the local Mac to keep working.

It stops with the lid open too

Look at the session's connection status, any pending permission request, and the terminal's error message. Keeping the Mac awake does not resolve an agent error or approve a tool call.

The Mac loses internet

Restore the connection. A keep-awake app cannot provide network access.

The job runs in Claude Code on the web

That is cloud execution. Keeping this Mac awake is not needed for that remote computation.

If lid sleep is the cause, keep the Mac on a ventilated desk with power and a stable connection. Arm Clamshell from the menu bar and confirm its armed state before closing the lid. Use the seven-day trial to check your own workflow; the app costs $9.99 once for one Mac. See the hardware requirements before downloading.

What Clamshell adds to a keep-awake command

If you leave the lid open, caffeinate can prevent idle sleep for a terminal job. Clamshell is for keeping an Apple Silicon MacBook working with the lid closed, without an external monitor or admin access.

Download the seven-day free trial to verify your actual agent workflow before buying. The direct license is $9.99 once for one Mac.

Set up a lid-closed phone session

Use an Apple Silicon MacBook on macOS 14 or later, with Clamshell installed and a working local agent session. Leave the Mac on a ventilated desk, connected to power and the internet. Disconnect external displays for this setup.

  1. Connect your phone while the lid is open. In an existing Claude Code terminal session, enter /remote-control and follow its connection link or QR code. Follow Anthropic's current setup instructions for account requirements. Send a small request from your phone and confirm that the Mac responds.
  2. Using Happy instead? Follow Happy's installation and pairing instructions, then start happy claude or happy codex in your project. Confirm that a phone request reaches that session before continuing. These are alternative phone connections; you only need one.
  3. Arm Clamshell. Use its menu bar control, or run the command below. Open the menu and confirm that it is armed. A paused state caused by an external display is not confirmation that this setup is active.
    open "clamshell://arm"

This command requests arming asynchronously. A successful shell exit does not prove the Mac is armed. Check the menu before closing the lid.

Prove that work continues

  1. Ask your connected agent to run this harmless timestamp check in its terminal.
    for i in {1..12}; do
      date -u '+%Y-%m-%dT%H:%M:%SZ'
      sleep 10
    done
  2. Approve the command while the lid is open, then close the lid during the two-minute run.
  3. After two minutes, ask from your phone for the timestamp output and one fresh timestamp. Pass: the recorded timestamps continued roughly ten seconds apart while the lid was closed, and the fresh request completes before reopening it.

Some clients buffer terminal output, so a quiet phone screen alone is not a failure. A connected badge alone is not a pass.

If it fails: reopen the lid and inspect the timestamp gaps, Clamshell's state, the terminal, and any pending permission request. A long gap points to interruption; it does not by itself identify the cause. Fix failures with the lid open first, then repeat this check before relying on a long job.

Finish the session

Reopen the lid, stop or finish your agent task, then disarm Clamshell from its menu or request it below. Confirm the inactive state before putting the Mac away. Menu and URL arming remain active until disarmed; opening the lid alone does not end that mode.

open "clamshell://disarm"

Clamshell also provides Arm, Disarm, Toggle, and Status actions in Shortcuts. Add them to a shortcut you create. Keeping the Mac awake does not bypass agent permissions, repair a network outage, or make a sleeping Mac remotely wakeable.

Why local work pauses when the lid closes

  1. You close the lidmacOS starts its lid-close sleep path.
  2. The Mac sleepsA running agent does not hold it off.
  3. The agent stops mid-taskBuilds, downloads, and SSH sessions stop too.

Lid-close sleep is not idle sleep. An active task does not by itself prevent lid sleep. Without a supported closed-display setup or a lid-sleep override, closing the lid can pause an agent mid-task. Once asleep, Claude Code, Codex, builds, downloads, and SSH sessions all stop making progress. Depending on the tool, the session may or may not recover when the Mac wakes; the hours in between are lost either way.

What doesn't work, and why

The two-second fix

Clamshell is a menu bar app built for exactly this. Hold Option and close the lid: the screen goes dark, the Mac stays awake, and your agent keeps working. With the Option-close gesture, opening the lid ends that momentary session. Arming from the menu or URL keeps Clamshell active until you disarm it. It needs no admin rights: no sudo, no kernel extension, no privileged helper.

Hold Option and close the lid. The blue state confirms that Clamshell is armed.

Clamshell keeps your Mac awake with the lid closed. Free for 7 days, then $9.99 once.

Download free trial

Arm it from the terminal

Clamshell accepts arm and disarm requests through its URL scheme. This shell example requests arming before a task and disarming when the shell exits. The open command delivers a request; it does not confirm that Clamshell armed successfully. Check the app's armed state before closing the lid. An EXIT trap is not a guarantee after a shell crash or forced termination.

set -e
open "clamshell://arm"
trap 'open "clamshell://disarm" || true' EXIT

# your long-running task
claude -p "run the test suite and fix the failures"

Once you have confirmed arming, no Option key is needed. clamshell://toggle exists too, and Clamshell's Shortcuts actions (Arm, Disarm, Toggle, Status) can be wired into your own shortcuts and automations.

Claude Code, Codex, Cursor, builds, and SSH

The lid does not care which process is doing the work. If the Mac sleeps, local coding agents pause, child processes stop, network sockets can disconnect, and remote sessions can time out. Keeping the machine awake preserves the whole working environment:

Claude Code and Codex

Continue tool calls, tests, and edits instead of waiting for the lid to reopen.

Cursor and other desktop agents

Stay alive with their local terminals and background tasks.

Builds, test suites, downloads, and renders

Continue using the same CPU and network resources they had with the lid open.

SSH, screen sharing, and remote access

Remain reachable because the Mac stays awake and on the network.

Overnight runs, on battery too

Closing the lid turns the screen off, which is most of a laptop's idle power draw. The Mac otherwise runs exactly as it would lid-open: light agent work sips power, heavy work draws what it always draws. Clamshell survives plugging and unplugging mid-run, and an optional low-battery switch (off by default, in Settings) lets the Mac go to sleep if the charge falls below a level you choose, so an overnight run does not have to run the battery flat. The Mac also stays on the network, so SSH and screen sharing keep working while the lid is shut.

Compatibility

Apple Silicon MacBooks on macOS 14 or later. The Option-and-close gesture uses the lid angle sensor found in the MacBook Air M2 (2022) or later and the 14-inch and 16-inch MacBook Pro (2021) or later; on other Apple Silicon laptops you arm from the menu bar instead. More detail is in the FAQ. If you are choosing a method, compare Clamshell, Amphetamine, pmset, caffeinate, and Apple's display setup.

Frequently asked questions

Does Claude Code keep running when I close my MacBook lid?

Not by default. Closing the lid puts the Mac to sleep and local Claude Code work stops making progress until it wakes. It keeps running only with an external display attached, pmset disablesleep, or a lid-closed app such as Clamshell for Mac.

Does Claude Code Remote Control keep working with the lid closed?

Remote Control lets your phone steer a session that runs on your Mac, so the Mac must stay awake. With the lid closed, it keeps working only if lid-close sleep is prevented, for example by arming Clamshell before you close the lid.

Can I keep Claude Code running with the lid closed without sudo?

Yes. Clamshell for Mac is a menu bar app that needs no sudo, admin rights, kernel extension, or privileged helper. Arm it from the menu bar or with Option-close, confirm the armed state, then close the lid.

Does Clamshell detect Claude Code automatically?

No. Clamshell has no agent auto-detection and no native Claude Code integration. A script can request arming with the clamshell://arm URL and disarming with clamshell://disarm, or you can use its Shortcuts actions.

Is it safe to leave a MacBook running Claude Code overnight with the lid closed?

Keep it on a ventilated desk, preferably on power. Clamshell's thermal safety is always on and disarms toward normal lid sleep at serious or critical thermal pressure, and an optional low-battery cutoff can let the Mac sleep before the battery runs flat.

Does this work for Codex, Cursor, and other agents?

Yes. Keeping the Mac awake keeps every local process running, including Codex, Cursor, builds, test suites, and SSH sessions. It does not approve agent permission requests or fix network outages.

Related guides

Clamshell is an independent app, not affiliated with or endorsed by Anthropic or OpenAI. Claude Code and Codex are trademarks of their respective owners.