Skip to content

[BUG] OAuth access token not auto-refreshed on startup — forces re-login after every PC restart #34306

Description

@Jmenfish

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

On Windows 11, Claude Code (VSCode extension) does not automatically refresh the OAuth access token when it has expired. Instead of silently refreshing using the stored refreshToken, it prompts the user to re-authenticate via browser on every session start.

  1. Environment:
    OS: Windows 11 Enterprise
    Claude Code: VSCode extension (v2.1.76)
    Auth method: Claude.ai subscription (OAuth, not API key)

  2. Steps to reproduce:
    Log in via claude login (browser OAuth flow completes successfully)
    Use Claude Code normally
    Wait for the access token to expire (~24h), or restart PC after expiry
    Open VSCode — Claude Code prompts for re-authentication instead of using the refresh token

  3. Expected behavior:
    Claude Code should detect that the accessToken in ~/.claude/.credentials.json is expired and silently use the refreshToken to obtain a new access token — without requiring user interaction.

  4. Actual behavior:
    Claude Code throws a 401 error and forces a full re-login via browser, even though a valid refreshToken is present in ~/.claude/.credentials.json.

  5. Additional context:
    ~/.claude/.credentials.json correctly contains both accessToken, refreshToken, and expiresAt
    No credentials are stored in Windows Credential Manager
    ~/.claude.json contains oauthAccount metadata but no token fields
    The refreshToken is never consumed — it remains unchanged after forced re-login

What Should Happen?

Expected behavior:
Claude Code should detect that the accessToken in ~/.claude/.credentials.json is expired and silently use the refreshToken to obtain a new access token — without requiring user interaction.

Error Messages/Logs

Failed to authenticate. API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth token has expired. Please obtain a new token or refresh your existing token."},"request_id":"req_011....."

Steps to Reproduce

  1. Steps to reproduce:
    Log in via claude login (browser OAuth flow completes successfully)
    Use Claude Code normally
    Wait for the access token to expire (~24h), or restart PC after expiry
    Open VSCode — Claude Code prompts for re-authentication instead of using the refresh token

Claude Model

Sonnet (default)

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

Claude 2.1.76 (VS Code extension)

Platform

Other

Operating System

Windows

Terminal/Shell

VS Code integrated terminal

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions