claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[FEATURE] Agent view: mark several sessions and send one reply to all of them (plus `claude send`)

Open hairglasses opened this issue 2 months ago • 3 comments

Problem

Agent view (research preview, tested on v2.1.281) is the place to watch and steer many background sessions, but every input surface is single-target:

  • The dispatch input at the bottom starts a new session per prompt ("Every prompt you enter here starts its own new session", agent-view docs).
  • The peek panel reply goes to one selected row.
  • The only group action is Ctrl+X on a group header, which deletes the group.
  • The CLI has agents, attach, logs, stop, respawn, rm, but no way to hand text to a running session. claude attach <id> takes no prompt argument.

Common situations where one prompt must reach N sessions: "post a status update and continue", "stop after the current step, main moved", "switch to the new branch name", "re-read CLAUDE.md, the rules changed", "reply READY when idle". Today that means attaching to each session in turn and pasting, or scripting tmux around claude attach.

Proposed UX

In agent view

  1. m (or Space with a modifier) toggles a mark on the selected row; M marks every row in the current group; marked rows show a marker in the status column and the footer shows 3 marked.
  2. With marks set, the peek-panel reply input reads Reply to 3 marked sessions and Enter sends the same text to each marked session, exactly as if typed there (same delivery path as the existing single-row reply, including the "saved and sent as its next prompt" fallback for sessions whose process is down).
  3. A per-row result line (sent / queued / saved for restart / failed: <reason>) appears in the peek panel; Esc clears marks.
  4. Marks never enable destructive actions: Ctrl+X keeps acting on the selected row/group only.

From the shell

claude send <id> [--file F] "<prompt>"       # one session, same path as the peek-panel reply
claude send --all [--state done,blocked] [--cwd P] [--name GLOB] "<prompt>"
claude send --ids a,b,c "<prompt>"

--json prints one row per target with the delivery state; exit non-zero if any target failed. --dry-run lists targets without sending. Reads the prompt from stdin when no argument is given, so cat brief.md | claude send --all works. Should reuse the existing supervisor delivery that the peek panel already uses, so it works for background sessions whether or not a terminal is attached.

Why the current workarounds fall short

  • Attach + tmux paste (what my cc-broadcast wrapper does): needs tmux, ~5–9 s per target to render the prompt, detects readiness by scraping screen text (❯, footer, the "Session is starting" banner) that changes across versions, and restarts any stopped session as a side effect of attaching.
  • Cross-session messaging via a headless claude -p relay using SendMessage: the recipient is told the message came "from another session, not from you", so it cannot answer permission prompts, slash commands arrive as text, and recipients spend a turn replying to the relay. Only "queued" is confirmed synchronously; a bypass-mode recipient holds the message unless crossSessionInbound: accept; identical repeats are throttled. Addressing is by session name and the ListAgents [ref] is not the agent-view id, so scripts cannot disambiguate same-named sessions (#93515 is adjacent).
  • Channels must be enabled at launch with --channels, so they cannot reach sessions that are already running.
  • ~/.claude/jobs/* is documented as "not a stable interface"; the inbox socket payload is undocumented.

Related

  • #24947 claude inject (closed 2026-04-07 after channels shipped; channels don't cover already-running sessions or fan-out)
  • #53049 external message injection API (closed as duplicate of #35072, which went stale)
  • #93515 ListAgents / cross-session messaging: expose user-assigned session titles
  • #95954 cross-session messages leak between unrelated sessions

Environment

Claude Code 2.1.281, macOS 27 (arm64), tmux 3.7c. Agent-view docs and cross-session-messaging docs as of 2026-09-26.

🤖 Generated with Claude Code

hairglasses avatar Sep 28 '26 05:09 hairglasses

Strong +1 on the broadcast send idea. The tmux script workaround is brittle — scraping screen state to decide whether a session is "ready" breaks whenever a session renders differently.

One thing that might sharpen the CLI design: a --state filter that accepts both status values AND a simple tag/name glob in one flag, so claude send --state done,blocked --name "migration-*" "switch to the new schema branch" reads naturally without needing to chain two filters. The peek-panel mark flow for the UI looks clean already.

Also worth noting in the spec: when a broadcast message lands while a session is mid-tool-call, the delivery state should be queued rather than sent — otherwise the operator's mental model of which sessions actually received it gets fuzzy. Looks like you are already thinking about this (queued is in your state list), just flagging it as the most common edge case people are likely to hit first.

Context: I am building Claudeverse, a monitoring layer for multi-agent Claude Code workflows. The "send one instruction to all waiting sessions" pattern is the most-requested thing from developers running 5+ parallel agents. Happy to share usage patterns if useful.

kcarriedo avatar Oct 09 '26 01:10 kcarriedo

+1 for claude send (or any supported way to submit a prompt to a running interactive session from another process).

Use case: an orchestrator session supervises interactive test sessions. Today we type into the Terminal tab via AppleScript do script; the text lands in the input box but isn't submitted, so a second, separate "Enter" call is needed, and if a dialog is open that Enter is applied to the dialog instead. A real API would remove that fragility. Cross-session SendMessage works for agent-to-agent text, but not for "submit this as the user's next prompt".

osmnnl avatar Oct 10 '26 23:10 osmnnl

+1, with a data point from driving the existing path. On 2.1.303 the supervisor already accepts {"proto":1,"op":"reply","short":"<id>","text":"…","auth":"<daemon/control.key>"} on its control.sock, the request the peek-panel reply sends. Sent from a script, it behaves exactly as wanted. An idle or blocked session takes the words as a user turn (origin.kind: "human"), and a busy one queues them for its next tool step. It works per config dir, with no attach and no window. The only thing missing is a supported front door. Please ship claude send <id|name> "text" (and stdin) as a thin wrapper over that op, with --json delivery state (sent / queued / saved for restart / failed: <code>) and the existing error codes (ENOJOB, ERESPAWNING, ENOREPLY) as exit codes, plus --config-dir or CLAUDE_CONFIG_DIR support so one script can reach sessions under two accounts. Then orchestrators stop depending on roster.json, control.key and proto: 1. Also: nextTurn: true made no visible difference in my tests (still delivered at the next tool step). If it is meant to hold until the turn ends, that would be worth a flag.

TonyDowney avatar Oct 19 '26 13:10 TonyDowney