If your Claude Code weekly limit dropped overnight with the lid closed and almost nothing to show for it, look for DarkWake in the Mac's sleep log. A sleeping Mac still wakes briefly on its own, and GitHub reporters describe background agents re-sending their whole conversation on each of those DarkWakes, writing it to the prompt cache again, and freezing as the Mac sleeps again, with weekly limits dropping by a quarter or more overnight. The fix is to keep the run either fully awake or fully stopped: with the lid open, caffeinate -i or Claude's Keep computer awake; with the lid closed, Clamshell for Mac, a menu bar app that keeps the Mac fully awake while armed so agents finish instead of pausing and re-sending; or stop the agents before you close the lid.
An animated MacBook with a coding agent deploying a website from its terminal. The Option key is held and the lid closes: the display goes black, but the Mac stays awake, so a dimmed copy of the terminal keeps working above the closed laptop while its front edge fills with light. When the deploy is done, a pointer shows how to lift the lid. Opening it wakes the Mac to its lock screen, which unlocks to the finished run: deployed, with the live address. The lid can then be opened and closed freely.
Clamshell for Mac keeps the Mac fully awake with the lid closed while armed, so agents finish their work instead of pausing and re-sending it. Free for 7 days.
Apple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or install with Homebrew: brew install --cask clamshell.
In mid-October 2026, several people opened GitHub issues against Claude Code with the same story: they closed the lid, or let the Mac idle-sleep, while background agents or a workflow were still running, and found a large part of their weekly limit gone in the morning with very little to show for it. This page separates what Anthropic documents from what those users report, then shows how to check your own Mac and how to stop paying for wake-ups.
Check, then fix
- Look for DarkWakes. Run
pmset -g log | grep -E "Entering Sleep|DarkWake|Wake from"and read the hours of the run. A run of short DarkWakes about every 15 minutes while the lid was closed is the pattern in the reports. - Match them to the drop. If agents were mid-run during those wakes and
/usageshows prompt cache misses, the wakes are the likely cost. The full checks are below. - Remove the half-asleep state. Next time, keep the run fully awake or fully stopped: stop or pause the agents before you close the lid, or arm Clamshell for Mac so the closed Mac stays awake while they work.
- If the agents hit the limit itself. Clamshell's optional Sleep Until Reset module (Clamshell 2.0 and later), on the charger with the lid closed, lets the Mac sleep once no agent is working and one stopped on a usage limit. It wakes the Mac 1 minute after each limited Claude Code or Codex account resets and keeps it awake while any agent works, up to 4 hours. macOS asks you once to allow it in Login Items.
On this Mac, in the cloud, or on a server
The half-asleep state only happens to agents that run on a sleeping Mac. There are three ways to keep a Claude Code run going while your laptop is shut without it.
| Where it runs | Fits when | What keeps running | Effort | Limits |
|---|---|---|---|---|
| This Mac, lid closed, with Clamshell for Mac | The task needs this Mac: your checkout as it is now, local MCP servers, simulators, local models, apps you are signed in to | The whole local session, fully awake, so there are no brief wakes and no re-sent context | Arm Clamshell, check it shows armed, close the lid. $9.99 once after a 7-day trial | Apple Silicon and macOS 14 or later. Keep the Mac on a desk with air around it, ideally on power. At serious or critical heat, or at 20% on battery, Clamshell disarms and normal sleep, brief wakes included, returns |
| Anthropic's cloud: a Claude Code cloud session | The task needs only the repository and the tools the cloud environment provides | The session on Anthropic's infrastructure. Anthropic says it keeps running after you close your laptop | Connect GitHub, push your branch, then start the task on the web, in the Claude app or with claude --cloud | It starts from a copy of the repository, not your live checkout, and cannot reach anything else on your Mac. Usage counts toward the same plan limits. Needs a Pro, Max, Ultra or Team plan, or an Enterprise seat that includes it |
| Your own server, in tmux | You already have a machine that stays on, such as a VPS, a Linux box or a desktop Mac, with the project and its tools set up there | Everything inside the tmux session. tmux keeps programs running in the background after you detach, and you reattach over SSH | Set up the machine, SSH keys, the repository and Claude Code, then tmux new -s agent and later tmux attach -t agent | A server to pay for or keep on, and to maintain. It cannot reach files or apps on your MacBook. Closing the MacBook only drops your SSH connection |
Clamshell for Mac is the way to do the first row without a monitor or admin rights. The rows also mix: cloud sessions for tasks that need only the repository, the closed Mac for the ones that need this Mac. Sources for the cloud and tmux rows, checked November 14, 2026: Anthropic's cloud sessions docs and the tmux wiki.
What Anthropic's docs say about the cache
Claude Code reuses a prompt cache so it does not reprocess the whole conversation on every request. Entries expire after a period of inactivity, the TTL (time to live). Anthropic's prompt caching docs set the default per request:
| Request | Claude subscription, within plan usage | Usage credits, API key or cloud provider |
|---|---|---|
| Main conversation | One hour | Five minutes |
| Subagents, workflow agents, everything else | Five minutes (a few server-controlled helper requests get one hour) | Five minutes |
- Agents get the short cache. The docs say subagents fall outside the main-conversation bucket and "get five minutes even on a subscription", and the workflows docs say the same for workflow agents.
- Over the plan limit, the main conversation drops too. Once you draw on usage credits, Claude Code switches the main conversation to the five-minute TTL.
- You can choose.
promptCacheTtlsets the main conversation andsubagentPromptCacheTtleverything else, to5mor1h; the environment variablesCLAUDE_CODE_PROMPT_CACHE_TTLandCLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTLdo the same. Both need Claude Code 2.1.242 or later. - Writes cost more than reads. On the Claude API price list, a five-minute cache write costs 1.25 times base input and a one-hour write 2 times, while a cache hit on Opus 5.5 or Sonnet 5.5 costs 0.05 times. Rewriting a context therefore costs 25 times what reading it would. Anthropic does not publish how cache writes weigh against a subscription's limits.
Two more documented facts matter here. The agent view docs say background sessions "are also preserved when your machine sleeps. Their processes resume on wake", so sleep does not lose your work. And the errors reference says that when Claude Code detects the computer went to sleep while a response was streaming (Your computer went to sleep mid-response), it treats the connection as broken once the Mac wakes. That partial response has to be requested again.
What the Claude Code changelog says
Anthropic has fixed several sleep problems this month. From the Claude Code changelog, with dates from the GitHub releases:
- 2.1.287, October 1: "macOS: Fixed Remote Control sessions started with
claude remote-controlstopping mid-turn when the Mac went to idle sleep". - 2.1.290, October 5: "Fixed background agents failing with "Agent stalled" and Workflow tool subagents restarting from their prompt when a Mac woke from sleep", and "Fixed automatic compaction giving up with "Prompt is too long" when a Mac went to sleep while it was running".
- 2.1.300, October 14: added
cache_creation_5m_tokensandcache_creation_1h_tokensto the OpenTelemetryapi_requestevent, so you can see which lifetime your cache writes used.
None of the entries from 2.1.287 to the current 2.1.302 changes the default cache TTL, and none addresses re-sending requests during brief wakes.
What users report
These are user reports, open as of October 17, 2026. Nobody from Anthropic had confirmed the billing impact in the threads, and the first three cross-reference each other, so treat them as one cluster with several reporters rather than independent proof.
| Report | Setup | What the reporter measured |
|---|---|---|
| #102597, Oct 15 | Lid closed on battery, two background subagents mid-stream | 26 sleep and wake cycles about every 15 minutes over 6.5 hours, 81 requests sent and 29 completed, 15 full cache rewrites of about 7.1M tokens, about 7K output tokens, weekly usage from 20% to 56% |
| #102269, Oct 15 | Desktop app Code tab, a 7-agent workflow left running overnight | Weekly limit down about 25%; a follow-up comment lists 75 cache writes after pauses longer than five minutes, 30.3M cache write tokens, all on the five-minute TTL |
| #102780, Oct 16 | Three background agents, Mac idle-sleeping about every 15 minutes | About six hours of "went to sleep mid-response" cut-offs, each retry re-sending about 80K tokens with zero cache reads |
| #102276, Oct 15 | Claude Code 2.1.300 | Main-conversation cache writes switched from one hour to five minutes |
| #103064, Oct 17 | Desktop app Code tab, one foreground session, no subagents, warm prompt cache | 29 requests during DarkWakes while the lid was closed, 25 completed; weekly usage rose from about 9% to 19% (the 9% from memory) |
| #103233, Oct 18 | Terminal session with a subagent running, Claude Code 2.1.302 | A failure loop while the Mac slept; the reporter estimates 40% of weekly usage with no useful output |
| #37752, Mar 23 | 9 sessions open, lid closed on battery, 24 DarkWakes over about 6 hours | About 10% of the 5-hour session limit gone by morning; closed as not planned on Apr 21 without a staff reply |
About the 2.1.300 TTL claim. Issue #102276 is labelled a duplicate, and a commenter's correction in the thread says the five-minute writes were not tied to the version: interactive sessions started on October 15 got five-minute writes on both 2.1.299 and 2.1.300, while claude -p kept one-hour writes, and setting "promptCacheTtl": "1h" switched a running session back. The changelog lists no TTL change, and the docs still give subscriptions a one-hour main-conversation cache. On the Mac this page was written on, every main-conversation cache write that 2.1.300, 2.1.301 and 2.1.302 recorded from October 15 to 17 was a one-hour write. That is one account, so check your own (below) rather than assume either way. Agents and workflows get five minutes by default regardless.
Why the half-asleep state is the expensive one
The reporters' logs show the middle case. A sleeping Mac still wakes briefly on its own (the #102597 log shows a DarkWake about every 15 minutes), and in that report Claude Code noticed the frozen stream on each wake and re-sent the request straight away. The retry paid a full cache write and was frozen again seconds later. In #102780 the Mac was idle-sleeping with the lid open, so the same loop can happen at your desk.
Closing the lid does not keep the Mac awake for a busy agent. Apple's developer note QA1340 classes closing the lid as forced sleep, which apps can delay but not prevent.
Check your own Mac
- Did the Mac sleep during the run? The
pmsetmanual says-g logshows the history of sleeps and wakes:
A row of short wakes roughly every 15 minutes through the night is the pattern in the reports.pmset -g log | grep -E "Entering Sleep|DarkWake|Wake from" - Which TTL do your writes use? Anthropic's docs give this test. Look at
usage.cache_creation: one-hour writes appear underephemeral_1h_input_tokens, five-minute writes underephemeral_5m_input_tokens.
It runs in print mode, which the #102276 thread says was not affected, so an interactive session can differ.claude -p "hello" --output-format json - How often did the cache miss? In a session, run
/usage. From 2.1.251 the Session block has a Prompt cache (main) line with the hit ratio, the misses and whether the cache is warm right now. - Is something holding the Mac awake now?
pmset -g assertionslists every sleep hold, includingcaffeinate's.
Fixes, cheapest first
Stop or pause agents before you close the lid
Free, and the right call if the run can wait. A fully asleep Mac sends nothing, and agent view preserves the sessions so they resume when you come back. The reporter of #102597 suggests the same thing: fully awake or fully asleep, not in between.
Lid open: caffeinate or Keep computer awake
Free and enough at a desk. caffeinate -i -w "$(pgrep -nx claude)" blocks idle sleep until that Claude Code process exits. In the Claude desktop app, Keep computer awake in Settings, This computer, System prevents idle sleep. Both stop at a closed lid; Anthropic's docs add that closing the lid still puts the Mac to sleep.
Set the cache to one hour
Add "subagentPromptCacheTtl": "1h" (and "promptCacheTtl": "1h" if your writes show five minutes) to ~/.claude/settings.json. Gaps under an hour then read the cache instead of rewriting it. It does not stop the re-sending, longer gaps still rewrite, and one-hour writes are priced at twice base input.
Lid closed: Clamshell for Mac
Keeps an Apple Silicon MacBook on macOS 14 or later fully awake with the lid closed while armed, on power or battery, with no external display, sudo or admin rights. No brief wakes, so no re-sent context. The agents keep working and keep using your limit on real work. If macOS reports serious or critical thermal pressure, or the low-battery switch (on by default) trips at 20%, Clamshell disarms and the closed Mac goes back to normal sleep, brief wakes included. Its optional Sleep Until Reset module, which macOS asks you once to allow in Login Items, lets the Mac sleep when an agent stops on a usage limit and wakes it when the limit resets. $9.99 once after a 7-day trial.
Try it freeTwo more ways exist. Apple's clamshell mode keeps a closed MacBook awake with power, an external display, keyboard and mouse attached. sudo pmset -a disablesleep 1 stops lid sleep with nothing attached, but it is a global admin switch that stays on until you undo it; read pmset disablesleep explained first.
Arm only around a run
Clamshell has a URL scheme and Shortcuts actions (Arm, Disarm, Toggle and Status). A wrapper arms it for one job and disarms when the job ends:
open "clamshell://arm"
claude -p "run the test suite and fix the failures"
open "clamshell://disarm"
The arm request is asynchronous, so check the menu bar state before you close the lid. Clamshell's core does not detect Claude Code or its agents, so it does not disarm on its own when they finish unless you use its optional Finish Work, Then Sleep module; the last line, a Shortcut, or Claude Code hooks do that. The hooks recipe arms on session start and disarms when the last session ends.
Clamshell keeps your Mac awake with the lid closed. Free for 7 days, then $9.99 once for one Mac. 14-day money-back guarantee.
Apple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or install with Homebrew: brew install --cask clamshell. Also on Setapp.
Frequently asked questions
Does Claude Code use my usage limit while my Mac is asleep?
Not while the Mac is fully asleep, because nothing is sent. The cost comes from the brief wakes in between: GitHub reporters describe background agents re-sending their whole conversation on each wake, writing it to the prompt cache again, and the Mac sleeping again before the answer arrives. Anthropic had not confirmed the billing impact in those threads as of October 17, 2026. To avoid those wakes with the lid closed, Clamshell for Mac keeps the Mac fully awake while armed, so agents finish their requests instead of re-sending them.
How long does Claude Code's prompt cache last?
Anthropic's docs say the main conversation gets a one-hour cache on a Claude subscription within plan usage, and five minutes on usage credits, an API key or a cloud provider. Subagents and workflow agents get five minutes by default, even on a subscription, unless you set subagentPromptCacheTtl to 1h.
Did Claude Code 2.1.300 change the prompt cache TTL from one hour to five minutes?
Not according to the changelog, which lists no TTL change from 2.1.287 to 2.1.302, and the docs still give subscriptions a one-hour main-conversation cache. Issue #102276 reported five-minute writes on 2.1.300; a commenter's later correction tied them to interactive sessions started on October 15 rather than to the version. Check your own writes with claude -p "hello" --output-format json.
Does caffeinate stop the cache rewrites?
With the lid open, yes for idle sleep: caffeinate -i -w "$(pgrep -nx claude)" keeps the Mac awake until that Claude Code process exits, so agents never pause long enough for the cache to expire. It does not stop the sleep that closing the lid causes. For a closed lid, Clamshell for Mac keeps the Mac awake while armed, with no sudo or external display.
Will keeping the Mac awake with the lid closed save usage?
It removes the sleep and wake cycles that make agents re-send their context, but the agents keep working, so they keep using your limit on real work. If you do not need the run, stopping the agents before you close the lid is the cheapest option. If you do need it, Clamshell for Mac keeps the closed Mac fully awake while armed, and its optional Sleep Until Reset module lets the Mac sleep through a usage limit and wakes it when the limit resets.
Related guides
- Does Claude Code keep running when you close your laptop?
- Does Claude prevent sleep? Keep computer awake vs closed lid
- Arm Clamshell from Claude Code hooks
- Claude Code Remote Control keeps disconnecting?
- Run AI coding agents overnight on a MacBook
- Why caffeinate does not work with the lid closed
Sources checked October 19, 2026: Anthropic's Claude Code docs on prompt caching, workflows, agent view, errors and desktop scheduled tasks; the Claude API prompt caching price list; the Claude Code changelog and GitHub release dates; GitHub issues #102597, #102269, #102780, #102276, #103064, #103233 and #37752 (user reports); Apple Technical Q&A QA1340; and the macOS caffeinate and pmset manual pages. Clamshell behavior is described from its published facts. Clamshell is an independent app, not affiliated with or endorsed by Anthropic or Apple. Claude and Claude Code are trademarks of Anthropic.