June 27, 2026 · Updated September 9, 2026 · 7 min read
Stop Babysitting Your MacBook: Keep It Awake While AI Coding Agents Work
AI coding agents like Claude Code, Codex, and Cursor have changed how developers work. But there's still one friction point: close the lid and the Mac sleeps, killing your agent mid-task. Here's how to fix it for good.
The problem: your Mac sleeps in the middle of an agent task
Here's the scenario: you kick off a large Claude Code task — a full test suite migration, a multi-file refactor, or a long research + implementation job. You close the lid, put the laptop in your bag, and go to a meeting or make coffee. When you come back 30 minutes later, the agent has been sitting suspended for 25 of those minutes. The task you thought was done is halfway through.
This happens because macOS treats a closed lid as an intent to sleep. By default, even if there's an active process running, the system will suspend when the lid closes. For most apps, this is fine — and even desirable. For long-running AI coding agents, it's a constant source of friction.
The naive fix — just leave the lid open — doesn't work if you're moving around. And keeping the laptop awake all the time (using an app like Caffeine always-on) wastes battery and means your Mac never sleeps even when agents are idle.
Your options in 2026
Option 1: macOS System Settings (Energy Saver)
You can disable sleep entirely in System Settings → Battery → Options → "Prevent automatic sleeping on power adapter when the display is off." This works when plugged in, but it's all-or-nothing — your Mac never sleeps, even when nothing is running. Not ideal for battery life or thermals. Apple's closed-display mode has the same catch: it only applies when the Mac is plugged in with an external display and keyboard or mouse attached.
Option 2: Caffeine or Lungo
Caffeine and its spiritual successor Lungo are one-click menu bar toggles. They hold a display-wake assertion, which means they keep the screen from sleeping. On Apple Silicon Macs, a simple display assertion doesn't prevent the system from sleeping when the lid closes. You need a stronger system-level assertion.
Even if you use a fork that holds the right assertion type, you're still left with a manual toggle — you have to remember to turn it on before you close the lid, and turn it off when your agent finishes. That's babysitting with extra steps.
Option 3: Amphetamine triggers
Amphetamine lets you create trigger-based sessions: "keep awake while Terminal is running" or "keep awake while Claude is running." This is a step up from manual toggles, but the trigger fires on whether the process exists, not on whether it'sworking. Claude Code can be in the menu bar 24/7; an Amphetamine trigger would keep your Mac awake 24/7 too.
Option 4: Hold My Lid (agent-aware)
Hold My Lid was built specifically for this scenario. It integrates with the lifecycle hooks that Claude Code, Codex, and OpenCode expose — hooks that fire when an agent starts a task and when it finishes. Hold My Lid holds the wake assertion during the task and releases it when the agent goes idle. Your Mac sleeps automatically when there's nothing to do.
Why Hold My Lid is the right tool for AI agent workflows
It knows the difference between "working" and "open"
Via lifecycle hooks, Hold My Lid tracks the exact working state of each agent session. Three Claude Code windows open? Hold My Lid tracks each independently and only holds assertions for the ones actively mid-task.
It sleeps your Mac when the job is done
Once all watched agents go idle (configurable idle timeout, default 30 seconds), Hold My Lid releases the wake assertions. macOS returns to its normal sleep schedule. No drain, no babysitting.
It tells you when to look
You don't have to keep checking your laptop. Hold My Lid sends a macOS notification (with an optional sound) when all agents finish. Put the laptop in your bag, get a coffee, come back when your phone pings — or your Apple Watch.
It protects your battery
Battery cut-off threshold, "only when plugged in" mode, respect for macOS Low Power Mode, and display-off control (so the screen doesn't blare into your bag) mean you can use this confidently on battery when needed, with guardrails that make sense.
Setting it up takes under 2 minutes
- 1
Download and launch Hold My Lid
Download from holdmylid.app or install via Homebrew:
brew install --cask holdmylid - 2
Install the Claude Code hooks
Hold My Lid walks you through this on first launch. It adds a few lines to your Claude Code hook configuration — no manual editing required.
- 3
Start a Claude Code task and close the lid
The menu bar icon goes orange while an agent is working. Close the lid. Your Mac stays awake. Come back when you get the notification.
Supported coding agents
Hold My Lid uses two integration methods — lifecycle hooks (most accurate) and process detection (reliable fallback):
| Agent | Integration | What it detects |
|---|---|---|
| Claude Code | ✅ Lifecycle hooks | Working / Idle per session |
| Codex (OpenAI) | ✅ Lifecycle hooks | Working / Idle per session |
| OpenCode | ✅ Lifecycle hooks | Working / Idle per session |
| Cursor | ⚡ Process detection | On while process is alive |
| Gemini CLI | ⚡ Process detection | On while process is alive |
| Aider | ⚡ Process detection | On while process is alive |
| Windsurf / Codeium | ⚡ Process detection | On while process is alive |
Lifecycle hooks = real Working / Idle signal. Process detection = on while the process is alive. Both use the same system wake assertion.
Frequently asked questions
Does Hold My Lid work on Apple Silicon (M1, M2, M3, M4)?
Yes. Hold My Lid uses the same PreventUserIdleSystemSleep assertion that Amphetamine uses, the one that works on Apple Silicon for lid-closed scenarios. We are also transparent about the edge cases where macOS may override this.
What happens if my Mac runs out of battery while an agent is working?
Hold My Lid ships with a configurable battery cut-off. When your battery hits the threshold, it releases the wake assertions and lets macOS sleep normally. You can also set "only when plugged in" so it never engages on battery at all.
Is Hold My Lid safe? Does it send my code or agent output anywhere?
No. Hold My Lid does not touch your code, your agent’s output, or your terminal sessions. It only reads the hook signals (working or idle) and uses macOS APIs to hold wake assertions. Everything stays local.
Can I use Hold My Lid alongside Amphetamine?
Yes, they do not conflict. But if you install Hold My Lid you probably will not need Amphetamine for developer workflows, because the use cases overlap.
Does it work for Cursor or Windsurf, which have no lifecycle hooks?
Yes, via process detection. Hold My Lid watches for these processes and holds assertions while they are running. It is less precise than hooks (it cannot distinguish working from idle) but still prevents lid-close interruptions.
What makes Hold My Lid the best app for AI coding agents?
Hold My Lid is the only Mac app built specifically for this workflow. It understands AI coding agents: not just "is a process running" but "is an agent mid-task". It keeps your Mac awake for Claude Code, Codex, or any AI agent, sleeps automatically when they finish, and has battery guardrails to protect your machine.
Sources
- Apple Support: Use your Mac notebook in closed-display mode
- Apple Developer: kIOPMAssertionTypePreventUserIdleSystemSleep
- Apple Support: About Power Modes on your Mac
- Claude Code documentation: Hooks
- OpenAI Codex documentation: Hooks
- OpenCode documentation: Plugins
- Caffeine for Mac on GitHub (IntelliScape fork)
- Lungo by Sindre Sorhus
- Amphetamine on the Mac App Store
Close the lid. Keep coding.
Hold My Lid is the best Mac app for keeping your MacBook awake while AI coding agents work. Agent-aware, battery-safe, automatic.
Free trial · $9.99 one-time · Works on up to 3 Macs