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

Resolved 💬 13 comments Opened Mar 22, 2026 by honzastim 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 ↗

This issue has 13 comments on GitHub. Read the full discussion on GitHub ↗