pi-copy-user-message

pi extension that adds /copy-user to copy the most recent user message to your clipboard

Package details

extension

Install pi-copy-user-message from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:pi-copy-user-message
Package
pi-copy-user-message
Version
1.0.17
Published
May 2, 2026
Downloads
1,442/mo · 168/wk
Author
fitchmultz
License
MIT
Types
extension
Size
17.4 KB
Dependencies
0 dependencies · 1 peer
Pi manifest JSON
{
  "extensions": [
    "./extensions"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

pi copy-user extension

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-user command 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-message

Or install it directly from GitHub with pi:

pi install https://github.com/fitchmultz/pi-copy-user-message

Then reload pi from inside the app with:

/reload

If 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.ts

Compatibility

  • Tested with pi 0.72.0
  • Minimum Node.js for local repo tooling: >=20.6.0
  • .nvmrc pins Node 22 for local development; CI also verifies Node 20.x, 22.x, and 24.x

This package keeps @mariozechner/pi-coding-agent as a development dependency for local typechecking and tests and declares pi core packages as wildcard peers per current pi package guidance; it is intended to run inside pi's bundled extension runtime.

Usage

Once loaded, run:

/copy-user

The 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, then wl-copy, then X11 tools (xclip, then xsel).
  • 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-user command success, warning, and error paths
  • OSC 52 emission
  • Linux clipboard fallback ordering
  • X11 xsel fallback after xclip
  • macOS pbcopy and Windows clip transport 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 repo
  • tests/copy-user-message.test.ts — regression test for message selection, /copy-user command behavior, and clipboard transport fallbacks