Skip to content

[BUG]Title: claude -p fails with "OAuth session expired and could not be refreshed" while interactive mode works fine #81937

Description

@PridetoPack

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?

Version: Claude Code v2.1.220 (confirmed up to date via claude update)

Environment: macOS, zsh

Description:
Non-interactive (-p / print mode) invocations fail to authenticate, while a normal interactive session in the same terminal, same directory, authenticates successfully.

Steps to reproduce:

Run claude -p "say hello" --permission-mode bypassPermissions
→ Fails immediately with:
Failed to authenticate: OAuth session expired and could not be refreshed
(An earlier attempt returned a slightly different message: Failed to authenticate. API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth access token has been revoked."},"request_id":null})

Run claude (interactive, no -p) in the same terminal, same directory
→ Succeeds immediately, no login prompt needed:
Claude Code v2.1.119
Sonnet 4.6 with high effort · Claude Pro
(Note: interactive banner shows v2.1.119 while claude update reports the installed version as 2.1.220 — possibly related, possibly a red herring.)

Exit the interactive session and retry claude -p ... → same authentication failure persists.
Ran claude update → already up to date (2.1.220). Retried -p again → same failure.
Expected: -p mode should authenticate using the same valid session as interactive mode, since I'm logged in and interactive mode works without any re-login prompt.

Actual: -p mode consistently fails to authenticate, blocking any headless/scripted/cron-based use of Claude Code, while interactive use is unaffected.

What Should Happen?

Expected: -p mode should authenticate using the same valid session as interactive mode, since I'm logged in and interactive mode works without any re-login prompt.

Actual: -p mode consistently fails to authenticate, blocking any headless/scripted/cron-based use of Claude Code, while interactive use is unaffected.

Error Messages/Logs

Failed to authenticate: OAuth session expired and could not be refreshed

Steps to Reproduce

Steps to reproduce:

Run claude -p "say hello" --permission-mode bypassPermissions
→ Fails immediately with:
Failed to authenticate: OAuth session expired and could not be refreshed
(An earlier attempt returned a slightly different message: Failed to authenticate. API Error: 401 {"type":"error","error":{"type":"authentication_error","message":"OAuth access token has been revoked."},"request_id":null})

Run claude (interactive, no -p) in the same terminal, same directory
→ Succeeds immediately, no login prompt needed:
Claude Code v2.1.119
Sonnet 4.6 with high effort · Claude Pro
(Note: interactive banner shows v2.1.119 while claude update reports the installed version as 2.1.220 — possibly related, possibly a red herring.)

Exit the interactive session and retry claude -p ... → same authentication failure persists.
Ran claude update → already up to date (2.1.220). Retried -p again → same failure.

Claude Model

Sonnet (default)

Is this a regression?

No, this never worked

Last Working Version

No response

Claude Code Version

2.1.220

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions