[BUG] Subagent infinite loop with no max_turns produces 153GB output file

Resolved 💬 3 comments Opened Feb 24, 2026 by braunshedd Closed Feb 27, 2026

Preflight Checklist

  • [x] I have searched for existing issues and this hasn't been reported
  • [x] This is a single bug report (not multiple bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

A background subagent (Task tool, subagent_type=Explore, model=Haiku) entered an infinite loop during a code exploration task. Without any max_turns limit set, the agent ran unchecked and produced a 153GB JSONL output file containing 65.6 million lines before the session was eventually killed.

Impact

  • Disk: 153GB consumed in /private/tmp/claude-501/ from a single task output file
  • Tokens: Millions of API round-trips with growing context windows, likely significant token/credit waste
  • No warning: No circuit breaker, no disk usage alert, no turn limit, no automatic termination

What Should Happen?

At minimum, one or more of:

  1. Default max_turns cap — subagents should have a sensible default turn limit (e.g., 100-200) even when the caller doesn't specify one
  2. Output file size limit — stop the agent if its output file exceeds some threshold (e.g., 1GB)
  3. Runaway loop detection — detect when an agent is repeating the same tool calls in a cycle and terminate it
  4. Disk usage monitoring — warn or halt when temp directory usage is excessive

Steps to Reproduce

  1. Spawn a background Task agent (e.g., subagent_type: "Explore") without setting max_turns
  2. The agent enters a read/glob loop (reading files, globbing for more, reading again)
  3. The output file grows unboundedly — each JSONL line includes the full conversation history, so file size compounds exponentially
  4. Nothing stops it

Observed Details

  • Agent ID: ab622460850478f01
  • Output file: /private/tmp/claude-501/.../tasks/b0db359.output
  • File size: 153GB (65,635,654 lines)
  • File type: UTF-8 JSONL (conversation transcript)
  • The agent was running Haiku on a code exploration task

Is this a regression?

I don't know

Claude Code Version

2.1.52 (Claude Code)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

VS Code integrated terminal

Claude Model

claude-haiku-4-5-20251001 (subagent), claude-opus-4-6 (parent)

Additional Information

The subagent was spawned by the parent agent during a code exploration task on a Kotlin backend project. The output file was located at /private/tmp/claude-501/-Users-braunshedd-Desktop-danielle-docxil-goldens-Backend/tasks/b0db359.output. The file was pure JSONL conversation transcript — each line included the full growing conversation history, causing exponential file size growth.

View original on GitHub ↗

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