Playbooks · Coding tasks
Stop a sleeping Mac draining your Claude Code limit
Written November 1, 2026
A Claude Code user on a Mac who leaves background agents running overnight needs to know which cache lifetimes and wake behaviours can re-send whole conversations, and which settings to check before closing the lid. This is the weakest-supported page in its batch: the drain itself rests on user reports, not on a statement from Anthropic.
What users reported, and what Anthropic has not said
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. The reports describe weekly limits dropping by a quarter or more overnight. One report counted 26 sleep and wake cycles in 6.5 hours with the lid closed. These are user reports. Nothing in the changelog entries or the caching docs linked below states that sleep drains a weekly limit, and no billing effect should be read into the fixes below: the fixes address sessions stopping, agents failing, and compaction giving up when a Mac sleeps or wakes. The mechanism in the next section — cache expiry plus a full re-send on wake — is documented by Anthropic. Whether it drained any particular reader's limit is not documented, and this page does not claim it.
Why a wake can cost a full re-send
Claude Code re-sends the full context on every request: the system prompt, the project context, every prior message and tool result, and the new message. Prompt caching avoids reprocessing the unchanged prefix, matching the start of each request against content recently processed. The match is exact, and entries expire after a period of inactivity. Each request that hits the cache resets the timer, so the cache stays warm while work continues. After a long enough gap, the next request recomputes the full input and re-establishes the cache, which is why the first turn back after stepping away can be noticeably slower. A Mac that sleeps for longer than the cache lifetime, then wakes briefly, therefore meets the documented conditions for a full re-send: the prefix has expired, and the whole conversation goes again.
The lifetime depends on which bucket the request falls in, and on how the reader is billed. Anthropic's caching docs give two buckets: the main conversation, and everything else — subagents, workflows, forks, compaction, and session titles. The defaults are:
| Request bucket | Claude subscription, within plan usage | Usage credits, API key, or cloud provider |
|---|---|---|
| Main conversation | One hour | Five minutes |
| Everything else | Five minutes, except server-controlled helper requests at one hour | Five minutes |
Subagents and workflows therefore get five minutes even on a subscription, until the reader chooses a longer lifetime. Once a subscription goes over its plan usage limit and draws on usage credits, the main conversation drops to the five-minute lifetime too. The five-minute bucket is the one that matters overnight: a background agent that wakes after more than five minutes of sleep has no warm cache to read from, and its next request reprocesses its context. A one-hour cache write costs more than a five-minute write, per the docs, so choosing the longer lifetime trades a higher write rate for survival through longer gaps.
What the October changelog fixed
Three early-October changelog entries address sleep directly, with the wording as the changelog states it. Version 2.1.287, October 1: macOS Remote Control sessions started with claude remote-control stopping mid-turn when the Mac went to idle sleep — fixed. Version 2.1.290, October 5: background agents failing with "Agent stalled" and Workflow tool subagents restarting from their prompt when a Mac woke from sleep — fixed; and automatic compaction giving up with "Prompt is too long" when a Mac went to sleep while it was running — fixed. Version 2.1.300, October 14: cache_creation_5m_tokens and cache_creation_1h_tokens added to the OpenTelemetry api_request event, splitting cache writes by lifetime, so the reader can see which lifetime each cache write used.
None of the three entries states a change to the default cache lifetime, and none of them addresses re-sending requests during brief wakes. The fixes stop sessions failing or restarting on wake; they do not keep a cache warm through a long sleep, and they do not stop a woken agent from re-sending an expired prefix. A reader on a version that includes all three fixes still faces the lifetime table above. Run claude --version before relying on any of them.
Choose the lifetimes yourself
Each bucket takes its own control, and each control takes 5m or 1h; Claude Code ignores any other value. Both controls require Claude Code v2.1.242 or later. The main conversation takes the promptCacheTtl setting or the CLAUDE_CODE_PROMPT_CACHE_TTL environment variable. Everything else takes the subagentPromptCacheTtl setting or the CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL environment variable. When more than one control applies, Claude Code takes the first match in this order: FORCE_PROMPT_CACHING_5M=1, which forces five minutes for both buckets; the bucket's environment variable; the bucket's setting; a subagent's cacheTtl frontmatter value; ENABLE_PROMPT_CACHING_1H=1, which requests one hour for both buckets; then the default for the bucket. For an overnight background run, the setting that changes the outcome is subagentPromptCacheTtl set to 1h: without it, the subagent and workflow bucket stays at five minutes on every billing kind. Setting it costs the higher one-hour write rate, and it does not help a sleep longer than an hour — a six-hour sleep expires a one-hour cache too.
Confirm which lifetime the main conversation's cache writes actually used with:
claude -p "hello" --output-format json
Read usage.cache_creation in the result. One-hour cache writes appear under ephemeral_1h_input_tokens and five-minute writes under ephemeral_5m_input_tokens. For a per-session summary, run /usage: after the main conversation's first response, Claude Code adds a Prompt cache (main) line showing the session's hit ratio, miss count, and whether the cache is warm, with the likely cause of the last miss where Claude Code can identify one. Both need Claude Code v2.1.251 or later; the likely-cause text needs v2.1.260 or later.
Steps: the checks before closing the lid
- Decide: fully awake, or fully stopped. The expensive middle state is a Mac that sleeps and wakes in short bursts with agents still running. Either keep the Mac awake for the whole run, or stop the background agents and workflows before the lid closes and resume them in the morning. Do not leave a run in the middle state overnight on the assumption that sleep pauses it cheaply.
- Check the version. Run
claude --version. The sleep fixes above shipped in early October; a version older than them still has the stalled-agent and compaction failures on wake. Update before relying on the fixes. - Set the subagent lifetime if the run must survive short gaps. Put
"subagentPromptCacheTtl": "1h"in settings, or setCLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL=1h, before starting the run. This covers gaps up to an hour. It does not cover an overnight sleep, and it raises the cache-write rate: use it for runs that wake within the hour, not as a general setting. - Keep the Mac awake only for idle sleep, deliberately.
caffeinate -iin another terminal blocks idle sleep while it runs. It does not stop lid-close sleep: closing the lid still sleeps the Mac unless the Mac is in a closed-display setup with an external display. A lid-closed overnight run needs the display setup or the stopped state from step 1, notcaffeinatealone. - After waking, read the cache line before continuing. Run
/usageand read thePrompt cache (main)line: hit ratio, miss count, and whether the cache is warm. A cold cache after a long sleep means the next turn reprocesses the conversation; that is the documented cost of the gap, and the time to decide whether the run is still worth continuing is before sending the next message, not after.
What can go wrong
- Assuming the October fixes solved the drain. They fixed failures on wake, not cache expiry. A fixed agent that wakes to an expired cache still re-sends its context.
- Setting the main-conversation lifetime and stopping there. The main conversation already gets one hour on a subscription within plan usage. The five-minute bucket is subagents and workflows, and it needs its own setting.
- Reading a user report as a confirmed billing effect. The quarter-or-more overnight drops are reports from GitHub issues. Anthropic's docs describe the cache mechanism and the sleep fixes; they do not state a billing effect. A reader's own
/usageline and billing page are the evidence for their own account. - Applying Mac evidence to other machines. Every sleep entry and every report in this page is Mac-specific: idle sleep, lid close, and wake behaviour on macOS. Nothing here describes sleep behaviour on Windows or Linux.
Limits
- This page states no billing figure and no confirmed billing impact. The only quantities are the documented lifetimes and the user-reported figures, labelled as reports.
- The changelog entries are stated with the dates and wording the changelog gives. Version numbers follow the release dates in the changelog; a reader whose installed version differs should trust
claude --versionand the changelog entry for that version. - Cache behaviour also depends on actions that invalidate the cache mid-session — model switches, effort changes, plugin and MCP changes, compaction — per the caching docs. A wake is one way to lose a warm cache, not the only one.
- Brief wakes during the night are the mechanism the reports describe, and the changelog does not address them. This page offers no setting that prevents a re-send after a gap longer than the chosen lifetime.
Related playbooks
- Claude Code 2.1.319: unattended runs stop stalling
- Keep Claude Code memory under 200 lines
- Stop fork subagents inheriting your context
- iPhone-use: a phone agent, no Mac needed
Sources
Sources: Claude Code changelog, How Claude Code uses prompt caching.
Back to: Coding playbooks hub · Also: Measure what Claude Code's background-agent summaries cost you, and decide what to turn off (a different cost: summary calls the reader cannot see, rather than sleep and cache expiry) · What an agent costs · Token cost calculator