Uncontrolled background agent parallelization causes context overflow, session death, and wasted tokens
Resolved 💬 7 comments Opened Feb 14, 2026 by xraysoft Closed Apr 23, 2026
Bug Report: Uncontrolled background agent parallelization causes context overflow, session death, and wasted tokens
Environment
- Claude Code version: v2.1.39
- Model: Opus 4.6 (Claude Max subscription)
- OS: Windows 11 Pro 10.0.26200
- Date: 2026-02-14
Summary
When Claude Code launches many background agents (Task tool with run_in_background: true) in parallel, the returning results can overflow the context window. This kills the session with no recovery path, and the user pays for all tokens consumed by the agents — even though the results were never usable.
Steps to Reproduce
- Start a Claude Code session and work on several tasks (building up context)
- Ask Claude to document a large codebase comprehensively ("Document everything — theme, plugins, all files")
- Claude launches 14 background agents (Explore subagent_type) in three waves (6 + 5 + 3)
- All agents run in the background, each consuming tokens independently
- Agents start completing and returning results
- Context window fills up
What Happened
- Claude launched 14 parallel background agents to explore different parts of the codebase
- Each agent consumed significant tokens (e.g., "21 tool uses · 80.8k tokens · 1m 25s" for a single agent)
- As agents completed, each return added to the context
- After ~10 agents returned, the context was full
- Every subsequent agent completion showed:
Context limit reached · /compact or /clear to continue - Running
/compactfailed with:Error: Error during compaction: Error: Conversation too long. Press esc twice to go up a few messages and try again. - Session was completely dead — no further interaction possible
- All tokens consumed by the 14 agents were billed to the user
Expected Behavior
- Context budget awareness: Before launching N background agents, Claude Code should estimate whether the returning results will fit in the remaining context window. If not, it should launch fewer agents or process results incrementally.
- Graceful degradation: When context is approaching limits, agent results should be summarized or truncated rather than causing a hard crash.
- Compaction should always work:
/compactfailing with "Conversation too long" is a dead end. If the conversation is too long, that's exactly when compaction is needed most. This is a catch-22.
- Token accountability: Tokens consumed by agents that cannot return results (because context is full) should not count against the user's quota, or at minimum the system should prevent this scenario.
- Agent launch limits: There should be a configurable or automatic cap on concurrent background agents to prevent context overflow.
Impact
- Token waste: 14 agents × ~50-80k tokens each = significant token consumption with no usable output
- Lost session: User cannot continue working, must start a new session
- Lost context: All prior conversation context (including earlier productive work in the same session) is inaccessible
- User pays for system failure: The user's subscription quota is consumed by Claude's own architectural limitation, not by the user's actions
Workaround
None available. Once the context overflows:
/compactfails/clearloses all context- The only option is to start a new session
Suggested Fixes
- Add a context budget check before launching background agents. Calculate:
remaining_context - (estimated_agent_results × num_agents) > safety_margin - Implement streaming/incremental agent processing — process each agent's result before launching the next, or cap concurrent agents at 3-4
- Fix
/compactfor oversized contexts — compaction should work especially when the context is too long, not fail because of it - Add a background agent limit — either hard cap or configurable setting (e.g.,
max_concurrent_agents: 4) - Implement result truncation — if an agent result would overflow context, summarize it automatically instead of crashing
Session Log
The full session transcript is available showing the exact sequence:
- 6 agents launched → 5 more agents launched → 3 more agents launched
- Agents completing with "Context limit reached" errors
/compactfailure- Session death
Total productive time before crash: ~25 minutes of successful code changes, then ~11 minutes of documentation attempt that killed the session.
This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗