Skip to content

Guard against claude -p hanging when auth is expired #58

Description

@macroclaw-bot

Problem

When Claude Code's OAuth session expires and claude -p is invoked, it hangs indefinitely retrying authentication instead of failing fast. This blocks macroclaw completely — the user gets no response and no error.

Proposed solution

Run claude auth status as a parallel guard alongside each claude -p invocation:

  1. Start both in parallel: spawn claude -p <prompt> and claude auth status concurrently
  2. If auth status fails (non-zero exit), kill the claude -p process and report to the user immediately (e.g. "Claude auth expired — run /login to re-authenticate")
  3. If auth status succeeds, let claude -p continue normally (discard the auth check result)

This avoids the overhead of a blocking pre-check on every request while still catching expired auth quickly. The auth check is fast (~1-2s) so it will resolve well before a hanging claude -p would time out.

Alternatives considered

  • Pre-check before every request: adds latency to every invocation even when auth is fine
  • Timeout then check: slower to detect the issue — user waits for the timeout before getting feedback
  • ANTHROPIC_API_KEY env var: bypasses OAuth entirely but requires managing API keys separately

Additional context

  • claude -p hanging on expired auth has no built-in CLI fix (no --no-retry flag exists)
  • The subprocess stdin hanging bug was fixed in v2.1.79, but auth retry hanging is a separate issue

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions