claude-code - 💡(How to fix) Fix [BUG] Subagent Work Is Lost on WorkTree Cleanup with No-Commit [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#52957Fetched 2026-04-25 06:16:12
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1

Error Message

Error Messages/Logs

Root Cause

The parent agent lost the work that subagents did because
worktrees are automatically cleaned up and it 'forgot' to tell the
subagents to commit their work so that it didn't get auto-cleaned up.
When it happens, this is a devastating waste of compute, time and
money for everyone involved.

RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

The parent agent lost the work that subagents did because
worktrees are automatically cleaned up and it 'forgot' to tell the
subagents to commit their work so that it didn't get auto-cleaned up.
When it happens, this is a devastating waste of compute, time and
money for everyone involved.

What Should Happen?

Use a background process that starts after a sub-agent completes, which waits N rounds before notifying the agent that they need to save the wireframe changes immediately unless they'd like them to be destroyed, so that this never happens again. Let them know it'll be destroyed in another M rounds, and of course, if they do nothing, go ahead and destroy it.

Error Messages/Logs

Steps to Reproduce

Ask the parent agent to run subagents on a task and see how often you end up losing the results to this bug. Doesn't happen every time, obviously, but once is enough. Major waste.

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.1.119

Platform

Other

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

extent analysis

TL;DR

Implement a background process to notify the parent agent to save subagent work before it is auto-cleaned up.

Guidance

  • Identify the timing and conditions under which the worktrees are automatically cleaned up to determine the optimal value for N rounds.
  • Develop a notification system for the parent agent to alert subagents to commit their work before cleanup.
  • Consider implementing a confirmation step for the parent agent to ensure intentional destruction of work if no action is taken.
  • Test the new background process to verify it resolves the issue without introducing new problems.

Example

No code example is provided due to lack of specific implementation details in the issue.

Notes

The solution relies on understanding the current cleanup mechanism and the subagent workflow. The value of N and M rounds should be determined based on the specific requirements and constraints of the system.

Recommendation

Apply workaround: Implement the proposed background process to mitigate the loss of subagent work due to auto-cleanup, as the root cause is understood and a targeted solution can be developed.

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

claude-code - 💡(How to fix) Fix [BUG] Subagent Work Is Lost on WorkTree Cleanup with No-Commit [1 comments, 2 participants]