Feature request: programmatically focus/attach a session in the agents view (e.g. `claude agents --select <session-id>`)

Resolved 💬 2 comments Opened Jun 12, 2026 by owenniles Closed Jun 16, 2026

Use case

Hooks make it easy to build completion notifications for background agents: a Stop/Notification hook on a background session can post a desktop notification (background sessions fire hooks even though they have no TTY, which is great). The natural next step is making the notification's click action bring you to the agent that fired it — but there's currently no supported way to do that:

  1. claude --resume <session-id> refuses supervisor-managed sessions with Error: Session <id> is currently running as a background agent (bg). Use 'claude agents' to find and attach to it, or add --fork-session to branch off a copy. So there's no non-TUI attach path.
  2. claude agents has no selection flag. --cwd scoping doesn't help when all agents run from the same project directory (common for a single-repo workflow).
  3. A running agents view can't be controlled externally — selection state is keyboard-only, so a notification click handler can at best focus the terminal window, leaving the user to scroll to the right row.

What already almost works

The internal CLAUDE_AGENTS_SELECT environment variable (used when backgrounding a session with ←, v2.1.175) does exactly the right thing for a new view: CLAUDE_AGENTS_SELECT=<session-id> claude agents opens the fleet view with that session selected. It works beautifully — but it's undocumented, and it's read once at startup, so it can't retarget an existing view.

Request

Any of these would close the gap, in rough order of preference:

  1. A way to retarget a running agents view, e.g. claude agents select <session-id> that signals the running TUI (the supervisor connection seems like a natural transport). This is the ideal for notification click-through: users keep one fleet view open and clicks jump it to the right agent.
  2. Document/stabilize startup selection — either bless CLAUDE_AGENTS_SELECT or add a claude agents --select <session-id> flag.
  3. Let claude --resume <session-id> attach to a supervisor-managed background session (the error message implies this is deliberate; if attach-via-resume is feasible it would also serve scripting use cases beyond notifications).

Related but distinct: #59327 asks for focus-change hooks (events out of the agents view); this asks for focus control (commands into it). Together they'd make the agents view fully automatable.

Environment

  • Claude Code v2.1.175, macOS 26 (arm64)
  • Reproduce the --resume refusal: start any session with claude --bg, then claude --resume <its-session-id> from the same project directory.

View original on GitHub ↗

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