DEV Community

Cover image for Keep Claude Code & Codex Running With a Closed MacBook Lid (2026 Free & Open-Source Tools Compared)
Dawon Lee
Dawon Lee

Posted on

Keep Claude Code & Codex Running With a Closed MacBook Lid (2026 Free & Open-Source Tools Compared)

Disclosure: I build Lidnight (listed at the end), a closed-source macOS menu bar app with a paid Pro tier. This guide starts with built-in macOS commands and free tools, and notes where Lidnight falls behind.

Before paying for anything, see if a built-in setting or free app already fits:

  • Lid can stay open: Enable Prevent automatic sleeping on power adapter when the display is off in System Settings › Battery › Options, or run caffeinate -i claude (or caffeinate -i -w <PID>) with pmset displaysleepnow.
  • Closed lid on macOS 14+ (free, notarized OSS): Keepresso (GPL-3.0, any macOS 14+ Mac, 10+ agents + MCP) or Agent Session Pilot (MIT, Apple Silicon, Claude Code/Codex hooks + own Telegram bot).
  • Closed lid on macOS 26+ (free MIT): Adrafinil (macOS 26.4+, 11 agent hooks + thermal cutout) or Insomnia (krishhgg/Insomnia, 2,209★, timed sessions + 1-min recovery, marked experimental).

If you only want a raw shell wrapper around pmset, see my earlier post. First, check your Mac's power log to confirm what paused your last run:

# Check recent lid-close sleep and DarkWake events (this can take a few seconds)
pmset -g log | grep -E "Clamshell Sleep|DarkWake|Entering Sleep" | tail -n 40
Enter fullscreen mode Exit fullscreen mode

Look at the timestamps next to your last agent output: Entering Sleep ... Clamshell Sleep means closing the lid put the Mac to sleep, while DarkWake lines are brief background wakes while the Mac stays asleep (not a continuous active session).


Why Claude Code and Codex pause when you close the lid

macOS separates idle sleep from lid-close sleep. Under Apple's official closed-display mode guide (support.apple.com/en-us/102555), a MacBook stays awake natively only when connected to power and an external display (see Apple's guide for input devices).

Without an external monitor, closing the lid overrides ordinary idle-sleep assertions:

  • caffeinate limits: Per man caffeinate, -i only blocks idle sleep. -s is explicitly valid only on AC power, and the manual does not promise lid-closed operation without an external display.
  • Built-in agent assertions target idle sleep: Claude Code spawns caffeinate -i -t 300 during active sessions (discussed in claude-code#21432, an issue asking for a setting to disable it) and ships a built-in Keep awake plugin in 2.1.337+; both target open-lid idle sleep rather than lid-closed operation. On Codex CLI, a user reported the Mac idle-sleeping between automatic turns (codex#52399).
  • Claude Desktop & Remote Control: Official docs note that closing a laptop lid still sleeps the machine and pauses local execution until wake.

Which tool fits your setup (5-line shortlist)

Pick the first option below that covers your setup:

  1. Lid stays open: caffeinate -i claude + pmset displaysleepnow (built-in), or Napless ($8 founding / $24 regular, 3 Macs, macOS 13+ Intel/Apple Silicon, 17 agents + MCP; explicitly doesn't support closed-lid sleep).
  2. Free closed-lid apps (open-source and freeware): Keepresso (GPL-3.0, notarized, macOS 14+ Intel/Apple Silicon), Agent Session Pilot (MIT, notarized, macOS 14+ Apple Silicon, own Telegram bot), Amphetamine (free Mac App Store; Apple Silicon uses MIT Power Protect), Adrafinil (MIT, macOS 26.4+), Insomnia (krishhgg, MIT, macOS 26+), or Agent Awake (freeware, license unstated, macOS 14+, unnotarized, 5-min offline sleep).
  3. Avoid an admin password prompt: Lidwork ($9.99 one-time on the Mac App Store, all Macs on your Apple Account, sandboxed + 30s crash watchdog) or Clamshell ($9.99 for 1 Mac / $19.99 for 3 Macs, Setapp/Homebrew cask, Sleep Until Reset; vendor states no helper or password is needed).
  4. 40+ agents, Docker/Ollama, or Intel paid options (besides free Keepresso/StayAwake): Agent Caffeine ($9 launch / $14 regular, 1 Mac, 40+ agents, MCP, iPhone hotspot Beta), LidRun (free lid-open; Pro $9.90–$19.90, Docker/Ollama), or Hold My Lid ($9.99 early bird / $14.99 regular, up to 3 Macs, 7 hooks).
  5. Phone status or remote approvals: AfterLid (free Always On closed-lid mode, native iOS/Android app, and 1 provider usage view; Pro subscription adds remote mode switch, supported approvals/replies, and full provider usage via account & server-masked relay; Pro price and macOS version unstated), or Lidnight (macOS 13+ Apple Silicon only; trade-offs below).

Full comparison table (17 tools, including caffeinate and Lidnight; verified 2026-12-06; scroll horizontally on mobile)

Tool Price & license OS & lid-closed Agents & remote
caffeinate Free (built-in) macOS (open lid only) -w only; no remote
Keepresso Free (GPL-3.0, notarized) macOS 14+ AS/Intel; lid-closed (1x helper) 10+ agents, MCP, fan floor; webhooks only
Agent Session Pilot Free (MIT, notarized) macOS 14+ AS (+Win/Linux); lid-closed Claude/Codex hooks, net-drop resume; own Telegram bot
Adrafinil Free (MIT, cask) macOS 26.4+ (community macOS 15 port; chip unstated), lid-closed 11 agent hooks + thermal cutout; no remote
Insomnia (krishhgg) Free (MIT, experimental) macOS 26+ AS; timed lid-closed + 1m recovery Timer only (distinct from phin/insomnia 4★ AC-only)
StayAwake Free (MIT, unnotarized) macOS 26+ AS/Intel; lid-closed (sudoers) Manual/timers; no remote
Agent Awake Freeware (license unstated, unnotarized) macOS 14+ AS/Intel (Intel untested); lid-closed Codex/Claude Code/Cowork + 5m offline sleep; no remote
Amphetamine Free (closed-source) macOS 10.13+, lid-closed General triggers (Apple Silicon: MIT Power Protect)
Coca Free + IAP (closed-source) macOS 14+ (chip unstated), lid-closed Local iOS/watchOS control
AfterLid Free tier (Always On, 1 usage) + Pro sub (price unstated, closed-source) macOS/chip unstated; free lid-closed Claude/Codex/Cursor; native iOS/Android app + server-masked remote approvals (Pro)
LidRun Free lid-open / Pro $9.90–$19.90 (closed-source, notarized) macOS 13+ AS/Intel; lid-closed (Pro) Claude/Cursor/Codex/Docker/Ollama; webhooks only
Lidwork $9.99 once (Mac App Store, all Macs, closed-source) macOS 14+ AS; lid-closed, no password Manual/timer + Claude URL-scheme hooks
Clamshell $9.99/1 · $19.99/3 (7d trial, Setapp/cask, closed-source) macOS 14+ AS; lid-closed (no-helper vendor claim) Claude/Codex auto-sleep + Sleep Until Reset; Mac alerts only
Agent Caffeine $9 launch / $14 reg (1 Mac, 7d trial, 1y upd, closed-source) macOS 13+ AS/Intel; lid-closed + iPhone hotspot (Beta) 40+ agents + MCP + CLI hold; Stay reachable timer
Hold My Lid $9.99 early bird / $14.99 regular (3 Macs, trial days unstated, closed-source) macOS 14+ AS/Intel; lid-closed (vendor FAQ cites idle-sleep assertion) 7 agent hooks + Cursor/Cline; Mac alerts
Napless $8 founding / $24 reg (3 Macs, 7d trial, closed-source) macOS 13+ AS/Intel; no closed-lid 17 coding agents + MCP; Telegram/Slack alerts only
Lidnight (mine) Free lid-open / Pro $9.99 (1) or $14.99 (3), 14d/5-run trial, closed-source macOS 13+ Apple Silicon only; lid-closed (Pro, 1x helper) 5 hooks / 45 detected; QR phone status & approvals (Pro)

Check sleep settings and avoid overheating

sudo pmset -a disablesleep 1 isn't documented in man pmset, and unlike caffeinate, it doesn't automatically reset when your task ends. Verify it's back to 0 (or reset it explicitly) before packing your laptop:

# See what is currently blocking sleep
pmset -g assertions

# Blank the screen while keeping the lid open (pair with caffeinate -i)
pmset displaysleepnow

# Confirm disablesleep is back to 0 before putting your MacBook in a bag
pmset -g | grep SleepDisabled

# Restore normal sleep if SleepDisabled is still 1
sudo pmset -a disablesleep 0
Enter fullscreen mode Exit fullscreen mode

Apple's operating-temperature guidelines (support.apple.com/en-us/102336) specify 10–35°C (50–95°F) on a hard, ventilated surface, not on a bed or inside a bag. Software thermal cutoffs and battery floors are last-resort safeguards; don't run a closed MacBook inside a backpack.


Lidnight's trade-offs

For free, Keepresso (macOS 14+), Adrafinil (macOS 26.4+), and Agent Session Pilot (macOS 14+ Apple Silicon, own Telegram bot) already cover most closed-lid workflows.

Where Lidnight falls behind:

  • Closed-source & new: Paid Pro, 0 public reviews, and own public Homebrew tap (not homebrew-cask; Clamshell has 4,900+ downloads + Setapp/cask).
  • Platform & helper: Apple Silicon only (macOS 13+; 7 table rows list Intel, 5 tested closed-lid: Keepresso, StayAwake, LidRun, Agent Caffeine, Hold My Lid). Needs a 1x admin helper for closed-lid sleep, battery modes, and fan control (open-lid needs none; Lidwork/Clamshell skip it).
  • Missing features: No native mobile app (uses browser /remote/), MCP server, AC-only toggle, lid-close chime, macOS update-restart deferral, iPhone hotspot auto-join, 5-min offline auto-sleep, or temp-independent fan floor (uses temp-triggered SMC curves + Max 100%).

What it includes (Apple-notarized, macOS 13+ Apple Silicon):

  • Free: Open-lid keep-awake (manual AI Auto or ≤1h timers), active session status, and basic Mac alerts.
  • Pro closed-lid & remote: Auto-sleep 10m after finish (8h limit), 10% battery floor, 42°C (60s)/45°C SMC battery thermal cutoffs on battery (AC: critical thermal state), 10+ min lid-open recap, optional limit-reset resume (Claude Code & Codex, off by default). Push alerts go via unencrypted ntfy.sh (metadata only; approvals omit commands; off-by-default "Content in phone alerts" sends result/ask lines in plaintext). QR /remote/ encrypts status, messages, replies, and relay-only approval diffs via AES-GCM on lidnight.app (ntfy.sh status fallback), with one-time HMAC-SHA256 signatures for allow/deny and presets (Claude Code/Codex; optional Kiro/Gemini CLI gates; multiple-choice Claude Code only).
  • Idle baseline (2026-12-05): v1.11.87 measured 0.762% CPU, 120 MiB median physical footprint (~465–466 MiB RSS incl. shared frameworks) over 185s on a 10-core M4 Mac mini (synthetic fixture; no head-to-head closed-lid battery test yet).

Pro: $9.99 USD (1 Mac) / $14.99 USD (3 Macs) one-time, 1.x updates, 14-day full refund; Creem adds local tax (VAT/JCT/sales tax). Free trial: 14 days or 5 closed-lid runs of 10+ min (whichever comes first), no card/account.

Feedback welcome: if Lidnight doesn't fit your setup, tell me at support@dawonlabs.com; I read every message.

Lidnight (notarized DMG · Apple Silicon, macOS 13+) or brew install whereisdw/tap/lidnight (open-lid monitoring works with zero permissions; closed-lid requires Pro/trial + 1x admin password).


Sources verified (2026-12-06)

Top comments (0)