[BUG] Orchestrator lead context never auto-releases after teammate exits — sticky status bar + blocked TeamCreate
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?
After a teammate exits cleanly (shutdown_approved returned, claude process gone, ~/.claude/teams/<team>/ auto-removed), the orchestrator still considers itself "leading" the now-empty team. The lead context is in-memory orchestrator state with no on-disk artefact, and it survives every cleanup signal except an explicit TeamDelete call.
Calling TeamCreate for a different team name fails with "Already leading team <old-name>" until TeamDelete is called. The status bar reads from this in-memory state, so dead teammates' names persist in the UI after every clean exit.
What Should Happen?
TeamCreate({ team_name: "lead-test-b" }) should succeed when the previous team has no living members, no on-disk state, and no other observable presence. The orchestrator should recognise the lead context is stale and release it implicitly.
The status bar should reflect actual live team state, not a snapshot frozen at last teammate spawn.
Error Messages/Logs
After a clean teammate exit (verified via `ls ~/.claude/teams/` showing no entry for `lead-test-a`), attempting to create a new team:
Error: Already leading team "lead-test-a". A leader can only manage one team at a time.
Use TeamDelete to end the current team before creating a new one.
State search confirming no on-disk binding to `lead-test-a`:
$ ls ~/.claude/teams/
(empty)
$ find ~/.claude -type f \( -name '*.json' -o -name '*.yml' \) | xargs grep -l "lead-test-a" 2>/dev/null
(no results)
$ python3 -c "import json; d=json.load(open(f'/Users/<user>/.claude/sessions/{ORCH_PID}.json')); print(list(d.keys()))"
['pid', 'sessionId', 'cwd', 'startedAt', 'procStart', 'version', 'peerProtocol', 'kind', 'entrypoint', 'status', 'updatedAt']
# no 'team' or 'leadingTeam' field
The lead context exists nowhere on disk. It must be in the orchestrator process's memory — and there is no public mechanism to inspect or release it short of TeamDelete.
After TeamDelete on the empty team:
{"success": true, "message": "Cleaned up directories and worktrees for team \"lead-test-a\"", "team_name": "lead-test-a"}
…and the next TeamCreate for a different name immediately succeeds.
Steps to Reproduce
- Create a team and spawn a teammate that idles immediately:
```
TeamCreate({ team_name: "lead-test-a" })
Agent({
team_name: "lead-test-a",
name: "probe",
subagent_type: "general-purpose",
prompt: "FIRST ACTION: ToolSearch select:SendMessage. Then SendMessage to team-lead 'ack'. Then go idle. When you receive {type: shutdown_request}, reply with shutdown_response."
})
```
- Wait ~15 seconds for boot and ack.
- Send a clean shutdown_request:
````
SendMessage({ to: "probe", message: { type: "shutdown_request" } })
- Wait until the teammate's claude process exits and the team_dir auto-cleans. Verify:
ls ~/.claude/teams/does not showlead-test-a.
- Try to create a different team WITHOUT calling TeamDelete first:
````
TeamCreate({ team_name: "lead-test-b" })
- Observe the rejection:
"Already leading team \"lead-test-a\"". Inspect the status bar — it still showslead-test-aandprobe.
- Workaround: call
TeamDelete()(succeeds even though there is nothing on disk left to delete), then retry step 5 — succeeds.
Claude Model
Opus
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.126
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
Additional Information
This is one of three related bugs in the Agent Teams teardown path (filed separately per the preflight checklist):
- Related Bug 1:
TeamDeletereturns success on a team with a shutdown-pending teammate, orphaning a pane. - Related Bug 2:
shutdown_approved's pane-close handler is non-deterministic. - This issue (Bug 3): Orchestrator lead context never auto-releases after teammate exits.
The three bugs together produce a workflow shape where:
- Even on the happy path the orchestrator must call
TeamDeleteto clear the status bar - But the harness's
TeamDeleteis itself unsafe if any teammate is still mid-shutdown handshake (Bug 1) - And even the "clean" shutdown path produces orphan panes intermittently (Bug 2)
Fixing this issue alone would let the status bar reflect live state and let the orchestrator create new teams without ceremony, which is the most user-visible of the three. Possible fixes:
- Lead context auto-releases when the team_dir at
~/.claude/teams/<team>/disappears (regardless of cause) - Lead context auto-releases when all non-lead members have exited (no claude processes matching the team's spawn signature, no entries in the team's
membersarray) - Lead context auto-releases after a configurable idle timeout with zero non-lead members
Either trigger fires the implicit TeamDelete (or its in-memory equivalent), so the orchestrator can immediately create a new team and the status bar reflects the actual live state.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗