Back to Guides

Claude Code stops when you close your MacBook: how to keep it running

Claude Code stops when you close your MacBook: how to keep it running

Claude Code or another AI coding agent stops when you close your MacBook because closing the lid puts the Mac to sleep, and a local session sleeps with it. To keep it running, the lid must not close fully, or you need a tool that blocks lid-close sleep, or the work has to run somewhere other than your MacBook.

The cause is macOS, not Claude Code. A MacBook without an external display always goes to sleep when the lid closes, and no normal setting changes that.

What are the ways to keep Claude Code running?

  • Leave the lid open. Costs nothing. caffeinate -i or the desktop app's "Keep computer awake" covers idle sleep.
  • Keep the lid 12 mm open with a lid spacer. WakeClip, a lid spacer for MacBook Air, MacBook Neo and MacBook Pro, stops the lid before it closes. No installation and no admin rights.
  • Amphetamine and similar apps. They keep the Mac awake, and some can also prevent sleep with the lid closed. The lid is then fully shut.
  • sudo pmset -a disablesleep 1. Switches sleep off system-wide, including lid-close sleep. Needs admin rights and has to be reset with sudo pmset -a disablesleep 0.
  • External display or HDMI dummy plug. With a display, power, keyboard and mouse, a closed MacBook keeps working. A dummy plug imitates the display.
  • Cloud routine or a second computer. The task does not run on the MacBook at all.

Why is caffeinate not enough when you close the lid?

caffeinate is a Terminal command that ships with macOS. It prevents sleep from inactivity. It does not prevent the sleep that closing the lid triggers.

Idle sleep starts when nothing has happened for a while, and a program can hold it off. Lid-close sleep starts the moment the lid shuts, and caffeinate has no option for it.

The same applies to the keep-awake functions inside Claude Code. Many tools keep the Mac awake by themselves while they work. In the Desktop app, the setting "Keep computer awake" under Settings, Desktop app does this for idle sleep. Anthropic's documentation for Desktop scheduled tasks says that closing the lid still puts the laptop to sleep.

So caffeinate -i claude is a good way to start a long session in the Terminal with the lid open. It does not help once the lid is shut.

Which Claude Code workflow are you using?

Whether the lid matters depends on where the work runs.

Local session in the Terminal or Desktop app

Files, commands and tests run on your MacBook. If the Mac sleeps, the run pauses. This is the case the rest of this guide is about.

/loop and local scheduled tasks

/loop repeats a prompt inside a running session. It does not move the work to the cloud. Local scheduled tasks in the Desktop app need the app running and the computer awake.

Remote Control from your phone

Remote Control gives you access to a session that still runs on your computer. Your phone does not take over the work. If the MacBook sleeps, there is nothing to control until it wakes.

Cloud routine

A cloud routine, which Anthropic now calls a cloud scheduled task, runs in a separate environment hosted by Anthropic and keeps working with your laptop closed. The repository, connections and tools have to be available there. It has no access to files that exist only on your Mac.

When does a lid spacer fit a Claude Code run?

WakeClip keeps the lid 12 mm open. Your MacBook does not go to sleep from closing the lid, and whatever is running keeps running.

It fits well in these situations:

  • You want to lower the lid and carry the MacBook in your hand to another room while the session continues. Hold it by the base and do not press on the lid.
  • You close the lid out of habit. The lid stops at the clip and the run is not ended.
  • You work on a company Mac where you cannot install apps or use sudo.
  • You do not want the MacBook standing open on the desk.

Unlike a fully closed lid, the gap leaves air above the keyboard, so heat can escape. Nothing has to be reset afterwards. Take the clip off and the MacBook sleeps normally again.

Idle sleep stays a separate matter. Many tools keep the Mac awake while they work. To be sure, start the session with caffeinate -i claude, turn on "Keep computer awake" in the Claude desktop app, or use the macOS setting that prevents sleep on the power adapter.

Where is something else the better choice?

  • The MacBook goes into a bag. WakeClip is made for carrying in your hand, not for a bag. A working MacBook does not belong in a bag or sleeve. Remove the clip and close the MacBook normally before you stow it.
  • The task should run overnight without you. A cloud routine, a server or a desktop computer is the better place.
  • The lid has to be fully shut. Use Amphetamine, pmset disablesleep, or an external display. With pmset, remember to reset it. Otherwise the Mac also stays awake in your bag.

What else can stop a run?

Three things interrupt a session even on a Mac that stays awake:

  • Network. If you carry the MacBook out of Wi-Fi range, the connection drops. That can interrupt a task whether the Mac is awake or not.
  • A waiting prompt. Claude Code may be waiting for a permission or an answer from you.
  • Power. An empty battery ends every run. Plug in for long sessions.

If a run stops with the lid open, the lid is not the cause. The guide MacBook sleeps despite keep-awake settings goes through the causes in order. For a side-by-side view of all methods, see Keep a MacBook awake with the lid closed: 7 ways compared.

Short answer

A local Claude Code run needs an awake MacBook, and a closed lid means sleep. If the small gap suits how you work, choose the WakeClip version for your MacBook model.

WakeClip is an independent accessory and is not affiliated with Apple or Anthropic.