C:/Program Files/Git/compact does not clean up subagent directory, causing stale agent state in compacted sessions

Resolved 💬 2 comments Opened May 13, 2026 by battlesym Closed Jun 11, 2026

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

  1. Spawn ≥6 background subagents across multiple turns (e.g., a large ingest pipeline)
  2. Wait for all subagents to complete successfully
  3. Run /compact
  4. Observe: subagents/ directory still contains all 18 agent-*.meta.json + agent-*.jsonl files
  5. After compaction, the stop hook permanently reports "Background subagents are still running"

Expected Behavior

/compact should either:

  1. Delete all files in subagents/ (since the session state is being reset), OR
  2. Mark all agent entries with "status": "completed" or "status": "discarded"

Actual Behavior

  • All agent-*.meta.json files persist unchanged with no status field
  • All agent-*.jsonl transcript 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.

View original on GitHub ↗

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