Agent re-launches failing API scripts without user consent, burning API credits

Resolved 💬 3 comments Opened Mar 30, 2026 by felixwittke-dev Closed Apr 3, 2026

Description

When a background script making Anthropic API calls fails with connection errors, the Claude Code agent (Opus 4.6, 1M context) re-launches the same script multiple times without asking the user — even when each run fails with the identical error.

What happened

  1. User asked the agent to run a test script that calls claude-sonnet-4-20250514 via the Anthropic SDK
  2. Run 1: 3 out of 4 API calls failed with SocketError: other side closed (APIConnectionError)
  3. Instead of reporting the failure and asking the user, the agent:
  • Attempted to "fix" the issue (cleared tsx cache, tried different Node.js invocation)
  • Re-launched the script a 2nd time — same failures
  • Re-launched the script a 3rd time — same failures
  1. Each launch sent ~18,000 input tokens per API call, charged even on socket failures
  2. Total: $1.60 USD in API credits consumed, with only ~$0.10 of useful output

Expected behavior

After the first script run fails with API errors, the agent should:

  1. Report what happened and the error pattern
  2. Stop and ask the user before re-launching
  3. Never assume that cache clearing or invocation changes will fix a server-side API issue

Additional context

  • The user had explicitly instructed the agent in a prior session (2026-03-27) not to retry failing API calls in loops, after a similar incident with 529 errors
  • The user has a Claude Pro Max subscription — Claude Code context costs are covered. The $1.60 is entirely from the user's separate API key, making unauthorized re-runs a direct financial cost
  • The abort-after-2-consecutive-failures safeguard in the script worked correctly each time — but the agent circumvented it by re-launching the script itself

Impact

  • $1.60 in API credits wasted (refund requested separately via Anthropic billing support)
  • User trust eroded — agent ignored explicit prior guidance
  • Pattern: agent prioritizes "solving the problem" over respecting the user's resources

Environment

  • Claude Code with Opus 4.6 (1M context)
  • Platform: WSL2 Linux
  • Script: TypeScript test harness using @anthropic-ai/sdk to call Sonnet

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗