What does “API Error: Your computer went to sleep mid-response” mean in Claude Code?
Short answer
It means your Mac went to sleep while Claude's reply was streaming. When the Mac woke, Claude Code treated the connection as broken, kept the parts Claude had finished and stopped. Reply continue to pick up from there. To stop it happening, keep the Mac from idle-sleeping while Claude works, and don't close the lid mid-task.
The sleep messages, word for word
Claude Code has four messages that name sleep. They come from Anthropic’s error reference.
| Message | When you see it |
|---|---|
API Error: Your computer went to sleep mid-response. The response above may be incomplete. |
The Mac slept while a reply was streaming, after Claude had finished at least one block |
Your computer went to sleep before a response was produced |
The turn ended after Claude finished thinking, but before any text or tool call |
Connection lost while your computer was asleep |
A retry label: Claude Code is sending the request again after a sleep broke it |
MCP server "<name>" connection timed out. Your computer went to sleep or its clock changed while connecting. |
An MCP server was still connecting when the Mac slept, or the clock jumped forward |
For the first one, the docs explain: “Claude Code detected that your computer went to sleep while the response was streaming. Once your computer wakes, Claude Code treats the connection as broken and stops reading from it.”
What to do right now
In an interactive session, read what’s on screen. Claude Code “keeps every block Claude completed before the error, but discards an interrupted final block when the turn ends, so the final sentences or tool calls may be missing.” Then reply:
continue
Claude picks up from its last completed block. If it was in the middle of editing files, a quick look at what changed
(for example with git status) before you continue doesn’t hurt.
In non-interactive mode (-p), resume the session and send continue. With --continue, Claude Code picks up the
most recent conversation:
claude -p "continue" --continue
For the MCP message, keep the Mac awake and reconnect: run /mcp, pick the server and choose Reconnect.
Why your Mac went to sleep
There are three usual causes:
- Idle sleep. Nobody touched the Mac, the display turned off, and the Mac slept. On our Mac, this was by far the most common.
- The lid. Closing the lid forces sleep, and Apple says apps can’t prevent that, only delay it (QA1340).
- Low battery. macOS also forces sleep when the battery runs very low.
You can see which one it was. This lists the Mac’s recent sleeps with their cause, such as Idle Sleep or
Clamshell Sleep (the lid):
pmset -g log | grep "Entering Sleep" | tail -20
We ran this on our own development Mac for one week (20 to 27 October 2026) and matched each sleep against Claude Code’s session logs. Sleep cut off 15 to 23 Claude Code runs:
| Cause | Runs cut off |
|---|---|
| Idle sleep on the charger | 7 to 12 |
| Idle sleep on battery | 8 |
| Lid closed (on battery) | 0 to 3 |
The range comes from two ways of counting: the higher number also counts a session that was waiting on a permission prompt. The battery ran down to 1% twice in the same week.
Why Claude Code’s own keep-awake didn’t stop it
It depends where you run Claude Code. The full breakdown is in Does Claude Code prevent sleep?, but in short:
- In a terminal, the CLI holds off idle sleep with caffeinate, but a reported gap every four minutes can let the Mac slip into sleep once the display is off (#81832).
- In VS Code, the extension held no sleep lock at all in our test (v2.1.311).
- In the desktop app, Keep computer awake is a setting you have to turn on.
- Everywhere, closing the lid still sleeps the Mac.
How to stop it happening
-
On the charger, turn on Prevent automatic sleeping on power adapter when the display is off in System Settings › Battery › Options (Apple). In our week, that covers seven to twelve of the runs above.
-
In a terminal, start Claude Code through caffeinate, which holds the Mac awake until you quit:
caffeinate -i claude -
In the desktop app, turn on Keep computer awake in Settings › Desktop app.
-
Keep the lid open, or read Can I close my laptop while an agent runs? for the options that work with it shut.
Or let Night Crew handle it. It sees Claude Code in the terminal and in VS Code with no setup, keeps the Mac awake while Claude works, and lets it sleep 60 seconds after. It also has lid mode, and it stops at a battery floor of 15%. See Night Crew for Claude Code.
Sources
- Claude Code docs: error reference
- Claude Code docs: continue conversations in non-interactive mode
- claude-code #81832: caffeinate respawn leaves a gap
- Apple QA1340: idle sleep vs forced sleep
- Apple: set sleep and wake settings for your Mac
- Claude Code docs: desktop scheduled tasks ("Keep computer awake")
- caffeinate man page (ss64)
Checked 5 November 2026.