Guide · October 2026

Keep your Mac awake while Claude Code runs

Hand off a long task and walk away without it stalling. The free commands that work right now (caffeinate, pmset), their limits, and how to check come first.

Lidnight keeps your Mac awake only while Claude Code or Codex is working, even with the lid closed, and lets it sleep when they finish.

Download freePro trial included · no card · Apple Silicon, macOS 13+

Why the work stops

When the Mac sleeps, Claude Code in your terminal stops too. The network drops, API requests fail, and you come back to find it stalled a few minutes in. Closing the lid or stepping away long enough for idle sleep both cause it.

The terminal may show API Error: Your computer went to sleep mid-response or Connection lost while your computer was asleep. The first is explained in the error-message guide, the second in the lid-closed guide.

The free fix, right now

Lid open, or plugged in: in another terminal tab run caffeinate -i -w "$(pgrep -nx claude)". Per man caffeinate, -i prevents idle sleep and -w releases when that PID exits. To wrap it from the start, use caffeinate -i claude. To prevent system sleep while on power, caffeinate -s (valid only on AC power).

Claude Code also starts its own caffeinate -i while it works (#21432), but there's a report of that caffeinate being killed so the Mac idle-sleeps mid-task once the display is off (#81832), so wrapping it yourself is the safer bet.

Lid closed, on battery: man caffeinate says nothing about closing the lid, and without an external display the Mac usually still sleeps. The command people use is sudo pmset -a disablesleep 1, undone with sudo pmset -a disablesleep 0. The option isn't in man pmset, so check the current value with pmset -g | grep SleepDisabled.

Limits: you turn it on for each session, and if you forget to undo disablesleep the Mac stays awake in your bag, draining and heating (it survives a restart). Handling that part automatically is what Lidnight below is for.

Checking that it worked

A free read-only script, lid-check, lists the sleep periods of the last 7 days and whether Claude Code requests were recorded inside them (lid-close sleeps show closed in the Lid column). It uses no network and writes no files.

curl -fsSL https://raw.githubusercontent.com/whereisdw/lid-check/main/lid_check.py | python3 -

To read it first, download the file, run less lid_check.py, then python3 lid_check.py. To see what is holding sleep off right now, use pmset -g assertions.

If you'd rather not toggle it yourself: Lidnight

Turn on Claude Code in Settings › Agents and Lidnight adds Claude Code hooks for when a task starts and ends, so it knows exactly — not by guessing — when it's working. Your settings file is backed up first, and turning it off removes only Lidnight's entries.

AI Auto mode: the Mac stays awake while work runs — lid closed or not — and sleeps once every session is quiet. With Pro it also turns itself on when work starts. Codex works the same way; other AI tools are detected from process and GPU activity.

Each AI gets a bunny in the menu bar. It runs faster as tokens flow, and sits down with an amber dot above its number when it's waiting for approval.

Also included

Claude and Codex 5-hour and weekly limits with reset times, plus tokens and estimated API-price cost by model and project — read from local logs. No sign-in, and your code and conversations never leave the Mac.

Questions

Multiple sessions at once? Yes. Each one is tracked, and the Mac sleeps only after the last one finishes.

Can I turn it on from inside Claude Code? Yes. The Claude Code plugin (free, MIT) adds /lidnight:awake, /lidnight:status and /lidnight:sleep, and Claude offers to keep the Mac awake before a long task. Run /plugin marketplace add whereisdw/lidnight-claude-plugin, then /plugin install lidnight@lidnight. The plugin

Why is lid-close sleep handled separately? Idle sleep and lid-close sleep are separate mechanisms. Details

Try Lidnight free

Apple Silicon Macs · macOS 13 or later. Every download includes a free trial of everything in Pro (5 lid-closed runs or 14 days), no payment details needed. Pro is a one-time payment (1 Mac $9.99 · 3 Macs $14.99, 50% off through Dec 1) with a 14-day refund.

Download freeBuy Pro ›More about Lidnight ›

Homebrew: brew install whereisdw/tap/lidnight