C:/Program Files/Git/compact does not clean up subagent directory, causing stale agent state in compacted sessions
Summary
When a session is compacted via /compact, the subagents/ directory (containing agent-*.meta.json and agent-*.jsonl files from all previously spawned agents) is not cleaned up. On session re-initialization, the harness loads these stale agent entries into an in-memory registry, causing cascading failures including the stop hook infinite loop reported in #58637.
Environment
- Windows 10, Claude Code v2.1.131
- Session that spawned 18 subagents across ~12 turns before compaction
Steps to Reproduce
- Spawn ≥6 background subagents across multiple turns (e.g., a large ingest pipeline)
- Wait for all subagents to complete successfully
- Run
/compact - Observe:
subagents/directory still contains all 18agent-*.meta.json+agent-*.jsonlfiles - After compaction, the stop hook permanently reports "Background subagents are still running"
Expected Behavior
/compact should either:
- Delete all files in
subagents/(since the session state is being reset), OR - Mark all agent entries with
"status": "completed"or"status": "discarded"
Actual Behavior
- All
agent-*.meta.jsonfiles persist unchanged with no status field - All
agent-*.jsonltranscript files persist - The harness loads these into an in-memory registry on session init and never re-reads from disk
- Disk cleanup post-compaction has zero effect because the registry is memory-resident
Impact
Combined with the registry state-sync bug (#58637), this means a session that hits the subagent limit becomes permanently broken — even /compact cannot recover it. Users must kill the process and restart.
Related
- #58637 — Stop hook false positive from zombie agent IDs
- #48470 — Stop hook false-positive: stale subagent IDs
Suggested fix priority
This is a smaller, more targeted fix than the full registry sync issue. Cleaning subagents/ on compaction (or adding a "discarded" status) would prevent the compacted-session variant of #58637 even without fixing the underlying registry.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗