Skip to content

fix(tui): support copying over ssh with set-clipboard on tmux config - #30472

Merged
simonklee merged 2 commits into
anomalyco:devfrom
ayubun:ayu/fix-osc52-handling
Aug 6, 2026
Merged

fix(tui): support copying over ssh with set-clipboard on tmux config#30472
simonklee merged 2 commits into
anomalyco:devfrom
ayubun:ayu/fix-osc52-handling

Conversation

@ayubun

@ayubun ayubun commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #25253
Closes #25252
Closes #19982
Closes #15907
Maybe Closes #36646
(possibly more?)

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

the appropriate config for clipboard management in modern tmux versions is set-clipboard: https://github.com/tmux/tmux/wiki/Clipboard

this PR makes it so that the copy to clipboard feature sends raw OSC52 when inside tmux, because that is what the set-clipboard feature is expecting (see tmux maintainer commentary: tmux/tmux#4214 (comment))

because opencode currently sends the \x1bPtmux;\x1b escape sequence when it recognizes the TMUX env, the set-clipboard feature does not function as-intended, forcing people to use allow-passthrough (which has its own security implications)

How did you verify your code works?

i built the darwin and x86 binaries, and tested locally + on my remote by sending a prompt and then using the copy feature to copy the text. then, i pasted elsewhere to validate

  • in all cases, testing outside of tmux works as expected, both in the old and new binary
  • with a default tmux config, local works & remote fails for both the old and new binary (expected, unfortunately)
  • with a set-clipboard on tmux config:
    • local works before & after
    • remote fails before & works after (this is the primary fix for this PR)
  • with a allow-passthrough on tmux config:
    • local works before & after
    • remote works before, but not after (unless set-clipboard on)

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label Jun 2, 2026
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found two related PRs that are worth reviewing:

  1. PR fix(cli): handle OSC52 clipboard passthrough properly under GNU screen #28592: fix(cli): handle OSC52 clipboard passthrough properly under GNU screen

  2. PR fix(clipboard): write OSC52 to /dev/tty instead of stdout #12129: fix(clipboard): write OSC52 to /dev/tty instead of stdout

These PRs are related in that they all address OSC52 clipboard functionality, though they target different scenarios (tmux vs screen, and different output approaches). PR #30472 (the current PR) is specifically focused on fixing tmux's set-clipboard on mode with raw OSC52 sequences, which is a more targeted fix than the earlier PRs.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Jun 2, 2026
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@ayubun ayubun changed the title fix: send raw osc52 in tmux so clipboard works over ssh with set-clipboard on fix(opencode): support set-clipboard on tmux config Jun 2, 2026
@ayubun ayubun changed the title fix(opencode): support set-clipboard on tmux config fix(opencode): support copying with set-clipboard on tmux config Jun 2, 2026
@ayubun
ayubun force-pushed the ayu/fix-osc52-handling branch from 533aaaa to a9093dd Compare June 8, 2026 18:23
@ayubun ayubun changed the title fix(opencode): support copying with set-clipboard on tmux config fix(tui): support copying with set-clipboard on tmux config Jun 8, 2026
@ayubun ayubun changed the title fix(tui): support copying with set-clipboard on tmux config fix(tui): support copying over ssh with set-clipboard on tmux config Jun 8, 2026
@ayubun
ayubun force-pushed the ayu/fix-osc52-handling branch from a9093dd to 695a311 Compare June 11, 2026 21:22
@ayubun
ayubun force-pushed the ayu/fix-osc52-handling branch from 695a311 to d8e561e Compare July 1, 2026 00:42
@simonklee
simonklee self-requested a review July 1, 2026 08:46
@ayubun
ayubun force-pushed the ayu/fix-osc52-handling branch from 8c7098a to bff21b8 Compare July 9, 2026 22:53
@ayubun
ayubun force-pushed the ayu/fix-osc52-handling branch from bff21b8 to 6117315 Compare July 15, 2026 20:35
@ayubun
ayubun force-pushed the ayu/fix-osc52-handling branch from 6117315 to 5f7d102 Compare August 4, 2026 20:01
@simonklee

Copy link
Copy Markdown
Member

While simple this pr sends multiple of the sequence. I explored a fix for this a long time ago anomalyco/opentui#1215 which i still need ot get back to.

@ayubun

ayubun commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

While simple this pr sends multiple of the sequence. I explored a fix for this a long time ago anomalyco/opentui#1215 which i still need ot get back to.

in what case would a user be using tmux passthrough but not set-clipboard on ? tmux set-clipboard on has been the standard for a while now, and it works even if you have passthrough enabled.. i dont see why we cant just send the regular OSC52 sequence in all cases. having an env (the PR you linked as WIP) feels pretty overengineered imo

i'm fine not double-sending the sequence; i only proposed that so it would be easier to accept the PR on the grounds of backwards compatibility. i've modified it to only send one, so now it's a one-liner

@simonklee

@ayubun
ayubun force-pushed the ayu/fix-osc52-handling branch from 5f7d102 to 07cfcfb Compare August 4, 2026 21:33
@simonklee

Copy link
Copy Markdown
Member

While simple this pr sends multiple of the sequence. I explored a fix for this a long time ago anomalyco/opentui#1215 which i still need ot get back to.

in what case would a user be using tmux passthrough but not set-clipboard on ? tmux set-clipboard on has been the standard for a while now, and it works even if you have passthrough enabled.. i dont see why we cant just send the regular OSC52 sequence in all cases. having an env (the PR you linked as WIP) feels pretty overengineered imo

i'm fine not double-sending the sequence; i only proposed that so it would be easier to accept the PR on the grounds of backwards compatibility. i've already modified it, now it's quite literally a one-liner

@simonklee

Yeah, i buy that.

@ayubun

ayubun commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

While simple this pr sends multiple of the sequence. I explored a fix for this a long time ago anomalyco/opentui#1215 which i still need ot get back to.

in what case would a user be using tmux passthrough but not set-clipboard on ? tmux set-clipboard on has been the standard for a while now, and it works even if you have passthrough enabled.. i dont see why we cant just send the regular OSC52 sequence in all cases. having an env (the PR you linked as WIP) feels pretty overengineered imo
i'm fine not double-sending the sequence; i only proposed that so it would be easier to accept the PR on the grounds of backwards compatibility. i've already modified it, now it's quite literally a one-liner
@simonklee

Yeah, i buy that.

is that sarcasm .. ? i genuinely cant tell o.o

it really was my intention, as i even mentioned it in the PR description long before you reviewed

Screenshot 2026-08-04 at 2 55 07 PM Screenshot 2026-08-04 at 2 55 24 PM

@simonklee

Copy link
Copy Markdown
Member

While simple this pr sends multiple of the sequence. I explored a fix for this a long time ago anomalyco/opentui#1215 which i still need ot get back to.

in what case would a user be using tmux passthrough but not set-clipboard on ? tmux set-clipboard on has been the standard for a while now, and it works even if you have passthrough enabled.. i dont see why we cant just send the regular OSC52 sequence in all cases. having an env (the PR you linked as WIP) feels pretty overengineered imo
i'm fine not double-sending the sequence; i only proposed that so it would be easier to accept the PR on the grounds of backwards compatibility. i've already modified it, now it's quite literally a one-liner
@simonklee

Yeah, i buy that.

is that sarcasm .. ? i genuinely cant tell o.o

it really was my intention, as i even mentioned it in the PR description long before you reviewed

Screenshot 2026-08-04 at 2 55 07 PM Screenshot 2026-08-04 at 2 55 24 PM

No, i meant i think your argument is sound and that this looks good.

@ayubun

ayubun commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

While simple this pr sends multiple of the sequence. I explored a fix for this a long time ago anomalyco/opentui#1215 which i still need ot get back to.

in what case would a user be using tmux passthrough but not set-clipboard on ? tmux set-clipboard on has been the standard for a while now, and it works even if you have passthrough enabled.. i dont see why we cant just send the regular OSC52 sequence in all cases. having an env (the PR you linked as WIP) feels pretty overengineered imo
i'm fine not double-sending the sequence; i only proposed that so it would be easier to accept the PR on the grounds of backwards compatibility. i've already modified it, now it's quite literally a one-liner
@simonklee

Yeah, i buy that.

is that sarcasm .. ? i genuinely cant tell o.o
it really was my intention, as i even mentioned it in the PR description long before you reviewed
Screenshot 2026-08-04 at 2 55 07 PM Screenshot 2026-08-04 at 2 55 24 PM

No, i meant i think your argument is sound and that this looks good.

oh i see, sorry it's difficult to read the intentions on text; thank you for your time

@simonklee

Copy link
Copy Markdown
Member

changed my mind and went back to y our original impl.

@simonklee

Copy link
Copy Markdown
Member

I'll test this and merge tomorrow.

@simonklee
simonklee merged commit def7220 into anomalyco:dev Aug 6, 2026
8 checks passed
charlesverge pushed a commit to charlesverge/opencode that referenced this pull request Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants