Skip to content

Loop dies silently when OAuth token expires in non-interactive mode #199

@awilkening

Description

@awilkening

Description

When using Ralph with Claude Code authenticated via OAuth (e.g., Claude Max subscription), the OAuth access token expires after ~10-15 minutes. Claude Code fails to refresh the token when invoked non-interactively via -p with --output-format stream-json, causing a 401 error that kills the loop.

Ralph treats this as a successful completion (the process exits cleanly with error text in the output), so the loop either stops or moves on without realizing auth failed.

Reproduction

  1. Authenticate Claude Code with claude /login (OAuth)
  2. Start a Ralph loop
  3. After 2-3 loops (~15-20 min), Claude Code returns:
    authentication_error: OAuth token has expired. Please obtain a new token or refresh your existing token.
    
  4. Ralph logs show successful completion, but no actual work was done

Expected behavior

  • Ralph should detect auth failures and either retry after prompting for re-auth, or clearly surface the error as a loop halt reason (not "completed successfully")
  • Ideally, Ralph could detect the authentication_failed error in the stream output and set an appropriate exit reason

Actual behavior

  • The loop appears to complete normally from Ralph's perspective
  • status.json shows "status": "running" / "last_action": "executing" with no indication of auth failure
  • .exit_signals shows no done signals
  • The auth error is only visible buried in the raw stream log

Relevant log output

{"type":"result","subtype":"success","is_error":true,...,"error":"authentication_failed"}

Note "subtype":"success" combined with "is_error":true — Ralph may be keying on subtype and missing the error.

Upstream issue

This is partially a Claude Code bug — the CLI should refresh OAuth tokens in non-interactive mode. Filed upstream: anthropics/claude-code#28827

Environment

  • Ralph version: latest (from ~/.ralph/ralph_loop.sh)
  • Claude Code version: 2.1.59
  • macOS (Darwin 25.2.0)
  • Auth: OAuth (Claude Max subscription)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions