Feature request: programmatically focus/attach a session in the agents view (e.g. `claude agents --select <session-id>`)
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:
claude --resume <session-id>refuses supervisor-managed sessions withError: 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.claude agentshas no selection flag.--cwdscoping doesn't help when all agents run from the same project directory (common for a single-repo workflow).- 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:
- 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. - Document/stabilize startup selection — either bless
CLAUDE_AGENTS_SELECTor add aclaude agents --select <session-id>flag. - 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
--resumerefusal: start any session withclaude --bg, thenclaude --resume <its-session-id>from the same project directory.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗