Babysit agents stop with 'socket connection closed unexpectedly' API error

Open 💬 1 comment Opened Jun 3, 2026 by sheldon

Summary

When running Claude Code in agents mode (babysit agents), sessions regularly terminate with the following error:

API Error: The socket connection was closed unexpectedly. For more information, pass `verbose: true` in the second argument to fetch()

This causes the babysit agent to stop entirely rather than retrying or recovering.

Steps to Reproduce

  1. Run Claude Code in agents mode (babysit agents)
  2. Wait for the agent to be mid-task
  3. Observe the session terminate with the above error

Expected Behavior

The agent should either:

  • Retry the request automatically after a socket close, or
  • Surface a more actionable error and resume/restart gracefully

Actual Behavior

The agent stops with the above error and does not recover. The babysit session is lost.

Environment

  • Platform: macOS (darwin)
  • Shell: zsh
  • Claude Code version: (latest)

Additional Context

This appears to be a transient network-level disconnect (TCP socket closure) that is not being handled with retry logic. The error message suggests that setting verbose: true would show more detail, but end-users running babysit agents have no natural place to pass that option.

Suggested improvements:

  • Automatic retry with backoff on socket-level disconnects
  • Clearer error message indicating whether the agent's state was preserved
  • Option to resume/restart the agent from where it left off after a reconnect

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗