Compaction cascade loop when spawning many parallel subagents via Task tool
Summary
Spawning a large number of parallel subagents (10-15+) via the Task tool can trigger an unrecoverable compaction cascade. The parent session's context fills rapidly from subagent return values, triggering compaction. But compaction fires session_start internally, which adds overhead back to the context, which triggers more compaction — creating a feedback loop the session cannot escape.
Steps to Reproduce
- Start a Claude Code session with several MCP servers configured (adds to base context size)
- Dispatch 10-15 parallel subagents via the Task tool in a single message
- Crucially, each subagent should do substantial work and write detailed summaries back to the parent (e.g., research tasks that return multi-paragraph findings, code exploration that returns file contents and analysis). The large return payloads are what overwhelm the parent context.
- As subagents complete and return results, the parent context grows rapidly
- Compaction triggers, but the post-compaction state plus incoming subagent results immediately re-fills context
- Session becomes unresponsive — compaction keeps firing but can't recover enough space
Expected Behavior
The session should gracefully handle the context pressure — either by queuing subagent results, compacting more aggressively, truncating excessively large subagent returns, or warning the user before accepting that many parallel dispatches.
Actual Behavior
The session enters a compaction loop and becomes unrecoverable. The only option is to kill the session, losing all in-progress subagent work and parent context.
Environment
- macOS Darwin 25.2.0
- Claude Code (observed across multiple recent versions)
- Opus 4.6
Notes
Related to #24591 (compaction + subagents) and #26575 (unrecoverable compaction states), but the specific trigger here is the volume of parallel Task tool dispatches — each returning substantial content — overwhelming the parent context faster than compaction can recover it.
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗