← Catalog

@nilskluewer/pi-copy-to-clipboard

A Pi extension that copies exact text, commands, and code to the system clipboard without executing it.

Extension

Install

Install with PiG

pig install npm:@nilskluewer/pi-copy-to-clipboard

Install with Pi

pi install npm:@nilskluewer/pi-copy-to-clipboard
Review before installing

Packages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.

Pi manifest JSON

The pi field of package.json.

{
  "extensions": [
    "./extensions/copy-to-clipboard.ts"
  ]
}

README

Written by the package's publisher, shown as published in version 1.1.0 (README.md). PiG does not review it.

@nilskluewer/pi-copy-to-clipboard

A Pi extension that lets the model copy exact text, commands, and code to the system clipboard without executing it.

This is useful with clipboard managers such as Maccy.

Install

Install the published npm package globally:

pi install npm:@nilskluewer/pi-copy-to-clipboard

Install directly from GitHub:

pi install git:github.com/nilskluewer/pi-copy-to-clipboard

Install from a local checkout:

pi install /path/to/pi-copy-to-clipboard

Run /reload after installing it in an existing Pi session.

Usage

Ask Pi explicitly to copy something:

Copy the exact Bash command from your previous response to my clipboard history. Do not execute it. Do not include the shell prompt, Markdown fences, or explanation.

The extension registers the copy_to_clipboard tool.

The tool accepts the exact text to copy and an optional label.

It preserves whitespace and newlines and never executes the supplied text. Text must be valid Unicode without embedded NUL characters.

Platform support

Requires Node.js 22.19 or later. No extra npm runtime dependencies are needed.

EnvironmentClipboard backendRequirements
macOSpbcopy with a UTF-8 localeIncluded with macOS; Maccy can record the result.
WindowsWindows PowerShell, then PowerShell 7 (pwsh.exe)Clipboard access and a permitted PowerShell process. No clip.exe fallback, to avoid Unicode corruption.
WSL 1 / 2Windows PowerShell via interop, then WSLg display toolsWindows interop enabled. Tries PATH, then the standard /mnt/c/Windows/... path. Custom Windows mount paths need a PATH entry.
Linux / WSLg — Waylandwl-copy, then X11 tools if a display is availableInstall wl-clipboard and allow access to the display.
Linux / WSLg — X11xclip, then xselInstall either tool and allow access to the display.
Termuxtermux-clipboard-setInstall the Termux:API app and termux-api package.
Headless / SSH / MoshOSC 52 terminal escape sequenceAn interactive terminal that supports and permits clipboard writes.

For Debian or Ubuntu desktops:

sudo apt install wl-clipboard xclip

Clipboard commands have a five-second timeout per attempt. Failed backends fall back to the next available backend. Cancelled calls stop without further attempts.

Terminal and remote sessions

If no OS clipboard command works, interactive sessions try OSC 52. SSH and Mosh sessions send OSC 52 directly to the client terminal. They do not change the server clipboard or wait for server-side display tools. Set PI_CLIPBOARD_OSC52=1 when a remote session has no SSH/Mosh environment markers.

Terminal delivery is unconfirmed: the tool asks you to paste to check it. It does not claim that the clipboard was updated. The limit is 75,000 bytes of UTF-8 text. Larger text can still use a local OS clipboard backend.

The extension wraps OSC 52 for tmux. Your tmux and terminal settings must allow passthrough and clipboard writes. Clipboard history recording depends on your clipboard manager.

RPC/JSON and print modes never emit clipboard escape sequences, even when stdout is a terminal. Local desktop clipboard writes can work in these modes, but headless or remote calls fail with a clear error if the client clipboard cannot be reached.

Development

Install without Pi's host-provided peer packages:

npm ci --omit=peer
npm test
npm run smoke

The smoke test loads the packed tarball in Pi and checks that the tool is registered. It needs a global Pi installation. For a separate Pi installation, set PI_SMOKE_CLI to its JavaScript CLI entry point.

Run real clipboard round-trip tests in a disposable desktop session. These tests replace its clipboard contents:

# Linux CI / headless machine; requires xvfb, xclip and xsel
xvfb-run -a npm run test:clipboard

# Windows, WSL, macOS, or a Wayland desktop
npm run test:clipboard

CI runs unit tests, real clipboard tests, and the package smoke test on Linux, macOS, and Windows. WSL routing is covered by unit tests; native WSL and Wayland round trips need those environments and are not part of the CI matrix.

Inspect the npm tarball without publishing it:

npm run pack:dry

Load the local extension temporarily:

pi -e .

License

MIT