Skip to content

Instantly share code, notes, and snippets.

Created Nov 29, 2017
What would you like to do?
tmux + mosh OSC 52 clipboard paste hack


Now tmux, mosh and iTerm2 support the OSC 52 sequence that enables clipboard sharing. However, there is a trap that prevents them from working together.

Mosh accepts OSC 52 sequences with the c; option. However, tmux doesn't send that option when it emits OSC 52 sequences, which means you cannot use tmux and mosh together with the default configuration.


You can override the OSC 52 sequence generated by tmux by adding the following line to your tmux.conf.

set-option -ag terminal-overrides ",xterm-256color:Ms=\\E]52;c;%p2%s\\7"

Instead of using the default Ms sequence Ms=\\E]52;%p1%s;%p2%s\\7", whose %p1%s; is the option part, this configuration forces use c; as the option value.

Note that xterm-256color must be replaced with your $TERM value.

Copy link

agriffis commented Feb 5, 2018

Thanks, just finished getting tmux + mosh + hterm (Chrome OS) cooperating with OSC 52, and this was a big help!

Copy link

tylerhoran commented Jun 15, 2018

@agriffis do you mind sharing your tmux.conf for tmux + mosh + chrome os ?

Copy link

agriffis commented Jul 3, 2018

@tylerhoran Here are the most interesting bits

# tmux-256color instead of screen-256color enables italics
set -g default-terminal "tmux-256color"

# Tc enables true color
set -ag terminal-overrides ",*256col*:colors=256:Tc"

# Ms modifies OSC 52 clipboard handling to work with mosh, see
set -ag terminal-overrides "vte*:XT:Ms=\\E]52;c;%p2%s\\7,xterm*:XT:Ms=\\E]52;c;%p2%s\\7"

# enable OSC 52 clipboard
set -g set-clipboard on

# use bracketed paste, if the running application (vim/emacs/weechat) has
# sent the terminal code to enable it.
bind-key ] paste-buffer -p

setw -g aggressive-resize on

set -s escape-time 0

Copy link

tylerhoran commented Jul 29, 2018

thanks @agriffis!

Copy link

gwicke commented Jul 17, 2019

PR for mosh that avoids the need for custom tmux settings: mobile-shell/mosh#1054

Copy link

dasizeman commented Sep 30, 2020

@yudai @tylerhoran @agriffis @gwicke Do you know what the minimum mosh version needed for this is? It's not working for me and I wish it did, I would love to get this working without having to build a custom mosh right now (but thanks for your work @gwicke!)

Copy link

agriffis commented Sep 30, 2020

@dasizeman There isn't a release of mosh with truecolor support. You need unreleased trunk. mobile-shell/mosh#974

If you're running Fedora, you can use my COPR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment