[BUG] Subagent-created teams persist on disk after session ends, blocking future team creation
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:
- Teams created by subagents should be automatically cleaned up when the subagent exits, OR
- Sessions should detect that a team's
leadSessionIdreferences a dead session and allow overwriting/reclaiming it, OR - Subagents should not have
TeamCreateavailable (since they lack theTasktool 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
- Create
.claude/settings.jsonwith the env varCLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMSset to"1". - Exit the session (
/exitor Ctrl+C) and relaunchclaude— team tools are only loaded at startup. - Spawn a general-purpose subagent with this prompt: "Call TeamCreate with team_name: 'orphan-test'."
- Observe: subagent creates the team successfully.
- Exit the session entirely (
/exit). - In your terminal, verify
~/.claude/teams/orphan-test/config.jsonstill exists on disk. Note theleadSessionId— it points to the now-dead session. - Relaunch
claudein the same project. - Ask Claude: "Create a team called 'orphan-test'."
- Observe: error — "Already leading team 'orphan-test'. A leader can only manage one team at a time."
- 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.jsoncontains valid JSON withname,createdAt,leadSessionId, and an emptymembersarray — 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: inheritbecome permanently unrecoverable zombies after parent session ends. Blocks new team creation with "Already leading team" error, requires manualrm -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.jsonacross 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.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗