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).

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 claude 

Inside 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 login stops mid-run

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 it (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 Claude Code does 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

  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" fi 

caffeinate -i blocks idle sleep only; -s blocks system sleep only on AC power, and neither promises closed-lid operation without an external display.

  1. Keep the lid closed with no external monitor:
    • 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) and 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)

If a StopFailure hook plus Keepresso, Agent Session Pilot, or Adrafinil already works for you, stick with them.

Trade-offs first:

  • Closed-source & Apple Silicon only (macOS 13+): Paid Pro, 0 public reviews, own public Homebrew tap (not homebrew-cask). Intel Macs: Keepresso, Amphetamine, LidRun, Agent Caffeine (or Agent Awake, Intel untested).
  • 1x admin helper & missing features: Closed-lid sleep, battery modes, SMC fan control, and helper removal need a 1x admin password (open-lid needs none; no-admin options: Lidwork sandbox, Clamshell vendor claim). No native mobile app (uses browser /remote/), AC-only toggle, lid-close chime, MCP server, or temp-independent fan floor (uses temp-triggered SMC curves + Max 100%).

Coverage for these two errors (Apple-notarized):

  • Auth-stop alerts (free Mac / Pro phone): Configures 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; manual sign-in still required). Pro pushes metadata over unencrypted ntfy.sh (approvals omit commands; off-by-default "Content in phone alerts" sends result/ask lines in 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 limit, 10% battery floor, 42°C/60s warn & 45°C sleep SMC battery temp on battery, AC critical thermal stop) and 10+ min lid-open recaps.

Pro: $9.99 USD (1 Mac) / $14.99 USD (3 Macs) one-time (1.x updates, 14-day refund; Creem adds local tax). Free trial: 14 days or 5 closed-lid runs of 10+ min (whichever comes first), no card/account. Early-user batch: SADEN2FREE (auto-applied checkout) gives 1-Mac 1.x Pro ($9.99 USD → $0, no card, capped at 40 total redemptions across all customers, expires end of 2027-01-04 UTC; 3-Mac remains $14.99 USD).

Lidnight (15.6 MB DMG) or brew install whereisdw/tap/lidnight (closed-lid requires Pro/trial + 1x admin password).

Sources verified (2026-12-05)