[BUG] Subagent-created teams persist on disk after session ends, blocking future team creation

Resolved 💬 3 comments Opened Mar 10, 2026 by gabgoss Closed Apr 7, 2026

Preflight Checklist

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

What's Wrong?

When a general-purpose subagent calls TeamCreate, the team config is written to ~/.claude/teams/{team-name}/config.json. When the subagent finishes and the session ends, this team config is never cleaned up. The orphaned team file persists indefinitely on disk.

On the next session launch, the orphaned team's leadSessionId points to a dead session. Despite this, if the user (or Claude) attempts to create a new team with the same name, they get:

Error: Already leading team "orphan-test". A leader can only manage one team at a time. Use TeamDelete to end the current team before creating a new one.

The user must manually delete ~/.claude/teams/{team-name}/ to recover.

This is compounded by the fact that subagents have TeamCreate available but lack the Task tool to populate the team with teammates. The subagent creates a team shell it can never use, and that shell blocks future team creation.

What Should Happen?

Either:

  1. Teams created by subagents should be automatically cleaned up when the subagent exits, OR
  2. Sessions should detect that a team's leadSessionId references a dead session and allow overwriting/reclaiming it, OR
  3. Subagents should not have TeamCreate available (since they lack the Task tool to add teammates anyway)

Error Messages/Logs

Error: Already leading team "subagent-team-test". A leader can only manage one team at a time. Use TeamDelete to end the current team   
     before creating a new one.

Steps to Reproduce

  1. Create .claude/settings.json with the env var CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS set to "1".
  2. Exit the session (/exit or Ctrl+C) and relaunch claude — team tools are only loaded at startup.
  3. Spawn a general-purpose subagent with this prompt: "Call TeamCreate with team_name: 'orphan-test'."
  4. Observe: subagent creates the team successfully.
  5. Exit the session entirely (/exit).
  6. In your terminal, verify ~/.claude/teams/orphan-test/config.json still exists on disk. Note the leadSessionId — it points to the now-dead session.
  7. Relaunch claude in the same project.
  8. Ask Claude: "Create a team called 'orphan-test'."
  9. Observe: error — "Already leading team 'orphan-test'. A leader can only manage one team at a time."
  10. Clean up: manually delete ~/.claude/teams/orphan-test/.

Claude Model

Opus

Is this a regression?

No, this never worked

Last Working Version

2.1.59

Claude Code Version

2.1.72 (Claude Code)

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

  • The orphaned config.json contains valid JSON with name, createdAt, leadSessionId, and an empty members array — confirming the team shell was created but never populated.
  • A default/ directory (empty, no config) was also observed in ~/.claude/teams/, suggesting other orphan scenarios may exist.
  • Related: subagents have TeamCreate/TeamDelete available despite lacking the Task tool to add teammates — an undocumented tool distribution that enables this orphan scenario. Filed separately as a documentation issue.
  • Related issues (similar symptoms, different root causes):
  • #27610 — Teammate agents with model: inherit become permanently unrecoverable zombies after parent session ends. Blocks new team creation with "Already leading team" error, requires manual rm -rf ~/.claude/teams/. Similar symptoms but caused by teammate-level zombie, not an empty team shell from a subagent.
  • #29271 — Dead teammates persist in config.json across sessions. Lead can't distinguish dead from idle, spawns duplicates. Proposes liveness checks on TeamCreate. Focuses on teammate entries within a team, not on the team shell itself.
  • #31788 — TeamDelete blocked indefinitely by hung agents with no force-kill or timeout. Related cleanup gap but at the teammate shutdown level.
  • Our bug is distinct: the team itself orphans (not a teammate within it), created by a subagent that lacks the Task tool to populate or clean it up.

View original on GitHub ↗

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