OAuth token not persisted/refreshed for --print mode, breaks automation

Status Closed — not planned
Maintainer reply None cached
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:

  1. The .credentials.json file gets wiped (all fields become null/empty strings)
  2. claude --print returns "Not logged in · Please run /login"
  3. There is no refreshToken stored, so automatic refresh is impossible
  4. An interactive claude session 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 refresh command for automation use cases

Environment

  • Claude Code v2.1.81
  • Windows 11
  • Auth type: claudeAiOauth
  • Usage: Paperclip AI spawns claude --print --dangerously-skip-permissions as agent workers

Impact

This makes 24/7 autonomous operation impossible. Every ~8 hours, all automation stops and requires manual /login intervention.

Reproduction Steps

  1. Run claude and /login to authenticate
  2. Use claude --print -p "echo ok" - works
  3. Wait ~8 hours for token to expire
  4. claude --print -p "echo ok" → "Not logged in"
  5. Check ~/.claude/.credentials.json → all fields are null/empty

View original on GitHub ↗

13 Comments

github-actions[bot] · 5 months ago

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/31095
  2. https://github.com/anthropics/claude-code/issues/29896
  3. https://github.com/anthropics/claude-code/issues/28827

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

honzastim · 5 months ago

This is a new bug. Today my workers got the same login error after just 1 hour. Unbelievable.

honzastim · 5 months ago

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:

  • We run 4 Claude Code workers via Paperclip AI (agent orchestration platform)
  • Every time the token expires, ALL workers fail simultaneously
  • The .credentials.json file gets completely wiped (all fields null/empty)
  • There is NO refresh token stored, so no automatic recovery is possible
  • We have to manually run /login every few hours, which defeats the purpose of automation
  • We're paying for Claude Code Pro but can't use it for its primary use case

Evidence from today (2026-03-22):

  • Login at ~11:00 → Token expired by ~12:11 (just over 1 hour!)
  • Multiple worker runs failed with "Not logged in · Please run /login"
  • All 4 workers producing identical "claude_auth_required" errors
  • Screenshot shows 15+ consecutive failed runs

What we need:

  1. Immediate: claude --print should auto-refresh tokens using OAuth refresh_token
  2. Short-term: claude auth refresh CLI command for automation
  3. Minimum: Store the refresh_token in .credentials.json so we can refresh manually

This 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

honzastim · 5 months ago

Second Escalation — Token now expires every 10-15 MINUTES

This is getting exponentially worse. Since my last comment 2 hours ago:

  • Token expired 3 more times within a single work session
  • Token lifetime has degraded from ~8 hours (yesterday) → ~1 hour (this morning) → ~10-15 minutes now
  • Each time requires manual /login with browser OAuth flow
  • Zero automation is possible — workers die within minutes of spawning

Timeline today (2026-03-22):

11:03 - /login → workers start
11:45 - token expired, workers dead
12:38 - /login → workers start  
12:50 - token expired again
15:06 - /login → task created
15:13 - token expired, worker produced garbage result
17:10 - /login → workers triggered
17:30 - token expired AGAIN
17:45 - /login
17:55 - expired within 10 minutes

That's 6+ forced re-logins in one day, with token lifetime shrinking each time.

What's happening technically:

  • ~/.claude/.credentials.json gets wiped (all fields become null/empty)
  • No refreshToken is stored — ever
  • Interactive session (this one) keeps working with in-memory token
  • But claude --print (headless/automation mode) immediately fails
  • Paperclip AI (agent orchestrator) spawns claude --print workers that die instantly

Business impact:

  • We're paying for Claude Code Max ($100/mo) specifically for automation
  • We have 4 Claude workers + Paperclip AI orchestrating 12 agents
  • The entire autonomous operation pipeline is completely broken
  • We cannot deliver on any tasks because workers keep dying
  • This is now a subscription-threatening issue — we cannot justify paying for a tool that requires manual intervention every 15 minutes

What we need (urgently):

  1. Fix the token refresh mechanism for --print mode
  2. Or at minimum: make the token lifetime reasonable (24h+)
  3. Ideally: claude auth refresh command for automation

This is not a feature request. This is a critical regression that makes Claude Code unusable for its advertised use case.

honzastim · 5 months ago

Third escalation — 7th forced re-login today, token lasted less than 5 minutes this time

Just did /login again. 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

honzastim · 5 months ago

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:

  • Session started ~20:30 UTC
  • Multiple successful tool calls (Bash, Read, Glob, curl commands)
  • Token expired at ~20:45 UTC — 15 minutes into session
  • Error: API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth authentication is currently not supported."}}
  • Required manual /login to restore

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

honzastim · 5 months ago

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:

  • 20:30 — session start
  • 20:45 — 1st expiry (reported in previous comment)
  • 20:50 — 2nd expiry (after /login restore)
  • 20:55 — 3rd expiry (after another /login restore)

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.

honzastim · 5 months ago

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:

  1. 20:30 — session start
  2. 20:45 — 1st expiry (~15 min)
  3. 20:50 — 2nd expiry (~5 min after re-login)
  4. 20:55 — 3rd expiry (~5 min after re-login)
  5. 21:00 — 4th expiry (~5 min after re-login)

The intervals are SHRINKING. First was 15 min, now it's consistently ~5 min. Each /login restores 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.

honzastim · 5 months ago

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.

honzastim · 5 months ago

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 /login twice just to start the morning.

Overnight impact:

  • NightWatch monitoring daemon ran but couldn't restart workers when needed
  • All Phoenix AI workers (autonomous coding agents) stayed dead since ~21:00 UTC yesterday
  • The only reason trading continued is because trading bots are independent Python processes — NOT because Claude Code was functional

Session count since yesterday: 6+ forced /login re-authentications in ~10 hours. The token never survived more than 15 minutes.

This is day 2 of this regression. Any ETA on a fix?

honzastim · 5 months ago

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 --print workers 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:

  • Token expires or gets wiped during concurrent --print usage
  • .credentials.json fields become null/empty
  • All workers die simultaneously
  • Only manual /login fixes it

Root cause confirmed

This matches the deep source analysis by @LARIkoz in #24317:

  1. The proper-lockfile in v2.1.81 has only 5 retries with ~7.5s max wait — insufficient for 3+ concurrent processes
  2. The 5-second Keychain cache TTL creates stale token windows
  3. No Windows Credential Manager integration — Windows doesn't have macOS Keychain, so file-based .credentials.json is the only storage, making the race condition worse

What we need (from a paying Max subscriber running production automation)

  1. Immediate: Increase lock retry budget to 15-20 retries with exponential backoff (currently 5 retries)
  2. Short-term: claude auth refresh CLI command for automation pre-warming
  3. Medium-term: Token broker pattern (single daemon manages credentials, like gcloud auth)
  4. Alternative: Support ANTHROPIC_API_KEY within subscription billing (not separate API billing)

Our workaround attempts

  • We cannot use the CLAUDE_CODE_OAUTH_TOKEN workaround (blocked server-side since Feb 2026)
  • We cannot use tmux isolation (Windows)
  • Pre-warming tokens before batch doesn't help — workers run 24/7, not in batches
  • The only option is manual /login every few hours, which defeats autonomous operation

This 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

github-actions[bot] · 4 months ago

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

github-actions[bot] · 4 months ago

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.