AIToday
AI Coding AssistantsZenn AI/MLPublished: Oct 9, 2026, 22:00 JST

pmset disablesleep fix keeps Claude Code alive with lid shut

pmset disablesleep fix keeps Claude Code alive with lid shut

A user left a Claude Code subagent running overnight with the MacBook lid closed and returned to a "Request timed out" failure. Logs (`pmset -g log`) showed the machine entered Clamshell Sleep the moment the lid shut, cutting the in-flight request.

Not sure about something? Ask the AI

Questions and answers are published on this page.

Summaries like this, in your inbox every morning.

Context & Analysis

The problem the author describes is not a bug in the code or the API — it's macOS itself. When the lid closes without an external display attached, the machine enters what the logs call "Clamshell Sleep", and a request that was in flight at that moment is cut. The failure doesn't surface immediately; it was recorded hours later, during a DarkWake, as "Request timed out". That gap is why the symptom looks mysterious and the cause is easy to misattribute.

The tools that seem like they should help don't. `--bg` background sessions and Remote Control both keep execution on the local Mac, so they are preserved across sleep but produce no progress during it. `caffeinate` and the Desktop app's "Keep computer awake" setting only target idle sleep — as the macOS SDK comment quoted in the piece puts it, the system may still sleep for lid close, low battery, or other reasons. The author also points out that idle sleep is already handled: Claude Code itself spawns a `caffeinate -i -t 300` child process, so the only remaining gap is the lid.

The proposed fix, `sudo pmset -a disablesleep 1`, has to be run in an ordinary Terminal, because Claude Code's `!` bash mode has no terminal to read a password. Interestingly, the `AppleClamshellCausesSleep` flag still reads `Yes` even after the change; based on a reading of the public XNU source, `SleepDisabled` sets a separate `userDisabledAllSleep` path that rejects the clamshell sleep request, so `pmset -g log` is the more reliable check. The author tested this once, only on battery, with the lid closed for an unrecorded period, and warns the option isn't documented — hence the caution about power draw, heat, and remembering to reset it.

FAQ
Why doesn't `--bg`, Remote Control, or `caffeinate` keep Claude Code alive with the lid shut?
`--bg` and Remote Control both execute on your own Mac, so nothing progresses while the machine sleeps. `caffeinate` and the Desktop app's "Keep computer awake" only block idle sleep, and the system still sleeps on lid close.
How do I check whether the sleep setting actually took effect?
Run `pmset -g | grep SleepDisabled` and look for `SleepDisabled 1`. The author also filtered `pmset -g log` with `(Sleep|Wake|DarkWake) {2,}` so idle-sleep assertion lines from `caffeinate` don't bury the real sleep and wake entries.
Why not just use the cloud session (`claude --cloud`) instead?
Cloud sessions keep running after you close the laptop, but they can't reach local databases, localhost services, SSH tunnels, or credentials that only exist on your machine. The author also notes they need a Pro / Max / Team plan and a claude.ai login, and may be reclaimed if idle.

AI news that matters for your work, delivered every morning.

Pick your industry and the AI tools you use, and get news related to your work every day.

Free · 30 seconds with Google · unsubscribe anytimeWhat is AIToday? →

Ask AI

Ask AI anything about this article. The AI reads this article, earlier AIToday articles, and Wikipedia, and cites its sources. Q&As are published on this page for other readers too.

Questions and answers are published on this page.

Related Articles

Next articleOpenAI halts Dark Clark, Iranian fake-byline influence ops