Skip to content

CLI auto-logout after ~8h idle: expired access token not silently refreshed via refresh token #60503

Closed as duplicate

Description

@larrymanloklai

Summary

When a Claude Code CLI session is left idle for ~8 hours, the access token expires and the session requires a manual /login — even though a valid refreshToken is present in ~/.claude/.credentials.json. The CLI does not proactively (or lazily on next use) refresh the token silently.

Steps to Reproduce

  1. Log in to Claude Code CLI (/login)
  2. Leave the session idle (no API calls) for ~8 hours
  3. Return to the session and attempt to use it
  4. CLI prompts for re-login despite a valid refresh token being stored

Expected Behavior

When the access token is expired but a valid refreshToken exists in credentials, Claude Code should silently exchange it for a new access token without requiring the user to manually /login.

Actual Behavior

The session appears "logged out". The user must run /login again to continue.

Environment

  • Platform: Linux (Ubuntu)
  • Shell: bash
  • Claude Code CLI

Additional Context

Inspecting ~/.claude/.credentials.json, the credentials object contains:

  • accessToken — short-lived (~8 hour TTL based on expiresAt)
  • refreshToken — long-lived
  • expiresAt — Unix timestamp in milliseconds

The access token TTL of ~8 hours is reasonable for security, but the UX should be transparent: the refresh token should be used automatically so users are not forced to re-authenticate on every session that spans more than 8 hours.

This is especially disruptive when:

  • A login session is idle while another tool (e.g. Codex) is actively running in a separate session using the same credentials
  • The user returns to the original session after the TTL window and finds it requires re-login

Suggested Fix

Before making any API call (or on CLI startup), check if expiresAt is within a threshold (e.g. < 5 minutes remaining or already expired). If so, use the refreshToken to silently obtain a new accessToken and update ~/.claude/.credentials.json — without interrupting the user.

Activity

  1. added
    bug
    platform:linux
    on May 19, 2026
  2. github-actions commented on May 19, 2026

    @github-actions

    Found 2 possible duplicate issues:

    1. [BUG] OAuth token expiration disrupts autonomous workflows – refresh token handling needed #12447
    2. [BUG] Forced to Reauth after sleep #59937

    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

  3. github-actions commented on May 23, 2026

    @github-actions

    This issue has been automatically closed as a duplicate of #12447.

    If this is incorrect, please re-open this issue or create a new one.

    🤖 Generated with Claude Code

  4. added
    duplicate
    and removed
    bug
    platform:linux
    on May 23, 2026
  5. github-actions commented on Jul 13, 2026

    @github-actions

    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.

  6. locked as resolved and limited conversation to collaborators on Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions