Skip to content

Add copy-last command to copy assistant messages to clipboard#583

Open
backnotprop wants to merge 2 commits intomainfrom
claude/add-copy-last-message-e4FLB
Open

Add copy-last command to copy assistant messages to clipboard#583
backnotprop wants to merge 2 commits intomainfrom
claude/add-copy-last-message-e4FLB

Conversation

@backnotprop
Copy link
Copy Markdown
Owner

Summary

This PR adds a new copy-last command that copies the last rendered assistant message to the system clipboard, complementing the existing annotate-last functionality. The command works across Claude Code, Copilot CLI, and other integrations without opening any UI.

Key Changes

  • New clipboard utility (packages/server/clipboard.ts): Cross-platform clipboard support for macOS (pbcopy), Windows (clip.exe), WSL, and Linux (wl-copy/xclip/xsel)

  • Two new CLI modes in apps/hook/server/index.ts:

    • copy-last: Copies the last message from standard Plannotator sessions using the same lookup logic as annotate-last
    • copilot-copy-last: Copies the last message from Copilot CLI sessions
  • New slash commands:

    • /plannotator-copy-last for Claude Code (in both hook and copilot apps)
    • Registered in installation scripts (install.sh, install.ps1, install.cmd)
  • Updated CLI help and tests: Added copy-last to the help text and updated test assertions to verify the new command files are installed

Implementation Details

  • The copy-last command reuses the existing message lookup infrastructure (getLastRenderedMessage, getLastCodexMessage, getLastCopilotMessage) to find the target message
  • Clipboard writing is handled asynchronously with proper error handling and platform detection
  • The command outputs the number of characters copied and exits with appropriate status codes
  • Installation scripts create the necessary slash command definition files for all supported platforms

https://claude.ai/code/session_01J3fNDB7ika2PdUdRMdrmHp

claude added 2 commits April 18, 2026 03:58
Copies the last rendered assistant message to the system clipboard.
Reuses the annotate-last session-log lookup (PPID → CWD slug → ancestor
walk for Claude Code; CODEX_THREAD_ID for Codex; session dir for
Copilot CLI) but skips the UI and writes straight to the clipboard.

- Adds cross-platform clipboard helper (pbcopy / clip.exe / wl-copy,
  xclip, xsel fallback / clip.exe under WSL)
- Adds `plannotator copy-last` and `plannotator copilot-copy-last`
  subcommands
- Registers the /plannotator-copy-last slash command in the Claude Code
  and Copilot plugins plus all three install scripts and their tests
Registers the Pi command that mirrors /plannotator-copy-last in the
Claude Code and Copilot CLI plugins. Pi runs on Node, so the clipboard
helper was refactored to drop its Bun.file dependency (inline WSL
detection via fs.readFileSync) and vendored into apps/pi-extension/
generated/ via vendor.sh — the same reuse pattern used for other
shared server utilities.

The Pi handler reads the last assistant message from the session
manager (same source as /plannotator-last) and writes it to the
system clipboard, surfacing success / failure through ctx.ui.notify.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants