Skip to content

fix(remote): copies leave the agent's tmux; exact-text clipboard tool for agents - #824

Merged
bborn merged 1 commit into
mainfrom
task/5550-copypaste-to-and-from-executor-panes-on
Oct 3, 2026
Merged

bborn merged 1 commit into
mainfrom
task/5550-copypaste-to-and-from-executor-panes-on

Conversation

@bborn

@bborn bborn commented Sep 26, 2026

Copy link
Copy Markdown
Owner

Fixes copy/paste to and from executor panes, especially on placed hosts (found in InfluenceKit task 5547).

What was wrong

  1. The agent's tmux swallowed clipboard writes. fix(hosts): a task on another host behaves like a local one #758 set set-clipboard on on the outer (UI) server only. The server the agent runs on (the local agent server, or the placed host's tmux) kept tmux's default, external. Under that default an OSC 52 written by an application in the pane is dropped: Claude Code's copy, an editor yank, printf '\e]52;…'. It never reaches the view. I reproduced this with two nested tmux servers, and it is now a test.
  2. Wrapped output gains hard newlines. When you select text in the terminal, you get a line break wherever the agent's UI wrapped it. Agents like Claude Code draw those breaks themselves, so no tmux option (copy-mode -J, capture-pane -J) can join them. The fix has to avoid the terminal altogether.

Changes

  • tmuxctl.AgentClipboardArgs / PassthroughArgs, applied whenever a view opens, both locally (ensureViewSession) and on the placed host (the attach chain). They set:

    • set-clipboard on on the agent server.
    • terminal-features[90|91] = tmux*:clipboard, screen*:clipboard, so an older tmux on a host, or one whose feature query was lost over ssh, still knows ty's view can take OSC 52. These use fixed indices, so they overwrite rather than append each time a view opens.
    • allow-passthrough on scoped to the task's window, for programs that wrap OSC 52 in tmux passthrough.

    All of these are set before the client attaches, because tmux reads terminal features on connect. On the host, errors are discarded so an older tmux still attaches.

  • New MCP tool taskyou_copy_to_clipboard(text) and a new internal/clipboard package. The tool runs where the task was scheduled; placed tasks reach it over the existing MCP relay. It delivers the text byte for byte:

    • to the system clipboard (pbcopy, wl-copy, xclip, xsel or clip.exe),
    • and, when a ty view is attached, as OSC 52 through it (load-buffer -b ty-clipboard -w), which covers a TUI reached over ssh.

    There are no terminal escapes from the agent and no secret written to a file on the host. The task log records only the byte count. The tool is auto-approved, and agents are told to use it in both the local guidance and the relayed-host guidance.

  • Docs: docs/remote-execution.md and docs/mcp-tools-reference.md.

Tests

  • internal/tmuxctl: a real two-server test. An app's OSC 52 inside the inner server reaches the outer server with AgentClipboardArgs, and a control test shows it is dropped without them. Also an idempotency test against real tmux.
  • internal/executor: the attach chain sets every option, before the attach, scoped to the task's window, and silences errors. I also ran the generated chain by hand against an isolated tmux to check the quoting.
  • internal/clipboard: choice of route per OS and session, fallback when a command fails, the OSC 52 route, the no-route error, and the size limits.
  • internal/mcp: the tool is advertised, delivers the exact text, keeps the text out of the task log, and returns failures as tool errors.

TestEnsureTaskWindow_ExportedEnvVarsReachLiveShellPane fails on the host I ran this on (mona), with or without this change. It is environmental and unrelated.

Not in this PR

  • Your local terminal still has to accept OSC 52. In iTerm2 that is "Applications in terminal may access clipboard".
  • The web GUI doesn't receive clipboard pushes. The tool reaches the scheduling machine's system clipboard, which covers the desktop app on the same machine.

🤖 Generated with Claude Code

…act-text clipboard tool

Copy/paste from executor panes on placed hosts was broken two ways.

The agent's own tmux dropped clipboard writes. ty set `set-clipboard on` on
the outer (UI) server only. Under the agent server's default, `external`,
an OSC 52 from an application in the pane (Claude Code's copy, an editor,
a printf) is swallowed and never reaches the view. Now, when a view opens,
the agent server (local, or the placed host's tmux via the attach chain)
gets `set-clipboard on`, terminal-features entries saying ty's nested view
(TERM tmux*/screen*) has a clipboard, and `allow-passthrough on` on the
task's window. A two-server tmux test shows the copy dropped without these
options and delivered with them.

Terminal selections still pick up hard line breaks wherever the agent's UI
wrapped its output, and no tmux option can undo those. The new MCP tool
taskyou_copy_to_clipboard carries text over ty's own channel (the MCP relay
for placed tasks) to the scheduling machine. There it goes to the system
clipboard (pbcopy/wl-copy/xclip/xsel/clip.exe) and, when a ty view is open,
out as OSC 52 through it. The task log records only the size, never the
text. Agents are told to use it in both local and relayed guidance.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@bborn
bborn merged commit 91d78c0 into main Oct 3, 2026
3 of 4 checks passed
@bborn
bborn deleted the task/5550-copypaste-to-and-from-executor-panes-on branch October 3, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant