Better Clipboard Handling in Claude Code

A plugin that makes clipboard operations in Claude Code more reliable and natural to use.

Better Clipboard Handling in Claude Code

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

PlatformCopyPaste
macOSpbcopypbpaste
Linux (Wayland)wl-copywl-paste
Linux (X11)xclipxclip -o
WSLclip.exepowershell.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.

More Articles

Generate Commit Messages with Ollama in Neovim

Generate Commit Messages with Ollama in Neovim

Generate conventional commit messages from staged diffs using Ollama. Run it locally for privacy and offline, or use cloud models for speed.

Adding Umami analytics to the OpenClaw morning brief

Adding Umami analytics to the OpenClaw morning brief

An agent skill that fetches traffic data from Umami, and how it fits into a daily automated briefing.

Setting up Google Calendar sync for OpenClaw

Setting up Google Calendar sync for OpenClaw

How I set up read-only Google Calendar sync for my personal AI assistant running on a home server VM.

Get notified when Claude Code needs your input

Get notified when Claude Code needs your input

Stop constantly checking your terminal. Set up notifications that alert you when Claude Code is ready for your input.

Auto-format generated Code with Claude Code Hooks

Auto-format generated Code with Claude Code Hooks

How to set up a PostToolUse hook in Claude Code to automatically run prettier after every file edit or write operation.

PWA Web Share Target on Android: The Absolute URL Fix

PWA Web Share Target on Android: The Absolute URL Fix

Getting the Web Share Target API to work on Android PWAs can be frustrating. Your manifest looks correct, but the app never appears in the share sheet. Here is what finally worked.

Standard function keys on external keyboards in MacOS

Standard function keys on external keyboards in MacOS

Configure Karabiner Elements to use standard function keys on external keyboards while keeping media keys on your MacBook.

How to Clear Cloudflare Cache using a webhook

How to Clear Cloudflare Cache using a webhook

Automatically purge Cloudflare cache using webhooks and API tokens.

Monitoring Cron Jobs with Notifery

Monitoring Cron Jobs with Notifery

Stop silent cron job failures from catching you off guard.