By default, closing a MacBook lid puts macOS to sleep and pauses local Claude Code and Codex sessions until you open it again. Cloud runs (Claude Code cloud, cloud Cowork tasks on Pro and Max plans, and Codex Cloud) execute on remote servers and keep going while your laptop sleeps. Local CLI runs (claude, codex, codex exec), local desktop sessions, and phone remote control stop on lid sleep. Your closed-lid options are sudo pmset -a disablesleep 1, Apple's closed-display mode, a free app with a sudoers rule, or a paid app like Clamshell.

I make Clamshell, one of the options below.

caffeinate and built-in app settings

With the lid open, locking the screen keeps local Claude Code sessions running. On macOS, Claude Code starts caffeinate while working, or you can wrap a run yourself:

caffeinate -i claude 

Claude's desktop app also has "Keep computer awake", and OpenAI's desktop app has "Keep this Mac awake" and "Prevent sleep while running".

Where they stop working: caffeinate and those settings hold off idle sleep only. Closing the lid runs a separate lid-close sleep path, so the Mac sleeps anyway. caffeinate -s applies on AC power only, and caffeinate(8) says nothing about closing the lid. OpenAI's docs also say that with a Mac laptop lid closed, you should connect an external display.

sudo pmset -a disablesleep 1

macOS includes a command that works with the lid closed and no monitor:

sudo pmset -a disablesleep 1 

Check it with pmset -g (look for SleepDisabled 1). When you are done, undo it and confirm SleepDisabled reads 0:

sudo pmset -a disablesleep 0 pmset -g 

Where it stops working: pmset needs sudo and an admin password both ways. disablesleep is undocumented in pmset(1), and pmset -g reports SleepDisabled as one value across battery and charger (even with -c or -b). It has no menu bar state, timer, heat cut-off, or battery stop, and closing Terminal or restarting does not guarantee it clears. Forget to undo it and a closed Mac can drain flat or overheat in a bag. Full check and undo steps are in my pmset disablesleep guide.

Apple's closed-display mode

Connect an external monitor, power, and an external keyboard and mouse, and macOS keeps a closed MacBook awake for free.

Where it stops working: unplug the monitor or charger and closing the lid sleeps the Mac again.

Amphetamine and other free apps

KeepingYouAwake and Caffeine-style apps cover idle sleep only, so closing the lid still sleeps the Mac.

Amphetamine is free and includes Closed-Display Mode. On Apple Silicon, it can fail when you plug in or unplug power unless you add Power Protect, a separate add-on that installs a sudoers file with your admin password. Users also report timed sessions without a display quietly dropping protection. Sleepless is a free, open-source (MIT) option on macOS 26 if you accept the sudoers rule its installer adds.

Clamshell

Clamshell is a paid menu bar app for Apple Silicon MacBooks on macOS 14 or later (not Intel Macs). While armed, it keeps the Mac awake with the lid closed, on power or battery, with no external display, no sudo or admin rights, and no kernel extension or privileged helper. The built-in display stays black, the Mac locks when you open the lid, and normal lid sleep returns when you disarm, quit, or restart.

It has a free 7-day trial (no card), then $9.99 once for one Mac or $19.99 for up to 3 Macs, with no subscription and a 14-day money-back guarantee. It is also on Setapp. It is not on the Mac App Store (App Store apps named Clamshell are from other developers). Install from clamshell.dev or Homebrew, then open it once:

brew install --cask clamshell 

Arm it from the menu bar, with both Option keys, by holding Option while closing the lid (on Macs with a lid angle sensor), or from a script or agent:

/Applications/Clamshell.app/Contents/Helpers/clamshell arm /Applications/Clamshell.app/Contents/Helpers/clamshell disarm /Applications/Clamshell.app/Contents/Helpers/clamshell status 

Setapp installs the same command under /Applications/Setapp/Clamshell.app. Each call prints one line. Exit 0 means done, 1 means refused or failed (with the reason, such as heat or an ended trial), and 3 means Clamshell is not running (arm launches it first). status --json prints JSON, and Settings > General has a Copy button with a one-sentence instruction for Claude Code or Codex.

Clamshell 2.1.0 adds the optional Arm While Agents Work module (Settings > Modules > Agents). It arms while an agent works or waits on you, then lets the Mac sleep about 2 minutes after agents stop. Waiting counts for 15 minutes, and each agent for 4 hours at most.

If you prefer hooks, Claude Code (~/.claude/settings.json) and Codex (~/.codex/hooks.json) support SessionStart and SessionEnd hooks. A session-counting script can drive free caffeinate -i (lid open) or open "clamshell://arm" and open "clamshell://disarm" (lid closed). The tested script is in my Claude Code hooks guide.

Heat, battery, and unattended runs

Keep a closed MacBook on a hard, ventilated desk, never in a bag or on bedding, and plug it in overnight. Staying awake does not approve prompts or fix dropped Wi-Fi, so set permissions up front (claude -p with --allowedTools or --permission-mode, or codex exec --sandbox workspace-write).

Clamshell's thermal safety is always on: serious or critical thermal pressure disarms toward normal lid sleep and blocks arming until the Mac cools. Disarm on low battery is on by default at 20%.

Which option to use

  • Cloud sessions (Claude Code cloud or Codex Cloud) if the job only needs your Git repo.
  • caffeinate -i or locking the screen if the lid can stay open.
  • Apple's closed-display mode at a desk with a monitor, power, keyboard, and mouse.
  • sudo pmset -a disablesleep 1 on Intel Macs or macOS 13 and earlier, or when you accept sudo for a free option. Amphetamine with Power Protect and Sleepless are the free apps, each with a sudoers rule.
  • Clamshell on an Apple Silicon MacBook (macOS 14 or later) for closed-lid local runs with no monitor, no sudo, nothing to undo, and heat and battery cut-offs.