# Keep Claude Code running with the MacBook lid closed

> caffeinate doesn't survive closing a MacBook's lid. pmset disablesleep does, if you remember to undo it. The free options, the risks, and a one-switch way.

Source: https://shuriken.sh/guides/keep-claude-code-running-lid-closed

caffeinate doesn't survive closing a MacBook's lid. pmset disablesleep does, if you remember to undo it. The free options, the risks, and a one-switch way.

By Shuriken Updated 27 October 2026 5 min read

**Contents**

caffeinate won't keep Claude Code running when you close a MacBook's lid: the Mac sleeps anyway. sudo pmset -a disablesleep 1 does keep it running, but it stays on until you undo it, battery and all. Or turn on Cocaine mode in Shuriken: one switch, a one-time password, off when you say.

Below: why the Mac sleeps, every free option with its catch, and how we do it.

## Why the Mac sleeps when you close the lid #

Closing the lid isn't the same as walking away. "Idle sleep" happens when nobody touches the computer for a while. Closing the lid is a separate, deliberate signal, and macOS treats it as "go to sleep now".

The one built-in exception is closed-display mode, often called clamshell mode: a MacBook on power with an external display, keyboard and mouse stays awake with the lid shut. That's great at a desk. It's no help on a train.

When the Mac sleeps, Claude Code stops mid-step. The network drops, the test run never finishes, and Anthropic's own Remote Control docs say it plainly: if your laptop sleeps, the session reconnects "when your machine comes back online" ([Claude Code docs](https://code.claude.com/docs/en/remote-control)). Nothing happens in between.

## caffeinate: good, but not for the lid #

macOS ships caffeinate, and it's the right tool for "don't nap while I'm out of the room". Its manual page lists what it can hold ([caffeinate(8)](https://ss64.com/mac/caffeinate.html)):

- -i "prevent the system from idle sleeping"
- -s "prevent the system from sleeping", but "valid only when system is running on AC power"
- -d keeps the display on, -w <pid> releases the hold when a process exits

A handy pattern is caffeinate -i -s -w <pid> with the process ID of your agent, so the hold ends when the agent does. Or run the agent under it: caffeinate -i claude.

What caffeinate doesn't do is override the lid. Its manual page never mentions the lid, and in practice a MacBook with no external display goes to sleep when you shut it, caffeinate or not.

## pmset disablesleep: works, with a catch #

The switch that does survive a lid close is a power setting:

bash
sudo pmset -a disablesleep 1

-a applies it on battery and on power. Check it with pmset -g, where you'll see SleepDisabled 1. Now close the lid, and the Mac keeps running.

To undo it:

bash
sudo pmset -a disablesleep 0

The catch is everything around it:

- It stays on. Until you run the second command, your Mac won't sleep for anything: not the lid, not idle, not overnight in your bag. Forget once and you find out at 3% battery.
- It isn't documented. disablesleep isn't in pmset's own manual page ([pmset(1)](https://ss64.com/mac/pmset.html)), so Apple can change it without telling anyone. It works on the Macs we use today.
- It needs sudo every time, unless you add a sudoers rule yourself, which is its own small project.

If you go this way, put the undo command somewhere you'll see it, like an alias you run every morning, or a script that turns sleep back on when your agent exits.

## Menu-bar keep-awake apps #

Several Mac apps put keep-awake in the menu bar. The best-known is Amphetamine, which is free on the Mac App Store and says it can "keep your MacBook awake while its display/lid is closed". Its listing also notes that Closed-Display Mode sessions "now require 1) installation of a script that Amphetamine will run", plus administrator verification ([App Store](https://apps.apple.com/us/app/amphetamine/id937984704?mt=12)). Smaller utilities exist too, and how they handle the lid varies.

They're a real improvement on remembering Terminal commands: triggers, timers, a visible icon. What they don't know is whether your agent is still working. We compared them in [keep-awake apps for coding agents](https://shuriken.sh/compare/amphetamine-alternatives-for-coding-agents).

Shuriken's Cocaine mode keeps the computers you pick awake while your agents run.

[Download](https://shuriken.sh/download)

## Cocaine mode: one switch #

Yes, that's really its name. We called it that because that's roughly what it does to your laptop: no sleep, a lot of work, slightly warm. The story is in [Yes, it's called Cocaine mode](https://shuriken.sh/blog/cocaine-mode-yes-really).

We built it because we kept doing the pmset dance ourselves and kept forgetting the second half.

- Pick your computers. The syringe button in the top bar opens your devices. Turn Cocaine mode on for the ones that should keep going, including a computer you're not sitting at. A pill in the sidebar shows when it's on.
- One password, once. On a Mac, running with the lid closed needs an administrator to allow it. Shuriken asks once, and after that it switches without prompts. Revoke permission takes it back.
- It stays on until you turn it off. No timers to babysit.
- It cleans up after itself. Under the hood it's the same disablesleep switch, but Shuriken notes what it changed and puts it back when you turn the mode off or Shuriken stops, a crash included. While Shuriken isn't running, your Mac sleeps as usual.
- Lid open is a separate setting. On each device's page, Keep awake is While working (held while an agent, the queue or a workflow runs) or Always. A computer signed in to Shuriken starts on Always, so it stays reachable; the screen can still turn off. That setting never covers a closed lid: that's Cocaine mode's job. See [Keep awake only while agents work](https://shuriken.sh/blog/keep-awake-while-working).

Close the lid, walk to the train, open it at home and read what the agents did. Or don't open it, and check from your phone; our guide to [running Claude Code from your phone](https://shuriken.sh/guides/run-claude-code-from-your-phone) shows how.

## Windows and Linux #

You can do this by hand on both:

- Windows: in your power plan, set what closing the lid does to Do nothing. Microsoft documents it as the lid close action, LIDACTION, with 0 meaning Do nothing ([Microsoft Learn](https://learn.microsoft.com/en-us/windows-hardware/customize/power-settings/power-button-and-lid-settings-lid-switch-close-action)). Remember to set it back.
- Linux: systemd-logind decides. HandleLidSwitch= "defaults to suspend"; set it to ignore in logind.conf, or have a program hold a handle-lid-switch inhibitor lock while it runs ([logind.conf](https://www.freedesktop.org/software/systemd/man/latest/logind.conf.html)).

Shuriken 5.1 brings Cocaine mode to Windows and Linux. Laptops differ there, so we don't promise lid-closed on every one: each device says what it can do, from "Keeps running with the lid closed" to "Stays awake. No lid setting found on this computer". On Linux it needs systemd-logind.

## Heat, bags and battery #

A laptop that works with its lid shut is still a computer doing work.

- Heat. A closed MacBook has less room to shed heat. On a desk, lid shut, is fine. Zipped into a backpack for an afternoon of test runs is not. Give it air.
- Battery. Awake means drawing power. Agents, the network and your test suite all use it. For anything longer than a commute, plug in.
- Network. On a train the Wi-Fi drops in tunnels. Agents need a connection to reach their models, so expect pauses.

And if a laptop just shouldn't be on all night, put the agents on a computer that's always on. Our guide to [running Claude Code overnight](https://shuriken.sh/guides/run-claude-code-overnight) covers the rest of the checklist.

If you're tired of typing sudo pmset twice a day, [download Shuriken](https://shuriken.sh/download), close the lid, and let the agents keep working.

Share

[X](https://x.com/intent/post?url=https%3A%2F%2Fshuriken.sh%2Fguides%2Fkeep-claude-code-running-lid-closed&text=Keep%20Claude%20Code%20running%20with%20the%20MacBook%20lid%20closed)[LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fshuriken.sh%2Fguides%2Fkeep-claude-code-running-lid-closed)[Hacker News](https://news.ycombinator.com/submitlink?u=https%3A%2F%2Fshuriken.sh%2Fguides%2Fkeep-claude-code-running-lid-closed&t=Keep%20Claude%20Code%20running%20with%20the%20MacBook%20lid%20closed)[Reddit](https://www.reddit.com/submit?url=https%3A%2F%2Fshuriken.sh%2Fguides%2Fkeep-claude-code-running-lid-closed&title=Keep%20Claude%20Code%20running%20with%20the%20MacBook%20lid%20closed)[E-mail](mailto:?subject=Keep%20Claude%20Code%20running%20with%20the%20MacBook%20lid%20closed&body=https%3A%2F%2Fshuriken.sh%2Fguides%2Fkeep-claude-code-running-lid-closed)

## Sources

- [caffeinate(8) manual page (macOS)](https://ss64.com/mac/caffeinate.html) (accessed 22 October 2026)
- [pmset(1) manual page (macOS)](https://ss64.com/mac/pmset.html) (accessed 22 October 2026)
- [Amphetamine on the Mac App Store](https://apps.apple.com/us/app/amphetamine/id937984704?mt=12) (accessed 22 October 2026)
- [Microsoft Learn: Lid switch close action](https://learn.microsoft.com/en-us/windows-hardware/customize/power-settings/power-button-and-lid-settings-lid-switch-close-action) (accessed 22 October 2026)
- [systemd: logind.conf](https://www.freedesktop.org/software/systemd/man/latest/logind.conf.html) (accessed 22 October 2026)
- [Claude Code docs: Remote Control (limitations)](https://code.claude.com/docs/en/remote-control) (accessed 22 October 2026)

## Frequently asked questions

**Is it safe to run a MacBook with the lid closed?**

It's safe on a desk or a shelf, where air can move. A closed laptop has less room to shed heat, so don't run long jobs zipped into a bag or under a duvet, and plug in for long runs.

**Does caffeinate keep a Mac awake with the lid closed?**

Not on its own. caffeinate stops idle sleep, and its -s option only works on AC power. Closing the lid without an external display still sleeps the Mac.

**How do I keep a Windows or Linux laptop awake with the lid closed?**

On Windows, set what closing the lid does to Do nothing in your power plan. On Linux, set HandleLidSwitch=ignore in logind.conf or hold a systemd-inhibit lock. Shuriken 5.1 brings Cocaine mode to both, where the laptop allows it.

**What is clamshell mode?**

Apple's closed-display mode: a MacBook stays awake with the lid shut when it's on power with an external display, keyboard and mouse. Without that setup, closing the lid sleeps it.

**How do I undo pmset disablesleep?**

Run sudo pmset -a disablesleep 0. Check with pmset -g: SleepDisabled should read 0 or be missing.

Cocaine mode

Close the lid. Your agents keep working.

Pick which of your computers stay awake while agents work. On a Mac that holds with the lid closed, and on Windows and Linux where the laptop allows it.

[Download](https://shuriken.sh/download)

[Other platforms](https://shuriken.sh/download#main)

## Keep reading

- [Shuriken on Windows 10 and 11: Update 27 Oct 2026 3 min read Run Claude Code, Codex and 65 more coding agents in parallel on Windows 10 and 11. Installer or .zip, x64, with signed updates.](https://shuriken.sh/blog/shuriken-on-windows)
- [What's new in Shuriken 5.1: Update 27 Oct 2026 16 min read Shuriken 5.1 adds sign-in with Google, Apple or an email code, passkeys, Allow and Always allow at a MacBook's notch, and billing and fuel in Sources.](https://shuriken.sh/blog/shuriken-5-1)
- [How to switch Claude accounts without logging out: Guide 27 Oct 2026 7 min read Three ways to use several Claude accounts in Claude Code without /logout and /login: one config per account, a switcher CLI, or a harness.](https://shuriken.sh/guides/switch-claude-accounts-without-logging-out)

## Free tools

- [Claude limit reset tracker](https://shuriken.sh/tools/limit-resets/claude)
- [Codex limit reset tracker](https://shuriken.sh/tools/limit-resets/codex)
