When copying from Claude Code into the terminal or a text file, you get trailing whitespace, inconsistent indentation, and invisible non-breaking spaces that break things silently. I decided to fix this with a script (built with Claude Code of course, because I never remember how “sed” works). The script ( claude-clipboard-cleaner.sh ): #!/bin/bash # Cleans text copied from Claude Code before pasting. # Fixes: non-breaking spaces, bullet characters, common leading indentation, trailing whitespace. # Bound to Ctrl+Shift+X. Workflow: Shift+Ctrl+C, Ctrl+Shift+X, Ctrl+V. # Skip if clipboard is empty or non-text (e.g., images, files) content=$(xclip -selection clipboard -o 2>/dev/null) || exit 0 [ -z “$content” ] && exit 0 echo “$content” \ | sed ‘s/\xc2\xa0/ /g; s/●/ /g’ \ | python3 -c “import sys, textwrap; print(textwrap.dedent(sys.stdin.read()), end=‘’)” \ | sed ‘s/[[:space:]]*$//’ \ | xclip -selection clipboard -i Save it to ~/.local/bin/claude-clipboard-cleaner.sh and make it executable ( chmod +x ). Bind it to Ctrl+Shift+X as a global shortcut (Ubuntu 24.04, no restart needed): gsettings set org.gnome.settings-daemon.plugins.media-keys custom-keybindings \ “[‘/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/’]” gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybindings.custom0 \ name ‘Claude Clipboard Cleaner’ gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybindings.custom0 \ command “$HOME/.local/bin/claude-clipboard-cleaner.sh” gsettings set org.gnome.settings-daemon.plugins.media-keys.custom-keybindings.custom0 \ binding ‘<Ctrl><Shift>x’ Now it’s: Shift+Ctrl+C, Ctrl+Shift+X, Ctrl+V. Clean paste every time. Hope this helps someone. submitted by /u/yprez
Originally posted by u/yprez on r/ClaudeCode
