[BUG] Duplicate compaction subagents spawned (5x identical work, 65% of session quota) — changelog fix incomplete as of v2.1.87
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Compaction subagents are being spawned multiple times for the same
work. In one session, 5 identical compaction agents ran in
parallel on Opus, sharing 100% of their requestIds, consuming
quota equivalent to ~$213 at API rates — 65% of the entire
session's token budget — for a job that needed to run once.
The changelog for a recent version states: *"Fixed background
subagents becoming invisible after context compaction, which could
cause duplicate agents to be spawned."* This fix is incomplete —
the bug persists on v2.1.85 through v2.1.87.
This compounds with two other known token-waste bugs (detailed
below) to produce a ~3x quota inflation, which is why moderate
Pro-plan tasks exhaust the 5-hour window in ~15 minutes.
Evidence
Analysis of a multi-day session's subagents/ directory reveals
7 compaction agents. Five of them launched at the exact same
timestamp and did identical work:
agent-acompact-2aedc6ef 27 reqs cc=856,502 cr=6,066,525
agent-acompact-366bb75d 27 reqs cc=856,502 cr=6,066,525
agent-acompact-82b74587 28 reqs cc=856,502 cr=6,233,095
agent-acompact-9797cc12 27 reqs cc=856,502 cr=6,066,525
agent-acompact-b7701760 27 reqs cc=856,502 cr=6,066,525
All 5 share all 27 requestIds (verified via set intersection).
They ended at different times (18:43–18:59), confirming parallel
execution of the same work. Four copies are pure waste.
Two further compaction agents continued the chain on subsequent
days, adding more quota drain.
Additionally, compaction runs on Opus — the most expensive
model. For what is essentially a summarization task, using Haiku
or Sonnet would reduce compaction's quota footprint by 10–15x.
Compounding issues in the same session
The duplicate compaction bug alone accounts for 65% of quota drain,
but two other known bugs compound with it:
Streaming prefill duplication (#6805, open since Aug 2025):
Each API response with N content blocks (thinking + text +
tool_use) is logged as N separate assistant entries, each carrying
the full usage object. This affects both the main session and
all subagents:
Main session: 341 entries from 166 unique requestIds (2.05x dup)
Subagents: duplication factors of 1.9x–2.6x across all agents
If the quota system sums JSONL entries rather than deduplicating by
requestId, every session with extended thinking is overcounted.
Resume cache busts (#40524, #34629):
5 full cache rebuilds occurred within seconds of the prior message,
triggered by "Continue from where you left off" / session
continuation events. Regression bisected to v2.1.69 per #34629.
Combined token consumption
cache_create cache_read output
Main session (JSONL) 3,024,493 23,088,829 258,030
Compaction subagents (7x) 6,026,143 42,915,466 467,357
Task subagents (5x) 600,027 5,291,192 32,975
---------- ----------- --------
TOTAL 9,650,663 71,295,487 758,362
API-equivalent cost at published Opus/Haiku per-token rates
(not actual subscription charges — represents quota consumption):
Main session: ~$111
Compaction (Opus): ~$213 (65% — includes 5 duplicate agents)
Task agents: ~$1
Total: ~$325
Legitimate work (after removing duplication, redundant compaction,
and cache busts) would require roughly a third of this.
Steps to Reproduce
- Use Claude Code (native binary, v2.1.85+) with Opus in VSCode
- Work on a session long enough to trigger context compaction
- Resume the session after timeout/rate-limit pauses
- Examine
~/.claude/projects/<project>/<session-id>/subagents/ - Look for multiple
agent-acompact-*files with overlapping
requestIds
Analysis script
A Python script that extracts only structural metadata (requestIds,
usage objects, timestamps, stop_reasons — no conversation
content) and detects all three bugs is available:
https://gist.github.com/girishnand/2aeb668ebde33d752ab0250c6c414523
Run as:
python3 analyze_session.py <session.jsonl> [session_dir]
Environment Info
- Platform: linux (Ubuntu 24.04)
- Terminal: vscode + cli
- Versions: 2.1.85, 2.1.86, 2.1.87 (auto-updated mid-session)
- Plan: Pro
- Model: claude-opus-4-6
Related Issues
- #6805 — Streaming duplication (Aug 2025, open)
- #22686 — Partial streaming values in JSONL (Feb 2026)
- #40524 — Sentinel + resume cache bugs (Mar 2026)
- #34629 — Resume cache regression bisected to v2.1.69
- #24677 — Compaction death spiral
--------------
Note: This bug report and script were generated by Opus 4.6 after examining my session logs. The script seems to run correctly on my session logs, but I have not gone through it carefully or verified it for correctness.
claude code cli Feedback ID: 889485b2-a917-40c6-939a-306980edd61f
This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗