MCPcopy
hub / github.com/codeaashu/claude-code / setClipboard

Function setClipboard

src/ink/termio/osc.ts:138–158  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

136 * outside tmux, DCS-wrapped inside).
137 */
138export async function setClipboard(text: string): Promise<string> {
139 const b64 = Buffer.from(text, 'utf8').toString('base64')
140 const raw = osc(OSC.CLIPBOARD, 'c', b64)
141
142 // Native safety net — fire FIRST, before the tmux await, so a quick
143 // focus-switch after selecting doesn't race pbcopy. Previously this ran
144 // AFTER awaiting tmux load-buffer, adding ~50-100ms of subprocess latency
145 // before pbcopy even started — fast cmd+tab → paste would beat it
146 // (https://anthropic.slack.com/archives/C07VBSHV7EV/p1773943921788829).
147 // Gated on SSH_CONNECTION (not SSH_TTY) since tmux panes inherit SSH_TTY
148 // forever but SSH_CONNECTION is in tmux's default update-environment and
149 // clears on local attach. Fire-and-forget.
150 if (!process.env['SSH_CONNECTION']) copyNative(text)
151
152 const tmuxBufferLoaded = await tmuxLoadBuffer(text)
153
154 // Inner OSC uses BEL directly (not osc()) — ST's ESC would need doubling
155 // too, and BEL works everywhere for OSC 52.
156 if (tmuxBufferLoaded) return tmuxPassthrough(`${ESC}]52;c;${b64}${BEL}`)
157 return raw
158}
159
160// Linux clipboard tool: undefined = not yet probed, null = none available.
161// Probe order: wl-copy (Wayland) → xclip (X11) → xsel (X11 fallback).

Callers 10

ConsoleOAuthFlowFunction · 0.85
handleSelectOptionFunction · 0.85
PassesFunction · 0.85
MCPRemoteServerMenuFunction · 0.85
copySelectionNoClearMethod · 0.85
copyOrWriteToFileFunction · 0.85
handleSelectFunction · 0.85
OAuthFlowStepFunction · 0.85
onSelectFunction · 0.85
REPLFunction · 0.85

Calls 5

oscFunction · 0.85
copyNativeFunction · 0.85
tmuxLoadBufferFunction · 0.85
tmuxPassthroughFunction · 0.85
toStringMethod · 0.65

Tested by

no test coverage detected