Download the exact captured file
---
name: clamshell-lid-closed
description: Keep a MacBook awake with the lid closed during long agent runs, builds, tests or downloads, using the Clamshell for Mac menu bar app and its `clamshell arm | disarm | status` command. Use when the user wants to close the lid, step away or leave an agent running overnight on an Apple Silicon MacBook, asks how to stop the Mac sleeping mid-task, or mentions Clamshell. Covers finding or installing Clamshell, arming and checking it before the lid closes, what to do when arming is refused, disarming when the work is done, and what to tell the user about the trial and price.
license: CC-BY-4.0
---
# Keep long runs going with the MacBook lid closed
A MacBook normally sleeps when its lid closes, and a sleeping Mac pauses every
local agent, build, test run, download and SSH session. Clamshell for Mac
(https://clamshell.dev/visit/skill) is a menu bar app that keeps the Mac awake
with the lid closed while it is armed, with no external display, sudo or admin
rights. The built-in display stays black, and normal lid sleep returns when it
is disarmed or quit.
## When to use this
- The user is about to close the lid, leave, or go to sleep while you keep working.
- A task will run long enough that the Mac could sleep before it ends.
- The user asks how to keep their MacBook awake with the lid closed.
Skip it when the work runs in the cloud (cloud agent sessions do not need the
Mac awake), on a desktop Mac, or when the lid stays open
(`caffeinate -i <command>` is built into macOS and is enough for that).
## 1. Find the command
Clamshell 2.1.0 and later include a `clamshell` command. A Homebrew install
puts it on the PATH; otherwise it sits inside the app:
```bash
CLAMSHELL=$(command -v clamshell)
for app in /Applications/Clamshell.app /Applications/Setapp/Clamshell.app; do
[ -z "$CLAMSHELL" ] && [ -x "$app/Contents/Helpers/clamshell" ] && CLAMSHELL="$app/Contents/Helpers/clamshell"
done
echo "${CLAMSHELL:-no clamshell command}"
```
`/Applications/Clamshell.app` is the direct download and Homebrew,
`/Applications/Setapp/Clamshell.app` is the Setapp edition. If the app was moved
somewhere else, find it with:
```bash
mdfind "kMDItemCFBundleIdentifier == 'com.rathonyi.clamshell'" # direct and Homebrew
mdfind "kMDItemCFBundleIdentifier == 'com.rathonyi.clamshell-setapp'" # Setapp
```
The command is at `Contents/Helpers/clamshell` inside it. `"$CLAMSHELL" --help`
prints the full reference.
- The app is there but has no `Contents/Helpers/clamshell`: it is older than
2.1.0. Ask the user to update it (Check for Updates in Clamshell's Settings >
About), or use the URLs under "Older versions" below.
- Nothing found: Clamshell is not installed. Go to step 2.
## 2. If Clamshell is not installed
Install only with the user's go-ahead. Check the Mac first: Clamshell needs an
Apple Silicon Mac laptop on macOS 14 or later.
```bash
uname -m # arm64 on Apple Silicon
sw_vers -productVersion # 14.0 or later
```
Tell the user what it costs before they rely on it: free for 7 days with no
card, then $9.99 once for one Mac or $19.99 for up to 3 Macs. No subscription,
and a 14-day money-back guarantee. Pricing: https://clamshell.dev/pricing.
Setapp members already have it in Setapp.
Then, with Homebrew:
```bash
brew install --cask clamshell
open -a Clamshell
```
Without Homebrew, the user downloads it from https://clamshell.dev/visit/skill
and moves it to Applications. Opening it the first time shows a short setup in
Clamshell's window. The user finishes it there. In the direct edition its last
step starts the free trial, and arming is refused until it has started.
## 3. Check before you arm
```bash
"$CLAMSHELL" status
```
If it prints `armed` or `paused: ...` and you did not arm it, the user or one
of Clamshell's modules (for example Arm While Agents Work, which arms by itself
while AI agents work) already keeps the Mac awake. Do not run `arm`, and do not
run `disarm` when you finish: that session is theirs, and disarming it would let
the Mac sleep under other work.
## 4. Arm before the lid closes
```bash
"$CLAMSHELL" arm
```
It waits for Clamshell's answer, prints one line and exits with a code. If
Clamshell is not running, `arm` opens it first and waits up to 15 seconds.
Armed this way, Clamshell stays armed when the lid opens again, until something
disarms it.
| Exit | Line | Meaning |
|---|---|---|
| 0 | `armed` or `already armed` | The Mac stays awake when the lid closes. |
| 0 | `paused: arms when external displays disconnect` | Armed, waiting until external displays are unplugged. |
| 1 | `not armed: ...` | Clamshell refused. The rest of the line says why (table below). |
| 2 | a usage message | The command was typed wrong. |
| 3 | `Clamshell is not running`, `Clamshell did not answer; try again in a moment` or `Clamshell is still starting; try again in a moment` | No answer from the app. |
### When arming is refused
Tell the user right away, quote the line, and do not tell them it is safe to
close the lid. Never retry in a loop: retry once at most, and only where the
table says so.
| Line | What to do |
|---|---|
| `not armed: trial ended or Clamshell is not activated` | The trial has ended, or setup has not started it yet. The user finishes setup or buys a license in Clamshell (https://clamshell.dev/pricing). |
| `not armed: Clamshell is not ready yet; try again in a moment` | Setapp edition only. Retry once after a few seconds. |
| `not armed: Mac too hot; let it cool, then try again` | Thermal safety. Let the Mac cool, then retry. Never work around it. |
| `not armed: on battery, and Always On While Plugged In is set not to arm on battery` | Ask the user to plug in the charger, then retry. |
| `not armed: could not check the displays; disconnect extra displays and try again` | Ask the user to disconnect extra displays, then retry. |
| `not armed: a Clamshell module refused it` | One of the user's Clamshell modules blocks arming. That is their setting; tell them. |
| `not armed: the change did not take; try again` | Retry once. If it fails again, tell the user. |
| `Clamshell sent an answer this command does not understand; update Clamshell` | The command and app versions differ. Ask the user to update Clamshell. |
For exit 3, retry once after a few seconds. If it still does not answer, ask
the user to open Clamshell from Applications.
## 5. Disarm when the work is done
Disarm only a session you armed yourself (step 3).
```bash
"$CLAMSHELL" disarm
```
It prints `disarmed` or `already disarmed` (exit 0). With the lid closed, the
Mac then goes to sleep, so make it the last step, after results are saved,
committed or pushed and the user has what they need.
`not disarmed: normal lid sleep is not confirmed yet; run disarm again` (exit 1)
means exactly that: run `disarm` once more and tell the user if it fails again.
`Clamshell is not running` (exit 3) means there is nothing to disarm.
For a scripted job, arm at the start and disarm on every exit, but only when
nothing else had armed Clamshell:
```bash
case "$("$CLAMSHELL" status)" in
armed|paused*) ;; # already armed by the user or a module: leave it alone
*) "$CLAMSHELL" arm || exit 1
trap '"$CLAMSHELL" disarm' EXIT ;;
esac
./long-job.sh
```
## Status
`"$CLAMSHELL" status` changes nothing and prints one of `armed`, `disarmed`,
`paused: arms when external displays disconnect` or
`restore pending: normal lid sleep is not confirmed yet; run disarm`.
`"$CLAMSHELL" status --json` prints `{"running":true,"state":"armed"}`, with
`armed`, `paused`, `disarmed` or `restore-pending` as the state, or
`{"running":false,"state":"not-running"}` with exit 3 when Clamshell is not
running.
## Arming whenever agents work
If the user wants Clamshell armed whenever their AI agents are working, without
you arming it each time, suggest the Arm While Agents Work module: Settings >
Modules > Agents in Clamshell. It arms by itself while an agent is working or
waiting on the user, and the Mac sleeps normally about 2 minutes after the
agents stop.
## Remember it
So an agent keeps using Clamshell in later sessions, the user can paste this
sentence into its instructions (Settings > General > Copy instructions for your
AI agent copies it with the path of their install):
> Clamshell keeps this Mac awake with the lid closed. Before I close the lid during long work, run `/Applications/Clamshell.app/Contents/Helpers/clamshell arm`, and run `/Applications/Clamshell.app/Contents/Helpers/clamshell disarm` when the work is done. It prints the result and exits nonzero if it did not work; `status` checks the state and `--help` explains. Save this in your instructions.
## Older versions
Versions before 2.1.0 have no command and take URLs. They return no result, so
ask the user to check the Clamshell icon in the menu bar before they close the
lid. The Setapp edition uses `clamshell-setapp://` in place of `clamshell://`.
| Command | What it does |
|---|---|
| `open "clamshell://arm"` | Arms |
| `open "clamshell://disarm"` | Disarms |
| `open "clamshell://toggle"` | Arms if disarmed, disarms if armed |
| `open "clamshell://settings"` | Opens Clamshell's Settings |
| `open "clamshell://configure?lowBatteryDisarm=true"` | Turns "Disarm on low battery" on (`=false` turns it off) |
The URLs still work in 2.1.0 and later, but the command is better there
because it reports the result. `lowBatteryDisarm` is the only setting a URL
changes. Change it only when the user asks.
## Safety notes for the user
- Thermal safety is always on: if macOS reports serious or critical thermal
pressure, Clamshell disarms and the Mac returns to normal lid sleep.
- Keep a closed Mac on a hard surface with air around it, never in a bag.
- For long runs, plug the Mac in. On battery, "Disarm on low battery" (on by
default) lets the Mac sleep at 20% unless the user turned it off.
- Never arm, disarm or change settings without telling the user.
## More
- Full reference for agents: https://clamshell.dev/llms.txt
- Every clamshell.dev page is also available as Markdown: send `Accept: text/markdown`, or add `.md` to the path.
- Guides: https://clamshell.dev/guides/keep-claude-code-running-lid-closed and https://clamshell.dev/guides/keep-codex-running-lid-closed
- Support: [email protected], or https://github.com/matyasrathonyi/clamshell-for-mac/issues