Fixing "Your computer went to sleep mid-response"
If Claude Code showed API Error: Your computer went to sleep mid-response. The response above may be incomplete., your Mac slept while the response was streaming. What the notice means, what to do now, and the free ways to stop it happening again.
Lidnight stops runaway spend, silent approval stalls, and unexpected limit hits while you step away. Track Claude Code, Codex, Antigravity, Gemini and Kiro sessions, limits and cost, approve from your phone, and keep going with the lid closed.
Lidnight is a Mac app, so it can't be installed on this device. Open this address on your Mac to download it.
Copied. Paste it on your Mac to open it.
Couldn't copy. Tap the address below to select it, then copy.
What the message means
Claude Code noticed the computer slept while the response was streaming, and after wake-up it treats that connection as broken and stops reading it. Per Claude Code's error docs, if Claude had already completed some text or a tool call, it doesn't re-send the request (a tool could run twice); it keeps what was finished and appends this notice. If nothing had finished yet, it re-sends the request, and the retry label reads Connection lost while your computer was asleep.
What to do now: the output above the notice is still there, so in an interactive session just send a line asking it to carry on (for example continue). In -p, SDK and cloud sessions, Claude Code prompts Claude to continue up to three times by itself when a text-only response is cut off.
A re-sent request has to write the context again if the prompt cache expired while the Mac slept, which makes long sessions heavier. Public issues on the same problem: #102780, #102269.
The free fix, right now
Lid open: run [ "$(pgrep -x claude | wc -l)" -eq 1 ] && caffeinate -i -w "$(pgrep -x claude)" in another terminal (with several sessions, find the exact PID with pgrep -fl claude and run caffeinate -i -w <PID>). It blocks idle sleep only while that Claude process is alive and releases on its own when it exits (-i and -w in man caffeinate). Claude Code starts its own caffeinate too, but there's a report of it being killed so the Mac sleeps mid-task (#81832).
Lid closed on battery: man caffeinate doesn't cover lid closing, and the Mac usually still sleeps. sudo pmset -a disablesleep 1 can prevent it, and you must set it back to 0 afterwards (otherwise it drains and heats up in your bag; the option isn't in man pmset). Or stop background agents before closing the lid so the Mac sleeps cleanly. Fully awake or fully asleep is fine; the in-between (DarkWake) is the expensive state.
Checking whether it happened on your Mac
A free read-only script, lid-check, shows for each sleep period whether Claude Code requests were recorded inside it and how many fall in a DarkWake. It uses no network and writes no files.
curl -fsSL https://raw.githubusercontent.com/whereisdw/lid-check/main/lid_check.py | python3 -The numbers are transcript timestamps; they don't show limit usage or why a request happened. To read it first, download the file and run less lid_check.py before running it.
When it tends to happen
Two cases are common. (1) The lid is open but nothing is touched, so the Mac enters idle sleep (often 10–15 minutes). (2) With the lid closed, macOS briefly wakes for a few seconds (DarkWake, Power Nap / maintenance), the retry goes out, and the Mac sleeps again right away. Case 2 can repeat all night. DarkWake retries after closing the lid
If you'd rather not toggle it yourself: Lidnight
Lidnight uses Claude Code and Codex hooks to keep the Mac fully awake only while work runs (lid closed, on battery, background sessions included) and lets it sleep once every session is quiet. It doesn't sleep mid-response, so the sleep that triggers this notice doesn't happen, and the Mac rests when the work is done. There's no setting left behind to forget. Why overnight runs eat your limit
Checked 2026-11-12 against Claude Code's ‘Error reference’ (code.claude.com/docs/en/errors). Things change; check the docs.
Try Lidnight free
Apple Silicon Macs · macOS 13 or later. Every download includes a free trial of everything in Pro (14 days or 5 lid-closed runs of 10+ minutes, whichever comes first), no payment details needed. Pro is a one-time payment (1 Mac $9.99 · 3 Macs $14.99 USD, plus regional tax) with a 14-day full refund, no questions asked.
Lidnight is a Mac app, so it can't be installed on this device. Open this address on your Mac to download it.
Copied. Paste it on your Mac to open it.
Couldn't copy. Tap the address below to select it, then copy.