OAuth token not persisted/refreshed for --print mode, breaks automation
Status Closed — not planned
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 13 comments · opened Mar 22, 2026 · closed Apr 21, 2026
Bug Description
When using claude --print in automation (e.g., Paperclip AI agent orchestration), the OAuth token expires after approximately 8 hours. After expiry:
- The
.credentials.jsonfile gets wiped (all fields becomenull/empty strings) claude --printreturns "Not logged in · Please run /login"- There is no
refreshTokenstored, so automatic refresh is impossible - An interactive
claudesession started before expiry continues to work (in-memory token), but any NEW process fails
Expected Behavior
- OAuth refresh token should be stored in
.credentials.json - Token should auto-refresh using the refresh token when it expires
- OR: provide a
claude auth refreshcommand for automation use cases
Environment
- Claude Code v2.1.81
- Windows 11
- Auth type: claudeAiOauth
- Usage: Paperclip AI spawns
claude --print --dangerously-skip-permissionsas agent workers
Impact
This makes 24/7 autonomous operation impossible. Every ~8 hours, all automation stops and requires manual /login intervention.
Reproduction Steps
- Run
claudeand/loginto authenticate - Use
claude --print -p "echo ok"- works - Wait ~8 hours for token to expire
claude --print -p "echo ok"→ "Not logged in"- Check
~/.claude/.credentials.json→ all fields are null/empty
13 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
This is a new bug. Today my workers got the same login error after just 1 hour. Unbelievable.
Escalation — This is getting worse and makes Claude Code unusable for automation
Update: This issue is now occurring multiple times per day, not just every 8 hours. The token seems to expire even more frequently now.
Real-world impact:
.credentials.jsonfile gets completely wiped (all fields null/empty)/loginevery few hours, which defeats the purpose of automationEvidence from today (2026-03-22):
What we need:
claude --printshould auto-refresh tokens using OAuth refresh_tokenclaude auth refreshCLI command for automation.credentials.jsonso we can refresh manuallyThis is a critical blocker for any production use of Claude Code in automation. Without a fix, we'll need to discontinue our subscription as the product is unusable for 24/7 operations.
/cc @anthropics/claude-code-team
Second Escalation — Token now expires every 10-15 MINUTES
This is getting exponentially worse. Since my last comment 2 hours ago:
/loginwith browser OAuth flowTimeline today (2026-03-22):
That's 6+ forced re-logins in one day, with token lifetime shrinking each time.
What's happening technically:
~/.claude/.credentials.jsongets wiped (all fields become null/empty)refreshTokenis stored — everclaude --print(headless/automation mode) immediately failsclaude --printworkers that die instantlyBusiness impact:
What we need (urgently):
--printmodeclaude auth refreshcommand for automationThis is not a feature request. This is a critical regression that makes Claude Code unusable for its advertised use case.
Third escalation — 7th forced re-login today, token lasted less than 5 minutes this time
Just did
/loginagain. Token expired before I could even finish reading the previous comment. This is now completely unusable.We are seriously considering canceling our Claude Code Max subscription. We've spent the entire day fighting this bug instead of doing actual work. Not a single task was completed successfully by our automation today because of this.
Please prioritize this. @anthropics/claude-code-team
Another OAuth expiry — 2026-03-22 ~20:45 UTC
Still happening consistently. This time the token expired mid-session while the agent was actively executing commands (last successful bash call returned 200 OK, then immediately got
401 authentication_error: "OAuth authentication is currently not supported").Timeline:
API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth authentication is currently not supported."}}/loginto restoreThis is the same pattern reported in the original issue — tokens expire every 10-15 minutes. This makes autonomous overnight operation impossible. We have trading bots and worker automation that depends on Claude Code sessions staying alive.
Impact: Blocks all Paperclip AI worker automation, overnight monitoring, and autonomous task execution.
Environment: Windows 11 Pro, Claude Code CLI, interactive mode (not just
--print).2x more OAuth expiry in 5 minutes — 2026-03-22 ~20:50-20:55 UTC
This is getting critical. Two more token expirations within a 5-minute window, each requiring manual
/login. The user is trying to set up overnight automation and cannot leave the terminal because tokens keep dying.Session timeline:
/loginrestore)/loginrestore)That's 3 forced logouts in 25 minutes of active usage. Each time the tool was mid-execution (writing files, making API calls) when it died.
This is a severe UX regression. The user literally cannot step away from the keyboard because the session dies every few minutes. Autonomous overnight workflows are completely blocked. This is not an edge case — it's core interactive usage breaking repeatedly.
Error:
API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth authentication is currently not supported."}}Please prioritize this fix. Users running Claude Code for production automation are severely impacted.
4th OAuth expiry in ~30 minutes — 2026-03-22 ~21:00 UTC
This is now the FOURTH forced logout in a single 30-minute session. The token is expiring every 5-8 minutes now (getting worse, not better).
Timeline of this session alone:
The intervals are SHRINKING. First was 15 min, now it's consistently ~5 min. Each
/loginrestores a token that dies almost immediately.The user is unable to perform any meaningful work. Background processes cannot be monitored. Overnight automation is impossible. This is a P0 regression — the product is effectively non-functional for sessions longer than 5 minutes.
Credentials behavior: The credentials file gets wiped (all fields null) with no refresh_token being stored. This suggests the OAuth flow is issuing short-lived access tokens without refresh tokens.
Environment: Windows 11 Pro, Claude Code CLI latest, interactive mode.
cc @anthropics/claude-code-team — this needs urgent attention.
5th OAuth expiry — 2026-03-22 ~21:30 UTC
Token expired AGAIN. 5th time in ~60 minutes. User went to sleep and had to come back to re-login because token died while agent was doing overnight monitoring work.
This is completely unusable for any automation or even extended interactive sessions. Please fix urgently.
Morning update — 2026-03-23: Token expired overnight, zero autonomous work possible
As predicted, the OAuth token expired overnight. The user woke up to dead Claude Code sessions and had to manually
/logintwice just to start the morning.Overnight impact:
Session count since yesterday: 6+ forced
/loginre-authentications in ~10 hours. The token never survived more than 15 minutes.This is day 2 of this regression. Any ETA on a fix?
Update 2026-03-24 — Issue confirmed on v2.1.81, fix from #24317 does NOT resolve this
Environment: Windows 11 Pro, Claude Code v2.1.81, Max plan (20x tier), 3 concurrent claude.exe processes (1 interactive + 2
--printworkers spawned by Paperclip AI / Phoenix)What we observed today
Token is currently valid (8h lifetime, refresh token present). But the pattern from previous days continues:
--printusage.credentials.jsonfields become null/empty/loginfixes itRoot cause confirmed
This matches the deep source analysis by @LARIkoz in #24317:
proper-lockfilein v2.1.81 has only 5 retries with ~7.5s max wait — insufficient for 3+ concurrent processes.credentials.jsonis the only storage, making the race condition worseWhat we need (from a paying Max subscriber running production automation)
claude auth refreshCLI command for automation pre-warminggcloudauth)ANTHROPIC_API_KEYwithin subscription billing (not separate API billing)Our workaround attempts
CLAUDE_CODE_OAUTH_TOKENworkaround (blocked server-side since Feb 2026)tmuxisolation (Windows)/loginevery few hours, which defeats autonomous operationThis is a subscription-threatening blocker. We're paying $100/mo for Max specifically for automation, but the product requires manual intervention every few hours. Please prioritize.
cc @anthropics/claude-code-team
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
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.