Graceful degradation for agent teams on session interruption

Resolved 💬 4 comments Opened Feb 28, 2026 by ketang Closed Mar 4, 2026

Problem

When a Claude Code session with active agent teammates ends unexpectedly, there's no coordinated shutdown. I've had sessions where a team of agents stopped mid-work, and when I resumed, the repository had conflicts and work that teammates appeared to have completed wasn't fully landed. Sorting it out took longer than the original work would have.

I don't know exactly what caused the interruption or what happened to each agent — the experience from the user side is just that the session ended and things were in a messy state.

Worktree risk

Teammates spawned with isolation: "worktree" may be particularly vulnerable. Speculation: if an agent exits and its worktree is cleaned up automatically, any unpushed commits on that worktree's branch would be lost. Normal exits prompt the user to keep or remove the worktree — my assumption is that this prompt may not happen during a forced exit, but I haven't verified this. If that assumption is correct, worktrees with commits on them should not be removed without explicit user confirmation, regardless of how the session ends.

What would help

A checkpoint opportunity before disruptive events. If there's any advance signal that a session is about to end or degrade (approaching a limit, context pressure, etc.), a hook or built-in behavior that gives agents a moment to commit and push their work would prevent most of the damage.

Team-aware shutdown. When the lead session is about to stop for any reason, teammates ideally get a signal to finish their current task and commit rather than being abandoned mid-work. Whether this is built-in behavior or a hook users can wire up, either approach works.

Safe worktree cleanup. Assumption: worktrees may be auto-removed on forced exit without user confirmation. If that's the case, worktrees containing commits not present on any other branch should never be auto-removed. If the session can't prompt the user, the safe default should be to keep the worktree.

Current workarounds

  • PreCompact hook that auto-commits before context summarization
  • Project instructions telling agents to commit frequently and push before reporting done
  • These help reduce the blast radius but can't cover cases where the interruption comes without warning

View original on GitHub ↗

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