Fixing Claude Code's 'Login reached its time limit' and 'Your computer went to sleep mid-response' Errors on Mac
Quick checks and free workarounds for the two errors that halt long or overnight Claude Code runs on macOS. Disclosure: I build Lidnight, a closed-source macOS app with a paid Pro tier; it's covered in one section at the end. Everything before that uses official Claude Code settings, built-in macOS commands, and free tools (plus a brief comparison of paid alternatives).
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.
Two errors that stop long runs
Leave Claude Code on a long or overnight run on a Mac, and two errors can stop it cold:
1. Login reached its time limit · Please run /login (or Login expired · Please run /login): Your claude.ai OAuth login couldn't refresh. Check /status, renew with /login (or claude setup-token for unattended scripts), and add a free StopFailure hook for alerts.
2. API Error: Your computer went to sleep mid-response. The response above may be incomplete.: macOS went to sleep mid-stream. Reply continue, check pmset -g log, and prevent sleep with caffeinate -i (lid open) or a free closed-lid tool.
Check your Mac logs first
Run these read-only checks before changing settings:
# 1. Confirm whether macOS slept or DarkWoke during the run (takes a few seconds)
pmset -g log | grep -E "Clamshell Sleep|DarkWake|Entering Sleep" | tail -n 30
# 2. If a login refresh failed, check expiry dates, disk space, and competing Claude processes
claude auth status --text
df -h ~/.claude
LC_ALL=C pgrep -fl claudeInside Claude Code, run /status. If your stored sign-in can no longer refresh, the Login row shows Expired — log in again.
What real Mac output looks like (read-only sample, 2026-12-05)
For contrast, here is a no-sleep baseline from an Apple Silicon MacBook with SleepDisabled=1 (pmset -g stats shows Sleep Count:0, Dark Wake Count:0): pmset -g log records lid-open and caffeinate idle-sleep assertions with no sleep events. When a Mac actually goes to sleep, you'll see Entering Sleep ... Clamshell Sleep lines instead:
2026-12-05 13:43:20 +0900 Assertions PID 565(powerd) Created UserIsActive "com.apple.powermanagement.lidopen" 00:00:00 id:0x0x90000888b [System: PrevIdle PrevDisp DeclUser IntPrevDisp kDisp]
2026-12-05 14:22:38 +0900 Assertions PID 565(powerd) TimedOut UserIsActive "com.apple.powermanagement.lidopen" 00:01:59 id:0x0x900008d37 [System: PrevIdle PrevDisp DeclUser SysAct IntPrevDisp kDisp]
2026-11-30 05:38:29 +0900 Assertions PID 72031(caffeinate) Summary PreventUserIdleSystemSleep "caffeinate command-line tool" 00:00:29 id:0x0x10000a0fc [System: PrevIdle PrevDisp DeclUser kDisp]The first two lines show powerd creating one lidopen assertion (line 1) and a separate lidopen assertion timing out 1m 59s after a later lid-open (line 2), with PrevIdle and PrevDisp active and no sleep or DarkWake events recorded in between. The third line shows caffeinate holding PreventUserIdleSystemSleep (-i idle sleep only) for 29 seconds and exiting cleanly.
For auth expiry checks, claude auth status --text (v2.1.333, active login, account fields redacted) prints the exact two-date window Claude Code uses for its 10-day stderr warning:
Login method: <redacted>
Organization: <redacted>
Email: <redacted>
Anthropic base URL: https://api.anthropic.com
Sign-in ends: between 2026-12-17 and 2026-12-20 (2026-12-20T14:32:43.237Z)1. "Login reached its time limit · Please run /login" — why it stops
A claude.ai subscription login refreshes automatically until it hits its lifetime cap or renewal fails. Anthropic's error reference documents these related messages (with reached its time limit wording starting in v2.1.318+):
Login reached its time limit · Please run /login (or Login expired · Please run /login) · Failed to authenticate: this login reached its time limit · Failed to authenticate: OAuth session expired and could not be refreshed · Could not refresh your login because another Claude Code process is refreshing it (concurrent sessions racing the same refresh token) · Could not refresh your login: the disk that holds the Claude Code config directory (~/.claude by default), or your disk quota on it, is full.
Before expiry, Claude Code warns at startup (Your login expires in 3 days · run /login to renew). In non-interactive claude -p text runs (v2.1.318+), it prints Warning: this sign-in on stderr when the later of the two expiry dates shown by claude auth status --text is under 10 days away.
How to fix and avoid login expiry (free)
1. Re-authenticate before long jobs: If /status, claude auth status --text, or a startup warning flags an upcoming expiry, run /login before stepping away from your desk. A Remote Control session that outlives the login disconnects until you sign in again.
2. Free up disk space and avoid refresh races: Check df -h ~/.claude and avoid leaving extra idle Claude sessions open that may refresh at the same time.
3. Use a long-lived token in scripts/CI: Run claude setup-token to authorize in the browser and print a 1-year token for CLAUDE_CODE_OAUTH_TOKEN. Claude Code does not save it automatically; treat it like a password and never commit it. While CLAUDE_CODE_OAUTH_TOKEN stays exported in your shell profile or settings, new sessions keep using it instead of /login until you unset it.
4. Alert yourself when auth fails (StopFailure hook): When a turn stops on an API error, Claude Code runs StopFailure with error values like authentication_failed, oauth_org_not_allowed, or account_on_hold. Add this to ~/.claude/settings.json:
{
"hooks": {
"StopFailure": [
{
"matcher": "authentication_failed|oauth_org_not_allowed|account_on_hold",
"hooks": [
{
"type": "command",
"command": "osascript -e 'display notification \"Check Claude Code auth\" with title \"Claude Code auth stopped\"'"
}
]
}
]
}
}(Run the osascript command once in Terminal first to grant macOS notification permission.) To also ping your phone, replace only the "command" line inside the "StopFailure" object above with the line below (swap in your own hard-to-guess topic name):
"command": "osascript -e 'display notification \"Check Claude Code auth\" with title \"Claude Code auth stopped\"'; curl -fsS -d 'Claude Code auth stopped' https://ntfy.sh/YOUR_RANDOM_TOPIC"Keep in mind that ntfy.sh push bodies are sent in plaintext (not end-to-end encrypted), and anyone who knows the topic name can read or publish to it. Treat the topic name like a secret and never include code or credentials in the message. Even with alerts set up, you'll still need to run /login (or resolve org/account holds) yourself.
2. "API Error: Your computer went to sleep mid-response" — what happens on wake
When macOS sleeps while a response is streaming, Claude Code treats the connection as broken on wake:
If Claude already completed text or a tool call: It keeps the completed blocks, drops the interrupted final block, and prints API Error: Your computer went to sleep mid-response. The response above may be incomplete. It won't blindly re-send the turn, so tools don't run twice.
If nothing completed yet: It retries automatically (Connection lost while your computer was asleep), or retries up to twice in quick succession once thinking finishes before stopping with Your computer went to sleep before a response was produced.
In -p, SDK, cloud, or subagent runs: For text-only cut-offs, Claude Code tries automatic continuations first and shows the notice only after those run out.
Repeated sleep/wake cycles overnight can also waste tokens: one open user report (anthropics/claude-code#102780, v2.1.300) describes macOS entering idle sleep roughly every 15 minutes during an overnight background run, with mid-response cut-offs triggering repeated uncached full-context re-sends.
Stopping sleep for free (and alternatives compared)
1. Resume your current turn: Check the completed blocks on screen and reply continue (or resume the session and send continue after a -p run).
2. Keep the lid open (safest for thermals): Turn on Prevent automatic sleeping on power adapter when the display is off in System Settings › Battery › Options. For a single run, wrap claude directly in caffeinate or attach to an existing PID safely:
# Preferred when starting a new run (exits cleanly when claude exits)
caffeinate -i claude
# Or attach to a running native claude binary and blank the screen
# (if installed via npm or running multiple sessions, pick the exact PID from `LC_ALL=C pgrep -fl claude`)
PID=$(pgrep -nx claude)
if [ -n "$PID" ]; then
caffeinate -i -w "$PID" &
pmset displaysleepnow
else
echo "No matching native claude process found; check LC_ALL=C pgrep -fl claude"
ficaffeinate -i blocks idle sleep only; -s blocks system sleep only on AC power, and neither promises closed-lid operation without an external display.
3. Keep the lid closed with no external monitor (free tools): Keepresso (free, GPL-3.0, Apple-notarized, macOS 14+ Intel/Apple Silicon: 10+ agents, MCP, closed-lid fan floor) · Agent Session Pilot (free, MIT, Apple-notarized, macOS 14+ Apple Silicon: Claude/Codex hooks, network-drop resume, own Telegram bot) · AfterLid (closed-source; free Always On closed-lid + native iOS / Android beta read-only status & 1 provider usage; Pro subscription adds remote approvals/replies via account & server-masked relay — Pro price & macOS version unstated) · Amphetamine (free Mac App Store, Intel/Apple Silicon; Apple Silicon uses MIT companion Power Protect) · Agent Awake (freeware, license unstated, macOS 14+ Apple Silicon/Intel with Intel untested, unnotarized, 5-min offline sleep) · Adrafinil (free, MIT, macOS 26.4+, 11 agent hooks + thermal cutout) · Insomnia (krishhgg/Insomnia, free, MIT, macOS 26+, timed mode + 1-min recovery, experimental).
Paid alternatives to compare:
• Lidwork ($9.99 one-time on Mac App Store, macOS 14+ Apple Silicon, no admin password, sandboxed + 30s watchdog).
• Clamshell ($9.99 for 1 Mac / $19.99 for 3 Macs, macOS 14+ Apple Silicon, Setapp/Homebrew cask, Sleep Until Reset, no helper/password stated).
• Agent Caffeine ($9 launch / $14 regular for 1 Mac, 1 yr updates, macOS 13+ Intel/Apple Silicon, 40+ agents + MCP).
• LidRun (free lid-open; Pro $9.90–$19.90, macOS 13+ Intel/Apple Silicon).
Apple's thermal guide (102336) specifies 10–35°C (50–95°F) on a hard, ventilated surface — never run a closed MacBook in a backpack. If you test manual sudo pmset -a disablesleep 1 (not documented in man pmset; see also my earlier pmset wrapper notes), run sudo pmset -a disablesleep 0 and confirm pmset -g | grep SleepDisabled returns 0 before packing your Mac.
One optional menu-bar app: Lidnight (mine)
Lidnight (lid + night) is the macOS menu bar app I build. If a StopFailure hook plus Keepresso, Agent Session Pilot, or Adrafinil already covers your alerting and sleep needs, stick with them — you don't need to pay for another app.
Trade-offs first:
• Closed-source, paid Pro tier, Apple Silicon only (macOS 13+): Intel Macs are covered by Keepresso, Amphetamine, LidRun, and Agent Caffeine (plus Agent Awake, Intel untested). Lidnight has 0 public reviews and ships via its own public Homebrew tap (not official homebrew-cask).
• One-time admin helper & missing features: Closed-lid sleep, battery power modes, SMC fan control, and helper removal require a one-time admin password prompt (open-lid mode needs none; no-admin alternatives include Lidwork via App Sandbox and Clamshell per vendor claim). It also lacks a native iOS/Android app (unlike AfterLid; Lidnight uses /remote/ in your mobile browser), an AC-only toggle, a lid-close chime, an MCP server, and a temperature-independent closed-lid fan floor (unlike Keepresso; Pro uses temperature-triggered SMC fan curves and Max 100% instead).
What it covers for these two errors (Apple-notarized, macOS 13+ Apple Silicon):
• Auth-stop alerts (free on Mac, Pro on phone): Sets up StopFailure (authentication_failed, oauth_org_not_allowed, account_on_hold, verification_required, plus /login and 401 transcript fallbacks) to show "Stopped, signed out" with claude auth login, separate from usage limits. You'll still need to sign in yourself.
• Phone alert privacy note (Pro): Pushes metadata via unencrypted ntfy.sh; approval alerts never include command text, though an off-by-default setting ("Content in phone alerts") includes each finished task's result line and in-progress ask line in completion alerts as plaintext (separate from /remote/).
• Sleep prevention: Open-lid keep-awake (manual, AI Auto, or ≤1h timers) is free. Pro adds closed-lid cutoffs (10m auto-sleep, 8h cap, 10% battery floor, 42°C/60s warning and 45°C sleep SMC battery thermal cutoffs on battery, and AC critical thermal stop) plus lid-open recaps for 10+ min runs.

Pro is $9.99 USD (1 Mac) or $14.99 USD (3 Macs) one-time (includes 1.x updates and a 14-day no-questions-asked refund; local tax is added by Creem at checkout). The free trial lasts 14 days or 5 lid-closed runs of 10+ minutes, whichever comes first, with no card or account required.
Early-user launch batch: Use code SADEN2FREE at checkout (or open the auto-applied checkout link) for a free 1-Mac Lidnight 1.x Pro license (regular $9.99 USD → $0, no card needed, capped at 40 total redemptions across all customers, expires end of 2027-01-04 UTC; 3-Mac licenses remain $14.99 USD).
Link: Lidnight (15.7 MB DMG) · Security & privacy · brew install whereisdw/tap/lidnight (closed-lid requires Pro or the free trial, plus a one-time admin password). Related guides: login expired overnight · computer went to sleep mid-response.
Sources verified (2026-12-05)
Claude Code docs: Error reference · Authentication · Hooks (StopFailure) · anthropics/claude-code#102780.
Apple & macOS: Acceptable operating temperatures (102336) · Change Battery settings on Mac · macOS man pages caffeinate(8), pmset(1) (verified locally).
Free & open-source tools: Keepresso (GitHub, GPL-3.0) · Agent Session Pilot (MIT) · Amphetamine (Power Protect) · Agent Awake · Adrafinil (MIT) · Insomnia (MIT).
Paid & compared apps: Lidwork · Clamshell · Agent Caffeine · LidRun · AfterLid · Lidnight.
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.