Sub-agent terminals not cleaned up after completion
Description
When Claude Code spawns sub-agents (e.g., via the Agent tool), each sub-agent appears to create a terminal/process that persists after the sub-agent completes its work and returns results. Over the course of a long session with multiple sub-agent invocations, idle terminals accumulate.
Steps to Reproduce
- Start a Claude Code session in a terminal multiplexer (tmux/cmux)
- Perform work that triggers sub-agent spawning (e.g., background research agents, verify-app agents)
- After the agents complete and return results, check for lingering terminal sessions
Expected Behavior
Terminals/processes created by sub-agents should be cleaned up automatically when the sub-agent completes and returns its result to the parent session.
Actual Behavior
Idle terminals remain after sub-agents finish, visible in the terminal multiplexer's session/window list. They appear as entries like Terminal 8, Terminal 9, etc. with no active process.
Environment
- macOS (Darwin 25.2.0)
- Claude Code CLI
- Session backend: tmux / cmux
Additional Context
Observed during an extended build session with multiple sub-agent invocations for code verification, test running, and codebase exploration. The idle terminals don't affect functionality but create visual clutter and potential resource waste.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗