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.
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.
- Connect your phone while the lid is open. In an existing Claude Code terminal session, enter
/remote-controland 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. - Using Happy instead? Follow Happy's installation and pairing instructions, then start
happy claudeorhappy codexin your project. Confirm that a phone request reaches that session before continuing. These are alternative phone connections; you only need one. - 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
Ask your connected agent to run this harmless timestamp check in its terminal. Approve the command while the lid is open, then close the lid during the two-minute run.
for i in {1..12}; do
date -u '+%Y-%m-%dT%H:%M:%SZ'
sleep 10
done
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
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
caffeinateand most keep-awake menu bar apps prevent idle sleep only. The lid-close sleep path ignores them, so local work still pauses. Some apps, like KeepingYouAwake, state outright that closed-lid operation is not supported.sudo pmset -a disablesleep 1does work, but it is a global, admin-level switch: it disables every kind of sleep until you remember to undo it, on battery too. Forget it and the Mac runs itself flat in your bag.- An external display or an HDMI dummy plug satisfies macOS's official clamshell mode, but that is hardware you have to own, power, and carry.
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.
Clamshell keeps your Mac awake with the lid closed. Free for 7 days, then $9.99 once.
Download free trialArm 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.
Clamshell is an independent app, not affiliated with or endorsed by Anthropic or OpenAI. Claude Code and Codex are trademarks of their respective owners.