Better Clipboard Handling in Claude Code
A plugin that makes clipboard operations in Claude Code more reliable and natural to use.
Claude Code can already use your clipboard through bash commands like pbcopy and pbpaste. But it doesn’t always think to use them, and when it does, things can go wrong with special characters and multi-line content.
This plugin fixes that by teaching Claude Code to handle clipboard operations reliably.
The Problems
Discoverability - Ask Claude Code to “copy that to my clipboard” and it might just print the content instead. It doesn’t always connect natural language to the right bash commands.
Special characters - Using echo to pipe content to pbcopy breaks when your text contains backslashes, quotes, or escape sequences. Code snippets and error messages often do.
Cross-platform - pbcopy only works on macOS. Linux users need xclip or wl-copy, WSL users need clip.exe. Claude Code doesn’t always pick the right one.
The Fix
A plugin that handles all of this:
claude plugin marketplace add martinhjartmyr/mh-cc-plugins
claude plugin install clipboard@mh-cc-plugins
What Changes
Natural language works - Say “copy that” or “what’s in my clipboard” and Claude Code knows what to do.
Special characters handled - Uses printf and heredocs instead of echo, so code snippets copy correctly.
Platform detection - Automatically picks the right clipboard command for your system.
Using It
Just ask naturally:
- “copy that to clipboard”
- “generate a commit message and copy it”
- “paste and format as JSON”
Or use slash commands for explicit control:
/clipboard:copy <content>
/clipboard:paste
How the Plugin Works
This plugin consists of two types of components:
Commands - Slash commands you invoke explicitly: /clipboard:copy and /clipboard:paste.
Skills - Natural language triggers that activate automatically:
clipboard-copy- Activates on phrases like “copy that”, “put in clipboard”, or “I want to paste this somewhere”clipboard-paste- Activates on phrases like “what’s in my clipboard”, “paste from clipboard”, or “use what I copied”
Each skill contains instructions that teach Claude Code how to handle the operation correctly - which bash commands to use, how to detect the platform, and how to handle special characters safely.
Platform Support
| Platform | Copy | Paste |
|---|---|---|
| macOS | pbcopy | pbpaste |
| Linux (Wayland) | wl-copy | wl-paste |
| Linux (X11) | xclip | xclip -o |
| WSL | clip.exe | powershell.exe Get-Clipboard |
Source Code
The plugin is open source: github.com/martinhjartmyr/claude-plugin-clipboard
Part of my Claude Code plugin collection at martinhjartmyr/mh-cc-plugins.
Both repos can serve as examples if you want to create your own plugins or set up a marketplace to share them with others.