pi-copy-user-message
v1.0.25
Published
Deprecated pi extension for copying the most recent user message; use pi-copy-message instead
Maintainers
Readme
pi copy-user extension
Deprecated: use
pi-copy-messageinstead. It provides a searchable picker for copying raw user, assistant, and tool messages.
A tiny pi extension that adds a slash command for copying the most recent user message to your clipboard.
What it does
- Adds
/copy-user - Copies the text from the most recent user message in the current session
- Preserves line breaks between text blocks
- Uses the system clipboard when available and a terminal OSC 52 clipboard escape in interactive TTY sessions
- Avoids synchronous clipboard subprocesses in the
/copy-usercommand path - Does not fall back to an older message if the latest user message has no text
Install
Install it from npm with pi:
pi install npm:pi-copy-user-messageOr install it directly from GitHub with pi:
pi install https://github.com/fitchmultz/pi-copy-user-messageThen reload pi from inside the app with:
/reloadIf you prefer to load it directly from a local checkout during development, you can point pi at the package entrypoint:
pi -e ./extensions/copy-user-message.tsCompatibility
- Tested with pi 0.78.1
- Supported Node.js range for local repo tooling:
>=22.19.0 .nvmrcpins Node 22.19.0 for local development; CI verifies Node 22.x and 24.x
This package keeps @earendil-works/pi-coding-agent as a development dependency for local typechecking and tests and declares pi core packages as optional wildcard peers per current pi package guidance. That keeps installs forward-open for future pi releases: npm peer ranges should not block users from trying a newer pi, though runtime behavior is only verified against the tested baseline until a follow-up package release confirms it.
Usage
Once loaded, run:
/copy-userThe command will:
- copy the newest user message text to the clipboard
- show a warning if there are no user messages
- show a warning if the newest user message contains no text
Behavior notes
- Text-only by design: image-only user messages are not copied.
- If a user message contains multiple text blocks, they are joined with newlines.
- OSC 52 is only emitted in interactive TTY sessions, so print/RPC output stays clean.
- Clipboard command fallbacks run asynchronously so the slash-command path does not block the TUI event loop while utilities resolve or time out.
- On Linux-family environments, the extension tries
termux-clipboard-set, thenwl-copy, then X11 tools (xclip, thenxsel). - If no supported clipboard transport is available, the command reports an error instead of claiming success.
- The command is intentionally strict about “most recent” so it never copies an older user message by mistake.
Development
This repo includes a small regression test in:
tests/copy-user-message.test.ts
The test covers:
- latest text message
- latest image-only message
- latest whitespace-only message
- no user message at all
- actual
/copy-usercommand success, warning, and error paths - OSC 52 emission
- Linux clipboard fallback ordering
- X11
xselfallback afterxclip - macOS
pbcopyand Windowscliptransport selection - failed or unsupported clipboard transport cases
Files
extensions/copy-user-message.ts— publishable extension implementation.pi/extensions/copy-user-message.ts— thin project-local wrapper for auto-discovery in this repotests/copy-user-message.test.ts— regression test for message selection,/copy-usercommand behavior, and clipboard transport fallbacks
