Skip to content

[BUG] /usage hangs indefinitely after OAuth token expires (idle session) #41955

Closed as not planned

Description

@digitalby

Description

When Claude Code has been running for an extended period (e.g. left open overnight while waiting on token limits), the OAuth session token expires. After returning to the terminal, typing /usage results in an indefinite "Loading..." spinner — the command never resolves and provides no error or recovery path.

The workaround is to send any trivial prompt (e.g. "say hello"), which triggers a real completion request, implicitly refreshes the expired token, and restores the session. Subsequent /usage invocations then work correctly.

This implies that /usage does not go through the same token-refresh path used by the completions API. Since /usage contacts the Anthropic servers to fetch usage data, it should be able to trigger the same re-authentication flow — or at minimum, fail with a clear actionable error rather than hanging.

Steps to Reproduce

  1. Start a Claude Code session and authenticate normally.
  2. Leave the process running without sending any prompts for several hours (long enough for the OAuth token to expire — typically 4–8 hours).
  3. Return to the terminal and type /usage.

Expected Behavior

One of:

  • /usage proactively checks token expiry, refreshes the token, then fetches and displays usage data.
  • /usage detects the expired token, surfaces a clear message such as: "Session expired. Send any prompt or run /login to re-authenticate." (this would require manual re-auth though - which is annoying if done manually)

The current silent outcome is not acceptable.

Actual Behavior

The /usage command displays "Loading..." and never resolves. No timeout, no error message, no recovery path is shown. The only way to recover is to send a regular prompt, which implicitly refreshes the token as a side effect.

Environment

  • Platform: macOS
  • Shell: zsh
  • Trigger: OAuth token expiry after idle session (no prompts sent)

Related Issues

Both prior issues are closed. This report adds a concrete reproduction path and a specific diagnosis: the /usage handler does not participate in the session's token-refresh lifecycle.

Proposed Fix (Sketch)

The usage fetch should go through the same authenticated HTTP client / token-refresh middleware used by the completions path. At minimum:

  1. Before making the usage API request, check whether the current token is expired and refresh it using the stored refresh token — mirroring what a regular prompt triggers implicitly.
  2. If refresh fails (no refresh token, network error), surface a clear error message rather than hanging indefinitely.
  3. Add a timeout + error boundary to the usage fetch so it cannot hang regardless of auth state. A 10–15 second timeout with a user-visible error is far better than an indefinite spinner.

The same pattern should apply to any other slash command that makes network requests (e.g. /status, /login polling).

Activity

  1. xbzzoo commented on Apr 1, 2026

    @xbzzoo
  2. darius-v commented on Apr 22, 2026

    @darius-v

    and when I asked it simple question "why it shows loading usage data when i type /usage but still does not load for long? " then ran /usage - I see 4 % used. Very much. Cause it went from zero, I just was doing this after I wake up in the morning, without doing other prompts yet

  3. added
    stale
    on May 13, 2026
  4. github-actions commented on May 27, 2026

    @github-actions

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

  5. github-actions commented on Jul 25, 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 25, 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

    stale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions