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.
For anyone trying to follow this guide in tmux 3.5 -
terminal-overridesis a server option, so it should be-as(or even just-a, astmuxshould automatically recognize known options). And if you want to debug this interactively, you should detach and reattach - only at that momentterminal-overrideswill kick in (i.e. you can find them intmux infooutput). This is what worked for me: