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

Function setClipboard

packages/@ant/ink/src/core/termio/osc.ts:164–184  ·  view source on GitHub ↗
(text: string)

Source from the content-addressed store, hash-verified

162 * outside tmux, DCS-wrapped inside).
163 */
164export async function setClipboard(text: string): Promise<string> {
165 const b64 = Buffer.from(text, 'utf8').toString('base64')
166 const raw = osc(OSC.CLIPBOARD, 'c', b64)
167
168 // Native safety net — fire FIRST, before the tmux await, so a quick
169 // focus-switch after selecting doesn't race pbcopy. Previously this ran
170 // AFTER awaiting tmux load-buffer, adding ~50-100ms of subprocess latency
171 // before pbcopy even started — fast cmd+tab → paste would beat it
172 // (https://anthropic.slack.com/archives/C07VBSHV7EV/p1773943921788829).
173 // Gated on SSH_CONNECTION (not SSH_TTY) since tmux panes inherit SSH_TTY
174 // forever but SSH_CONNECTION is in tmux's default update-environment and
175 // clears on local attach. Fire-and-forget.
176 if (!process.env['SSH_CONNECTION']) copyNative(text)
177
178 const tmuxBufferLoaded = await tmuxLoadBuffer(text)
179
180 // Inner OSC uses BEL directly (not osc()) — ST's ESC would need doubling
181 // too, and BEL works everywhere for OSC 52.
182 if (tmuxBufferLoaded) return tmuxPassthrough(`${ESC}]52;c;${b64}${BEL}`)
183 return raw
184}
185
186// Linux clipboard tool: undefined = not yet probed, null = none available.
187// Probe order: wl-copy (Wayland) → xclip (X11) → xsel (X11 fallback).

Callers 11

ConsoleOAuthFlowFunction · 0.90
handleSelectOptionFunction · 0.90
PassesFunction · 0.90
MCPRemoteServerMenuFunction · 0.90
copyOrWriteToFileFunction · 0.90
handleSelectFunction · 0.90
OAuthFlowStepFunction · 0.90
ArtifactsMenuFunction · 0.90
onSelectFunction · 0.90
REPLFunction · 0.90
copySelectionNoClearMethod · 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