Sub-agent terminals not cleaned up after completion

Resolved 💬 3 comments Opened Mar 29, 2026 by gosha70 Closed Apr 2, 2026

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

  1. Start a Claude Code session in a terminal multiplexer (tmux/cmux)
  2. Perform work that triggers sub-agent spawning (e.g., background research agents, verify-app agents)
  3. 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.

View original on GitHub ↗

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