Compaction triggers too late when calling multiple agents - causes context overflow
Problem
Claude Code's compaction system triggers reactively when context is already near/at limit, rather than proactively at a safe threshold. This causes frequent context overflow errors when multiple agents are invoked.
Current Behavior
- Compaction triggers at ~98-99% context usage
- Multiple agent calls rapidly consume context (each agent can add 10-20k tokens)
- Context exceeds limit before compaction completes
- User sees: Error during compaction: Conversation too long
Expected Behavior
- Compaction should trigger proactively at 80-85% context usage
- Block new agent launches when context > 85% until compaction completes
- Warn user at 75% context with suggestion to compact manually
Reproduction
- Start a conversation with moderate context (60-70%)
- Launch multiple agents in parallel using Task tool
- Context rapidly fills to 100%
- Compaction fails with 'Conversation too long' error
Suggested Fix
typescript
// Proactive compaction thresholds
const COMPACT_TRIGGER_THRESHOLD = 0.85; // 85%
const AGENT_BLOCK_THRESHOLD = 0.90; // 90%
const CRITICAL_THRESHOLD = 0.95; // 95%
// Before launching agents
if (contextUsage > AGENT_BLOCK_THRESHOLD) {
triggerCompaction();
blockAgentLaunch();
}
// Background monitoring
setInterval(() => {
if (contextUsage > COMPACT_TRIGGER_THRESHOLD) {
triggerCompaction();
}
}, 1000);
Workarounds
Until fixed, users can:
- Manually run /compact before launching multiple agents
- Use MCP knowledge-manager to store intermediate results externally
- Run agents sequentially with compaction between each
Environment
- Claude Code version: Latest (as of 2025-11-08)
- Platform: Linux
- Typical context usage: High (multi-agent workflows)
Impact
- Severity: High - blocks common multi-agent workflows
- Frequency: Every session with 2+ parallel agent calls
- User Experience: Frustrating, requires manual intervention
Priority
This affects core functionality (multi-agent orchestration) and should be prioritized for the next release.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗