Auto-compaction spawns unbounded parallel subagents, ignores SUBAGENT_MODEL setting

Resolved 💬 4 comments Opened Feb 26, 2026 by xuancuongdoo Closed Mar 1, 2026

Bug Summary

Auto-compaction (agent-acompact-*) spawns unbounded parallel subagents that:

  1. Don't respect CLAUDE_CODE_SUBAGENT_MODEL environment variable
  2. Have no limit on parallel spawns
  3. Run thousands of iterations each, causing rate limit exhaustion

Environment

  • Claude Code version: latest (Feb 2026)
  • OS: macOS Darwin 25.1.0
  • Model: claude-opus-4-5

Settings

{
  "CLAUDE_CODE_SUBAGENT_MODEL": "claude-sonnet-4-6",
  "ANTHROPIC_DEFAULT_OPUS_MODEL": "claude-opus-4-5"
}

What Happened

During a session with multiple Task subagents running, auto-compaction triggered and spawned 17 parallel agent-acompact-* subagents simultaneously.

Evidence from session logs

| Metric | Value |
|--------|-------|
| Auto-compact subagents spawned | 17 |
| Total API calls from acompact | 41,235 |
| Average calls per subagent | 2,426 |
| Time window | ~1 minute |
| Model used by acompact | claude-opus-4-5 (should be Sonnet per settings) |

Token consumption

minute=2026-02-26T05:10 calls=258 input=19,450,694 tokens

This exhausted the daily rate limit almost instantly.

Expected Behavior

  1. Auto-compaction should respect CLAUDE_CODE_SUBAGENT_MODEL setting
  2. There should be a limit on parallel compaction spawns (e.g., max 2-3)
  3. There should be a circuit breaker if compaction runs >N iterations
  4. Compaction agents should use a cheaper model by default (Haiku/Sonnet)

Reproduction

  1. Set CLAUDE_CODE_SUBAGENT_MODEL to Sonnet
  2. Run a session that spawns multiple Task subagents
  3. Let context grow until auto-compaction triggers
  4. Observe that acompact uses Opus and spawns unbounded parallel instances

Log Evidence

Session: 68a8f9fa-5b24-4ec8-965f-6fcff6f426c3

subagents/
├── agent-acompact-00e847e8a9da211c.jsonl  6.3M
├── agent-acompact-03594ecfc048d497.jsonl  6.0M
├── agent-acompact-2ba49320ebd7f8c1.jsonl  5.7M
... (17 total, each ~6MB)

Each acompact log shows:

  • Model: claude-opus-4-5-20251101 (not Sonnet as configured)
  • ~2,500 API calls per subagent
  • Started at 05:10:02Z, immediately exhausted rate limit

Suggested Fix

# In auto-compaction logic:
MAX_PARALLEL_COMPACT = 3
COMPACT_MODEL = os.getenv("CLAUDE_CODE_SUBAGENT_MODEL", "claude-haiku-4-5")
MAX_COMPACT_ITERATIONS = 50

View original on GitHub ↗

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