[Bug] Subagents (Agent tool) hit context limit without auto-compact ever triggering
Bug Description
Subagents spawned via the Agent tool (with run_in_background: true) hit "Context limit reached" and terminate without auto-compact ever triggering. The main session receives Context limit reached · /compact or /clear to continue from the subagent, and the subagent's work is lost.
This is distinct from #24591 (compaction fails with subagents) — in this case, compaction never activates at all within the subagent before it dies.
Steps to Reproduce
- Launch 4-5 background subagents in parallel using the
Agenttool withrun_in_background: true - Each subagent performs research-heavy tasks (web searches, file reads, large text generation)
- Wait for subagents to complete
Expected: Each subagent auto-compacts its own context when approaching limits and continues working.
Actual: Multiple subagents hit Context limit reached simultaneously and terminate. The main session displays:
⏺ Agent "task name" completed
⎿ Context limit reached · /compact or /clear to continue
In my case, 4 out of 5 background agents died this way in the same session.
Additional Context
- After this happens, the main session's context is also heavily consumed by the failed subagent results, pushing it near its own limit
/compacton the main session also fails at this point ("Conversation too long"), creating a total deadlock- The only recovery is
/clear, which loses all session state - This effectively makes parallel background agents unreliable for any non-trivial research tasks
Environment Info
- Claude Code version: 2.1.63
- Platform: macOS 26.2 (darwin, arm64)
- Model: claude-opus-4-6
Related Issues
- #24591 — Context compaction fails with multiple subagents (compaction fails; in our case it never triggers)
- #24976 — Context Limit Reached error should auto-compact and queue user message instead of failing
- #26317 — Context compaction fails with 'Conversation too long'
- #23047 — /compact fails with 'Conversation too long'
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗