claude-code - 💡(How to fix) Fix OAuth token expires frequently despite refresh_token present [2 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#47837Fetched 2026-04-15 06:40:56
View on GitHub
Comments
2
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×3commented ×2closed ×1

Authentication drops multiple times per day. ~/.claude/.credentials.json contains a refreshToken but it doesn't auto-refresh. Requires manual /login each time.

Started happening recently. Running /login in one session fixes all sessions (they share the same credentials file).

Root Cause

Authentication drops multiple times per day. ~/.claude/.credentials.json contains a refreshToken but it doesn't auto-refresh. Requires manual /login each time.

Started happening recently. Running /login in one session fixes all sessions (they share the same credentials file).

RAW_BUFFERClick to expand / collapse

Description

Authentication drops multiple times per day. ~/.claude/.credentials.json contains a refreshToken but it doesn't auto-refresh. Requires manual /login each time.

Started happening recently. Running /login in one session fixes all sessions (they share the same credentials file).

Environment

  • Claude Code version: 2.1.92 (native installer)
  • OS: Ubuntu Linux (VPS)
  • Auth method: OAuth (Max $200 plan)
  • Setup: Multiple tmux sessions with Claude Code running, sharing the same credentials file

Steps to reproduce

  1. /login in one session
  2. Run Claude Code in multiple tmux sessions
  3. After some hours all sessions lose auth simultaneously

What Should Happen?

Token should auto-refresh using the stored refreshToken without requiring manual /login. Sessions should stay authenticated indefinitely.

What Actually Happens?

Token expires silently, all sessions stop working until manual /login.

extent analysis

TL;DR

The issue can be mitigated by implementing a periodic token refresh mechanism using the refreshToken stored in ~/.claude/.credentials.json.

Guidance

  • Investigate the authentication library or module used by Claude Code to understand how token refresh is handled, as the current implementation seems to not utilize the refreshToken correctly.
  • Consider adding a scheduled task or a background process that periodically checks the token expiration and refreshes it using the refreshToken before it expires.
  • Review the OAuth implementation, specifically the token expiration and refresh logic, to ensure it aligns with the expected behavior of auto-refreshing tokens.
  • Verify that the refreshToken is correctly stored and retrieved from ~/.claude/.credentials.json across all tmux sessions.

Example

import json
import time
from datetime import datetime, timedelta

# Load credentials
with open('~/.claude/.credentials.json') as f:
    credentials = json.load(f)

# Assume token_expires_at is stored or can be calculated
token_expires_at = credentials.get('token_expires_at')

# Periodic refresh logic (simplified example)
def refresh_token():
    # Logic to refresh token using refreshToken
    pass

def check_and_refresh_token():
    if token_expires_at - datetime.now() < timedelta(hours=1):  # Refresh 1 hour before expiration
        refresh_token()

# Run check_and_refresh_token periodically (e.g., every 30 minutes)

Notes

The provided solution assumes that the refreshToken is correctly stored and that the issue lies in the implementation of the token refresh mechanism. The actual implementation details may vary based on the specific authentication library or framework used by Claude Code.

Recommendation

Apply workaround: Implement a periodic token refresh mechanism as described, to mitigate the authentication drop issue until a more permanent fix can be applied to the underlying authentication logic.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix OAuth token expires frequently despite refresh_token present [2 comments, 2 participants]