Skip to content

fix(tmux): enable OSC 52 clipboard passthrough in nested tmux layers - #996

Merged
namastex888 merged 1 commit into
devfrom
fix/tmux-osc52-clipboard
Apr 2, 2026
Merged

namastex888 merged 1 commit into
devfrom
fix/tmux-osc52-clipboard

Conversation

@namastex888

Copy link
Copy Markdown
Contributor

Summary

  • Switch both genie.tmux.conf and tui-tmux.conf from set-clipboard on to set-clipboard external so tmux forwards OSC 52 sequences instead of consuming them
  • Add allow-passthrough on and Ms terminal-override to the inner (agent) tmux layer, which was missing both
  • Create osc52-copy.sh helper script that writes OSC 52 directly to the SSH PTY, bypassing nested tmux absorption
  • Replace copy-selection-and-cancel with copy-pipe-and-cancel bindings piping through osc52-copy.sh in both configs
  • Update update.ts and setup.ts to install osc52-copy.sh to ~/.genie/ during setup/update

Root Cause

set-clipboard on tells tmux to handle the clipboard internally (via Ms capability), which means it consumes OSC 52 sequences rather than passing them through to the terminal emulator. In a nested tmux setup (TUI outer layer + agent inner layer), this double-consumption completely prevents clipboard sync from reaching the user's terminal.

Test plan

  • All 1812 existing tests pass (0 regressions)
  • 7 new regression tests added in tmux-config.test.ts covering all 5 defects
  • bun run build succeeds
  • bun run check passes (typecheck + lint + dead-code + tests)

Closes #967

Both genie.tmux.conf (inner/agent layer) and tui-tmux.conf (outer/TUI
layer) used `set-clipboard on`, which causes tmux to consume OSC 52
sequences instead of forwarding them to the terminal emulator. This
breaks clipboard sync for SSH users connecting through the TUI.

Changes:
- Switch both configs from `set-clipboard on` to `set-clipboard external`
- Add `allow-passthrough on` and Ms terminal-override to genie.tmux.conf
- Create osc52-copy.sh helper that writes OSC 52 directly to SSH PTY
- Replace copy-selection-and-cancel with copy-pipe-and-cancel bindings
  that pipe through osc52-copy.sh in both configs
- Update update.ts and setup.ts to install osc52-copy.sh to ~/.genie/

Closes #967
@coderabbitai

coderabbitai Bot commented Apr 2, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5b6bc25f-0d94-4e26-8e61-d1ecb030600a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/tmux-osc52-clipboard

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@namastex888
namastex888 merged commit 1007c0d into dev Apr 2, 2026
6 checks passed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request implements OSC 52 clipboard passthrough support for nested tmux sessions, which is particularly useful for clipboard operations over SSH. The changes include updating tmux configurations to use a new helper script, osc52-copy.sh, and ensuring this script is correctly installed and permissioned during setup and updates. Feedback on the helper script suggests piping data directly to base64 to avoid stripping trailing newlines and to improve memory efficiency for large buffers.

Comment on lines +6 to +7
buf=$(cat "$@")
encoded=$(printf '%s' "$buf" | base64 | tr -d '\n')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Capturing the input into a variable using buf=$(cat "$@") strips trailing newlines from the copied content, which is likely unintended for a clipboard helper. Additionally, for large clipboard buffers, it is more efficient to pipe the data directly to base64 to avoid unnecessary memory allocation in the shell.

Suggested change
buf=$(cat "$@")
encoded=$(printf '%s' "$buf" | base64 | tr -d '\n')
encoded=$(cat "$@" | base64 | tr -d '\n')

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 22aa551590

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const { resolve, dirname } = require('node:path') as typeof import('node:path');
const genieHome = process.env.GENIE_HOME ?? join(homedir(), '.genie');
const dest = join(genieHome, 'tmux.conf');
if (existsSync(dest)) return; // already installed

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Install OSC52 helper even when tmux.conf already exists

The early return on existing ~/.genie/tmux.conf prevents setup from installing ~/.genie/osc52-copy.sh, because the new helper-copy logic is placed after that return. This makes setup non-idempotent for the new clipboard path: if a user has a preexisting tmux config but is missing the helper script (for example after partial cleanup or a prior interrupted install), rerunning setup cannot repair clipboard copy bindings that now reference ~/.genie/osc52-copy.sh.

Useful? React with 👍 / 👎.

@namastex888
namastex888 deleted the fix/tmux-osc52-clipboard branch April 10, 2026 16:18
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