June 27, 2026 · Updated September 9, 2026 · 6 min read

How to Keep Your Mac Awake with the Lid Closed

Whether you're running a long compile, downloading a large file, or letting an AI coding agent work overnight — closing the MacBook lid and watching everything pause is one of the most frustrating Mac experiences. Here's every way to fix it, compared honestly.

Why does closing the Mac lid put it to sleep?

By default, macOS is designed to respect your power intentions. Closing the lid is treated as a signal that you're done working, so the system suspends. This behavior is deeply baked into macOS power management — the lid sensor triggers a sleep assertion that overrides most running processes.

However, macOS also exposes a public API for apps to hold wake assertions — essentially telling the OS "I'm still doing something important, don't sleep." Apple documents it as IOPMAssertionCreateWithName in IOKit, and the same mechanism powers the built-in caffeinate command. Apps like Caffeine, Amphetamine, and Hold My Lid all use this API. The difference is when and how intelligently they hold those assertions.

Apple's own answer for a shut lid is closed-display mode, which requires the Mac to be plugged in with an external display and a keyboard or mouse attached. Without those, a closed lid means sleep unless an app holds the right assertion.


Caffeine — The Classic Free Option

Caffeine is probably the most well-known Mac keep-awake app. It's free, open source, and brutally simple: click the menu bar icon to toggle it on, and your Mac stays awake. Click again to turn it off.

What Caffeine does well

  • Zero learning curve — one click, always on
  • Free and open source
  • Tiny memory footprint
  • Works reliably for keeping the display awake

Caffeine's limitations

  • Manual only — you must remember to toggle it on and off every single time
  • No lid-closed guarantee — on modern Apple Silicon Macs, Caffeine's standard wake assertion does not prevent sleep when the lid is fully closed. You need a stronger "system" assertion.
  • No timer or schedule support
  • No battery awareness — it'll happily drain your MacBook to 0%
  • Not actively maintained (the original Caffeine project has been largely dormant)

Bottom line on Caffeine: Great for desktop Macs or for keeping the display awake during a presentation. If you need your MacBook to stay awake with the lid physically closed, Caffeine alone won't cut it on modern Apple Silicon hardware.


Amphetamine — The Feature-Rich Free Option

Amphetamine is a free Mac App Store app that has become the go-to recommendation for power users who need more than Caffeine. It supports the stronger PreventUserIdleSystemSleep assertion, which — when combined with having an external display or power source — can keep a MacBook awake with the lid closed.

What Amphetamine does well

  • Free from the Mac App Store
  • Holds the right system assertion to keep lid-closed Macs awake
  • Scheduling (keep awake until a time, for N hours)
  • Trigger-based sessions (app running, drive mounted, network connected)
  • Battery percentage cut-off
  • Screen saver mode so the display isn't blaring all night

Amphetamine's limitations

  • No agent awareness — triggers fire when a process is running, not when it's actually doing work. Claude Code in the menu bar 24/7? Your Mac never sleeps.
  • Manual management — you still have to remember to start and stop sessions, or configure trigger rules upfront
  • No hooks into agent lifecycle — no way to know if Claude Code is mid-task vs. idle waiting for your next prompt
  • Trigger logic can be complex to set up correctly for developer workflows

Bottom line on Amphetamine: The best free option if you want to keep your Mac awake on a schedule or timer. But if you're running AI coding agents, you'll end up either (a) leaving your Mac awake unnecessarily long, or (b) having to babysit it anyway.


Hold My Lid — The Smart Option for Developers

Hold My Lid was built specifically for the workflow that Caffeine and Amphetamine weren't designed for: you have AI coding agents (Claude Code, Codex, Cursor, Gemini CLI) running long tasks, you want to close the lid and walk away, and you want the Mac to sleep again automatically once the agents finish.

How Hold My Lid keeps your Mac awake with the lid closed

Hold My Lid uses the same documented macOS wake assertions as Amphetamine — the ones that actually work for lid-closed scenarios. But it's agent-driven: it holds the assertions only while a watched agent is actively doing work, and releases them the moment your agents go idle. Your Mac sleeps automatically when the job is done.

Key features

  • Lifecycle hooks for Claude Code, Codex, and OpenCode — not just "is the process running" but "is it currently working on something"
  • Smart process detection for Cursor, Gemini CLI, Aider, and others
  • Battery guardrails — configurable cut-off, "only when plugged in" mode, Low Power Mode respect
  • Display control — turn the display off while agents run to save even more battery
  • Notifications — get a banner + sound when your agents finish so you know when to check back in
  • Global shortcut ⌥⌘L to toggle from anywhere
  • One-time payment of $9.99, works on up to 3 Macs

Why this matters: Amphetamine can trigger when Claude Code is running, but Claude Code might be sitting idle waiting for your next prompt 90% of the time. Hold My Lid knows the difference via lifecycle hooks, so your Mac only stays awake when there's real work to do.


Side-by-Side Comparison

FeatureCaffeineAmphetamineHold My Lid
PriceFreeFree$9.99 one-time
Lid-closed wake lock⚠️ Limited✅ Yes✅ Yes
Agent-aware (knows when agents are working)❌ No❌ No✅ Yes
Auto-sleep when agents finish❌ No❌ No✅ Yes
Claude Code lifecycle hooks❌ No❌ No✅ Yes
Codex + OpenCode hooks❌ No❌ No✅ Yes
Battery cut-off❌ No✅ Yes✅ Yes
Display off while sleeping❌ No✅ Yes✅ Yes
Finish notifications❌ No❌ No✅ Yes
Active maintenance⚠️ Minimal✅ Yes✅ Yes

Which one should you use?

Use Caffeine if…

You have a desktop Mac or an external display attached, and you just need a quick toggle to prevent sleep during a presentation or video call. Simple, free, zero setup.

Use Amphetamine if…

You need scheduling (keep awake until 3am), trigger-based rules (keep awake while a USB drive is mounted), or you're willing to manually manage sessions. Great free option for non-developer workflows.

Use Hold My Lid if… (recommended)

You run AI coding agents — Claude Code, Codex, Cursor, Gemini CLI — and want your Mac to stay awake exactly as long as the agents need it to, no more. Close the lid, put the laptop in your bag, and get notified when the job is done. Hold My Lid is the best Mac app for keeping your MacBook awake with the lid closed while AI agents work.


Frequently asked questions

Can I keep my MacBook awake with the lid closed without an external monitor?

Yes. Hold My Lid and Amphetamine both hold the PreventUserIdleSystemSleep assertion, which works without an external display. Note that some macOS updates have tightened lid-closed behaviour; both apps document their exact assertion types transparently.

Will keeping the Mac awake with the lid closed damage the battery?

Not directly, but heat management is slightly reduced with the lid closed. Hold My Lid ships with a battery cut-off threshold and an "only when plugged in" mode specifically to protect battery health.

Does Hold My Lid work with Claude Code?

Yes. Hold My Lid integrates with Claude Code via lifecycle hooks, so it knows exactly when Claude Code is mid-task versus idle, not just whether the process is running.

Is Caffeine still safe to use in 2026?

Caffeine is safe but limited. The original project is largely unmaintained, and its display-sleep assertion type does not prevent system sleep on lid close for Apple Silicon Macs.

Does the built-in caffeinate command keep a MacBook awake with the lid closed?

No. caffeinate -i or -d prevents idle sleep and display sleep, but macOS still treats a lid close as a sleep request. You need an app that holds the PreventUserIdleSystemSleep assertion, such as Amphetamine or Hold My Lid.

Sources

  1. Apple Developer: IOPMAssertionCreateWithName (IOKit power assertions)
  2. Apple Developer: kIOPMAssertionTypePreventUserIdleSystemSleep
  3. Apple Support: Use your Mac notebook in closed-display mode
  4. caffeinate(8) man page
  5. Caffeine for Mac on GitHub (IntelliScape fork)
  6. Amphetamine on the Mac App Store
  7. Apple: Maximizing battery performance

Ready to close the lid and keep coding?

Hold My Lid is the best app for keeping your Mac awake with the lid closed while AI coding agents work. Download free, pay once.