[BUG] macOS sleep/wake causes 401 authentication errors requiring full reboot
Status Closed — not planned
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 9 comments · opened May 18, 2026 · closed Jun 23, 2026
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
After MacBook Pro sleep/wake, Claude Code consistently returns 401 authentication errors. Only full macOS reboot resolves the issue.
Environment:
- macOS (MacBook Pro)
- Claude Code v2.1.142
- This persists despite the v2.1.137 Keychain race condition fix
Steps to Reproduce:
- Use Claude Code normally (works fine)
- Close MacBook Pro lid (sleep)
- Open MacBook Pro (wake)
- Try to use Claude Code → 401 error every time
What I've tried (none work):
- Deleting ~/.claude/.credentials.json and re-login
- macOS logout/login
- Only full macOS REBOOT fixes the issue
This suggests a deeper macOS system-level problem beyond the Keychain race condition fixed in v2.1.137. The securityd service appears to require a full system restart to resynchronize with Claude Code's OAuth tokens after sleep.
What Should Happen?
Sleep/wake cycles should not break Claude Code authentication. Users should be able to close and open their MacBook Pro without requiring a full system reboot.
Error Messages/Logs
API Error: 401 Invalid authentication credentials
Please run /login
Steps to Reproduce
- Use Claude Code normally on macOS (works fine)
- Close MacBook Pro lid to sleep
- Wait (any duration)
- Open MacBook Pro lid (wake from sleep)
- Open Claude Code
- Send any prompt → 401 authentication error occurs
- Try /logout then /login → 401 persists
- Delete ~/.claude/.credentials.json and re-login → 401 persists
- Only full macOS reboot resolves the issue
Claude Model
Sonnet (default)
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
v2.1.142
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_
9 Comments
Found 2 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
This is not a duplicate of #37078 or #48631.
#37078 is about stale connection pools causing ECONNRESET errors.
#48631 is about general 401 errors across all sessions (not sleep-specific).
My issue (#60104) is specifically triggered by macOS sleep/wake cycles and requires a full system reboot to resolve - neither #37078 nor #48631 mention this specific trigger or resolution. This appears to be a distinct macOS securityd synchronization issue that persists even after the v2.1.137 Keychain race condition fix.
Adding my data here. Have been at my wit's end with this for a while.
The sleep/wake pattern in this issue lines up exactly with what I see, and the timing is the giveaway. Here is what my logs show from the most recent occurrence:
StartIntervaltimers do not fire while the Mac is asleep.claude /loginflow.The pattern is consistent across multiple occurrences over the past few weeks. It is not "token aging" in any normal sense, it is that the macOS sleep cycle straddles the access token's lifetime and there is no wake-trigger to attempt a refresh before scripts start failing.
A second issue that compounds it: when I do run
claude /loginto recover, macOS Claude Code writes the new token to Keychain and immediately deletes~/.claude/.credentials.json. Any local script or hook that reads the credentials file (rather than going through the CLI) breaks until something can read Keychain back. SSH sessions cannot read the login Keychain, so remote recovery is also blocked.Workarounds I have tried:
claude /loginbefore bed — works, but only because it gives ~8 hours of access token life and I am usually back at the machine before it expiresWhat would actually fix this for me:
claude auth refreshcommand that uses the refresh token to mint a new access token without the full browser OAuth flowClosing for now — inactive for too long. Please open a new issue if this is still relevant.
Update: Issue confirmed to persist on v2.1.195 after macOS reboot.
After system reboot, authentication is temporarily restored,
but the issue recurs after sleep/wake cycles.
This requires a full system reboot every time, which is not
practical for daily usage.
Requesting escalation to engineering team for a lighter workaround.
CRITICAL: Issue is cumulative, not immediate.
Finding: Sleep/wake cycles do NOT always fail immediately.
This suggests Keychain state degrades progressively with each sleep/wake cycle,
or there's a state that only manifests on the second cycle.
This is NOT a simple "token expired" issue but a state management problem
that worsens with repeated sleep cycles.
Confirmed workaround:
Before sleep:
After sleep:
This prevents Keychain corruption by ensuring Claude Code tabs are closed
before sleep, while maintaining VSCode state.
Trade-off: Requires /resume workflow, but avoids full macOS reboot.
UPDATE: Workaround is NOT reliable.
Testing revealed:
The workaround provides temporary mitigation but does not resolve
the underlying Keychain corruption issue during extended sleep.
Conclusion: This is not a practical long-term solution.
The root cause requires a proper engineering fix from Anthropic.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.