Appearance
SOP-006: Clean Up Teams
ID: SOP-006 | Version: 1.0 | Status: Current | Date: 2026-02-12
Fresh 🌱Gracefully shut down agent teams and clean up shared resources when work is complete.
Overview
Proper cleanup ensures resources are freed, sessions are terminated cleanly, and no orphaned processes remain. Always use the lead to initiate cleanup.
Prerequisites
- Agent team is running (SOP-002)
- Work is substantially complete
- You're in the lead's session (not a teammate)
Cleanup Workflow
Step-by-Step Cleanup
Step 1: Verify Work is Complete
Before cleanup, check:
Show me the status of all tasksExpected output:
- All critical tasks: Completed
- Remaining tasks: Nice-to-have only
- No blockers preventing completion
- Results synthesized or documented
Step 2: Stop New Work
Tell the lead:
Stop accepting new work. We're wrapping up.Lead will:
- Stop creating new tasks
- Redirect teammates to finalize current work
- Begin synthesis/documentation
Step 3: Shut Down Teammates
When teammates are finishing:
Ask all teammates to shut down gracefullyOr individual shutdown:
Ask the backend specialist to shut downEach teammate will:
- Receive shutdown request from lead
- Respond with approval/rejection:
- Approve: "Ready to shut down"
- Reject: "I need 5 more minutes to finish X"
- Exit gracefully if approved
- Continue working if rejected with explanation
Let teammates finish current tasks - don't force shutdown mid-work.
Step 4: Wait for All to Exit
Monitor shutdown progress:
Are all teammates shut down?Lead will:
- Check each teammate status
- Confirm all sessions ended
- Report any stragglers
Expected output:
✓ Security Specialist: shut down
✓ Backend Developer: shut down
✓ Frontend Developer: shut down
All teammates have exited.Step 5: Clean Up Team
When all teammates are shut down:
Clean up the teamClaude (the lead) will:
- Verify all teammates are offline
- Remove shared task list
- Delete team configuration
- Free resources
- Confirm cleanup complete
Output:
✓ Team 'project-x-review' cleanup initiated
✓ Verified all 3 teammates shut down
✓ Task list removed
✓ Team resources freed
✓ Cleanup completeStep 6: Verify Cleanup
Check that team is really gone:
Show me the current team statusExpected:
No active team.Or check filesystem:
bash
# macOS/Linux
ls ~/.claude/teams/
# Windows PowerShell
ls $env:USERPROFILE\.claude\teams\Team folder should be gone.
Handling Shutdown Issues
Teammate Won't Shut Down
Can the backend specialist exit the team?If they refuse:
- Get explanation (they may have critical work)
- Allow more time: "We can wait 5 minutes"
- Or force exit (last resort):
Force shutdown the backend specialist
Cleanup Fails with Error
If cleanup doesn't complete:
What's preventing cleanup? Try again.Common issues:
- Teammate still running → shut them down first
- Permissions issue → use dangerously-skip flag
- Orphaned session → manual cleanup (see below)
Manual Cleanup for Stuck Teams
If automated cleanup fails:
bash
# List all teams
ls ~/.claude/teams/
# Remove specific team (replace with actual name)
rm -rf ~/.claude/teams/my-team-name
# Or remove all team files
rm -rf ~/.claude/teams/tmux cleanup (if using split panes):
bash
# List all tmux sessions
tmux ls
# Kill the team session
tmux kill-session -t session-namePost-Cleanup
Save Results
Before cleanup, save important findings:
Save all findings to docs/FINDINGS.mdClaude should:
- Compile all teammate work
- Synthesize discoveries
- Document decisions
- Write summary
Archive Session
Create a transcript or log:
bash
# macOS/Linux - save terminal history
history > team-session-log.txt
# Or copy Claude Code transcript
cp ~/.claude/logs/... backup/Lessons Learned
After first team cleanup, document:
- What worked well
- What was challenging
- How to improve next time
- Best team configuration for this type of work
Best Practices
Natural Shutdown Timing
❌ Too early:
Clean up when only 60% done(Valuable work interrupted)
✅ Just right:
Wait for key findings documented, all tasks completed or properly closedGet Final Summary First
Before cleanup:
Synthesize all findings into a comprehensive summary documentThis ensures no discoveries are lost.
Graceful Over Forced
Graceful shutdown (preferred):
Ask teammates to shut down- Clean exit
- Proper resource cleanup
- No orphaned processes
Force shutdown (last resort):
Force shutdown all teammates- Fast but messy
- May leave temporary files
- Risk of incomplete work loss
Document Everything Before Cleanup
Before we clean up, please:
1. Save all findings to RESULTS.md
2. Document any open questions in TODO.md
3. Include recommended next stepsVerification Checklist
✓ Work documented
- Results saved to files
- Findings compiled
- Summary written
✓ All teammates shut down
- None showing in Shift+Up/Down cycling
- Lead confirms all gone
- No orphaned sessions
✓ Team cleanup completed
- No errors during cleanup
- Lead confirms team removed
- Team folder gone from ~/.claude/teams/
✓ Resources freed
- No orphaned tmux sessions (tmux ls shows none)
- Terminal responsive
- No stray processes
✓ Session still responsive
- Can type new commands
- Lead isn't stuck in cleanup loop
- Ready for next session or team
Troubleshooting
Q: "Cleanup failed: teammates still running" A:
- Manually shut down:
Ask all teammates to shut down - Wait 10 seconds for graceful exit
- Force if needed:
Force shutdown all teammates - Then try cleanup again
Q: Cleanup hung/stuck A:
- Kill stuck lead session: Ctrl+C
- Manual cleanup:
rm -rf ~/.claude/teams/team-name - Restart:
claudestarts fresh
Q: "Permission denied" during cleanup A: Use flag on startup:
claude --dangerously-skip-permissionsQ: Orphaned tmux session remains A:
bash
tmux ls # Find session name
tmux kill-session -t session-nameQ: Lost important work during cleanup A:
- Check terminal history
- Check ~/.claude/logs/ for session transcripts
- Recovery may not be possible - lesson for future
Prevention Tips
Always Save Before Cleanup
Document all findings, save to files, then clean upCreate Backups
bash
# Backup team config before cleanup
cp -r ~/.claude/teams/ backup-teams/
# Backup chat logs
cp -r ~/.claude/logs/ backup-logs/Test Cleanup Process
First team cleanup:
- Do it with low-stakes work
- Verify all cleanup steps work
- Note any issues
- Document your team's cleanup procedure