Scapegoat TIL

TIL - Fix hanging kitty when using atotto/clipboard golang package

When using Go's popular atotto/clipboard package in Kitty terminal, the terminal would occasionally hang. This happens because the package defaults to xclip on Linux systems, which stays running in the background by design to serve clipboard content to other X applications.

The Fix

Simply remove xclip:

sudo apt remove xclip

The atotto/clipboard package will then fallback to xsel, which doesn't exhibit the same hanging behavior. Looking at the package's source code, it tries clipboard utilities in this order on Linux:

  1. Wayland: wl-copy/wl-paste (if WAYLAND_DISPLAY is set)
  2. X11: xclip
  3. X11: xsel
  4. Termux: termux-clipboard-get/set

Why This Works

By removing xclip, we force the package to use xsel, which has better terminal behavior while providing the same functionality. This is a clean solution that doesn't require any code changes in your Go applications.

Tags: #golang #terminal #linux #debugging