claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Desktop Code tab session keeps sending and retrying requests during macOS DarkWakes after lid close

Open ahmadkaouk opened this issue 1 month ago • 1 comments

Preflight Checklist

  • [ ] I have searched existing issues and this hasn't been reported yet. Closely related to #102597, which covers background agents. This report is a single foreground session in the desktop app, and the prompt cache stayed warm.
  • [x] This is a single bug report
  • [ ] I am using the latest version of Claude Code. The desktop app bundled 2.1.299 at the time; 2.1.302 is now the latest on npm.

What's Wrong?

A single foreground session in the desktop app's Code tab, with no background agents or subagents, kept sending and retrying requests during macOS DarkWakes after I closed the lid, and finished its task while the Mac was asleep.

I sent one prompt at 16:18 UTC on 2026-10-17 and closed the lid at 16:21:10 (Clamshell Sleep). The response being streamed at that moment ended at 16:21:09 with only a thinking block (8 output tokens). With nobody at the machine, the session then carried on in short background wakes:

UTC What happened (pmset log and session transcript)
16:30:29 7 s DarkWake. Claude Code flagged the 16:21 response as cut off mid-stream and sent an automatic "resume" request. The Mac slept again 7 s later with it in flight
16:50:30, 17:06:49, 17:21:06 Background wakes of 2 to 6 s (Sleep Service, then Maintenance). Each time the in-flight request failed with api_error "Connection lost while your computer was asleep" (StreamSuspended) and was retried
17:27:16 During a 5 s wake, one request completed and ran a tool. The next request was in flight when the Mac slept again
17:53:50 A 27-minute maintenance DarkWake began on AC power. After one more StreamSuspended retry, the session ran the rest of the task without interruption, finishing at 18:04:33
18:32:54 Lid opened

While the lid was closed, the transcript accounts for 29 requests: 25 completed and 4 were aborted with StreamSuspended. The 25 completed requests carried 648K to 728K tokens of context each and used 17.1M cache-read, 78K cache-write and 41K output tokens. Unlike #102597, the prompt cache stayed warm (1h TTL): every completed call read from the cache, and none wrote more than 8K tokens to it. The transcript records no usage for the 4 aborted requests.

My weekly Fable usage went from about 9% to 19% while the lid was closed (the 9% is from memory). The 25 completed requests are 18 to 23% of my Fable tokens this week, so I'd expect them to add roughly 2 to 4 points, not 10. As in #102597, I can't see locally what the aborted requests were charged.

What Should Happen?

A session that is mid-turn when the lid closes should wait until the user is back, or at least not send new requests during DarkWakes. Requests aborted by a system suspend shouldn't be billed as full requests.

Error Messages/Logs

# Session transcript: one api_error record per aborted request (fields summarized)
16:50:30Z  StreamSuspended  "Connection lost while your computer was asleep" / "Stream watchdog detected system suspend; aborting to retry on a fresh connection"  retryAttempt=1
17:06:49Z  StreamSuspended  (same)
17:21:06Z  StreamSuspended  (same)
17:53:50Z  StreamSuspended  (same)

# pmset -g log (exact lines, local time UTC+2)
2026-10-17 18:21:10 +0200 Sleep  Entering Sleep state due to 'Clamshell Sleep':TCPKeepAlive=active Using Batt (Charge:91%) 559 secs
2026-10-17 18:30:29 +0200 DarkWake  DarkWake from Deep Idle [CDNP] : due to smc.sysState.Wake(0x70070000) wifibt SMC.OutboxNotEmpty/ Using BATT (Charge:91%) 7 secs
2026-10-17 18:50:30 +0200 DarkWake  DarkWake from Deep Idle [CDNP] : due to NUB.SPMI0Sw3IRQ nub-spmi0.0x02 rtc/SleepService Using BATT (Charge:91%) 2 secs
2026-10-17 19:06:49 +0200 DarkWake  DarkWake from Deep Idle [CDNP] : due to NUB.SPMI0Sw3IRQ nub-spmi0.0x02 rtc/SleepService Using BATT (Charge:91%) 2 secs
2026-10-17 19:21:06 +0200 DarkWake  DarkWake from Deep Idle [CDNP] : due to NUB.SPMI0Sw3IRQ nub-spmi0.0x02 rtc/Maintenance Using BATT (Charge:91%) 6 secs
2026-10-17 19:27:12 +0200 DarkWake  DarkWake from Deep Idle [CDNP] : due to smc.sysState.Wake(0x70070000) wifibt SMC.OutboxNotEmpty/ Using BATT (Charge:91%) 5 secs
2026-10-17 19:53:50 +0200 DarkWake  DarkWake from Deep Idle [CDNPB] : due to NUB.SPMI0Sw3IRQ nub-spmi0.0x02 rtc/Maintenance Using AC (Charge:91%) 1610 secs
2026-10-17 20:32:54 +0200 Wake  Wake from Deep Idle [CDNVA] : due to smc.sysState.Wake(0x70070000) lid SMC.OutboxNotEmpty RTP.multi-touch/HID Activity Using BATT (Charge:98%)

Steps to Reproduce

These are the steps that led to it; I have not re-run them.

  1. On macOS with Power Nap on, open a session in the Claude desktop app's Code tab.
  2. Send a prompt that starts a multi-step task (tool calls, several model turns).
  3. Close the lid while a response is streaming, and leave it closed for about two hours, plugged into a charger for part of that time.
  4. Compare the session transcript with pmset -g log: requests are aborted and retried during DarkWakes, and the task finishes while the lid is closed.

Claude Model

Other: claude-fable-5-1

Is this a regression?

I don't know

Claude Code Version

2.1.299 (bundled with Claude desktop app 2.42304.0)

Platform

Anthropic API (Claude Max subscription)

Operating System

macOS 27.0.1

Terminal/Shell

Other: Claude desktop app, Code tab

Additional Information

Related: #102597 (the same DarkWake retry pattern with background agents, where each wake also rewrote the prompt cache) and #102269 (overnight sleep draining the weekly limit).

ahmadkaouk avatar Oct 17 '26 20:10 ahmadkaouk

Your table shows the costly part well: a turn that keeps going in 2–7 s DarkWake slices, losing each in-flight stream. Until the client waits for a full wake, the practical fix is to pick one state before you close the lid:

  • Let it finish awake. On AC or battery, sudo pmset -a disablesleep 1 keeps the Mac running with the lid shut, so the turn streams normally with no StreamSuspended retries. Undo it with sudo pmset -a disablesleep 0 afterwards. If you forget, the Mac stays awake in a bag.
  • Make it really stop. Press Esc to interrupt the turn before closing the lid, then resume when you're back. The session has nothing to send, so the wakes cost nothing.
  • Fewer wakes. sudo pmset -a powernap 0 should remove the long maintenance DarkWake (your 27-minute one on AC), but Wi‑Fi/BT and SMC wakes still happen, so this cuts down the retries without ending them.

pmset -g log | grep -E "DarkWake|Clamshell" shows which of these you're getting. None of this answers the billing question for the aborted requests. Only Anthropic can see that.

Disclosure: I build Lidnight, a menu bar app that keeps the Mac awake lid-closed only while Claude Code's hooks report a running turn, then lets it sleep: https://lidnight.app/en/

whereisdw avatar Oct 18 '26 02:10 whereisdw