claude-code - 💡(How to fix) Fix C:/Program Files/Git/compact does not clean up subagent directory, causing stale agent state in compacted sessions [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#58731Fetched 2026-05-14 03:40:55
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Author
Timeline (top)
labeled ×5commented ×1cross-referenced ×1

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.

Root Cause

  • 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
RAW_BUFFERClick to expand / collapse

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.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING