Remove whitespace after copying Claude Code response

· 2 min read

I’ve gotten into a workflow with Claude Code where I’ll copy parts of the chat session, paste them into a new document, and then annotate them with comments before pasting back into the chat. It’s a great way to keep context and communicate precisely about what Claude suggested.

The problem is that when you copy text from Claude Code running in VS Code, you get these Unicode box-drawing characters and extra whitespace padding on each line. What looked clean in the terminal turns into a mess in your editor.

I asked Caleb Sima about this and he gave me a couple of suggestions. It came down to a pretty simple sed pipeline that I aliased to cleanpaste.

Here’s a quick video walking through the problem and the fix:

The problem

When you copy text from a Claude Code session in VS Code and paste it into a new buffer, you’ll see lines padded with special characters and irregular spacing. These are Unicode box-drawing characters that VS Code uses for the terminal UI. They make the output unreadable and difficult to annotate or paste back into a chat.

The fix

The solution uses macOS built-in tools: pbpaste to grab the clipboard contents, sed to strip the offending characters and trim extra spaces, and pbcopy to put the cleaned text back on the clipboard.

Add this alias to your ~/.zshrc:

alias cleanpaste='pbpaste | sed "s/[▏▕│┃]//g" | sed "s/[[:space:]]*$//" | pbcopy'

Here’s what each part does:

  • pbpaste — outputs the current clipboard contents
  • sed "s/[▏▕│┃]//g" — removes Unicode box-drawing characters globally
  • sed "s/[[:space:]]*$//" — trims trailing whitespace from each line
  • pbcopy — puts the cleaned result back on the clipboard

After adding the alias, either restart your shell or source your config:

source ~/.zshrc

Usage

  1. Copy text from your Claude Code session as usual
  2. Run cleanpaste in your terminal
  3. Paste — the text is now clean and ready to annotate or paste back into the chat

It’s a small fix but it made a real difference in my workflow. Anyway, just passing it along in case you run into the same issue.

← Back to all posts