kovidgoyal/kitty · error
Invalid base64 encoded data from terminal with error: %w
Error message
Invalid base64 encoded data from terminal with error: %w
What it means
When reading the clipboard from the terminal, the kitten sends an OSC 52-style query and expects the reply base64-encoded. If the returned data cannot be base64-decoded, this error is raised. The terminal sent garbage instead of valid base64.
Source
Thrown at kittens/clipboard/legacy.go:198
var clipboard_contents []byte
lp.OnEscapeCode = func(etype loop.EscapeCodeType, data []byte) (err error) {
switch etype {
case loop.DCS:
if strings.HasPrefix(utils.UnsafeBytesToString(data), "1+r") {
lp.Quit(0)
}
case loop.OSC:
q := utils.UnsafeBytesToString(data)
if strings.HasPrefix(q, "52;") {
parts := strings.SplitN(q, ";", 3)
if len(parts) < 3 {
lp.Quit(0)
return
}
data, err := base64.StdEncoding.DecodeString(parts[2])
if err != nil {
return fmt.Errorf("Invalid base64 encoded data from terminal with error: %w", err)
}
clipboard_contents = data
lp.Quit(0)
}
}
return
}
esc_count := 0
lp.OnKeyEvent = func(event *loop.KeyEvent) error {
if event.MatchesPressOrRepeat("ctrl+c") || event.MatchesPressOrRepeat("esc") {
if transmitting {
return nil
}
event.Handled = true
esc_count++
if esc_count < 2 {
key := "Esc"View on GitHub (pinned to 6d5d0c4406)
Solutions
- Run outside tmux/screen or enable proper escape-sequence passthrough
- Update kitty and the terminal emulator
- Check that shell integration/prompt isn't injecting escape codes that answer queries
Defensive patterns
Strategy: validation
Validate before calling
if _, err := base64.StdEncoding.DecodeString(parts[2]); err != nil {
return errors.New("terminal clipboard reply not base64; run inside kitty without multiplexer mangling")
} Try / catch
data, err := base64.StdEncoding.DecodeString(s)
if err != nil { return nil, fmt.Errorf("bad clipboard payload: %w", err) } Prevention
- Run clipboard get directly in kitty, not through tmux/screen
- Keep shell prompt escape codes from answering terminal queries
When it happens
Trigger: Asking the terminal for clipboard contents (get mode) where the reply's third part fails base64.StdEncoding.DecodeString — e.g. corrupted or empty payload, or another program answered the query.
Common situations: Running inside tmux/screen that mangles DCS/OSC replies, shell prompt escape sequences interfering with terminal queries, non-kitty terminals with partial OSC 52 support.
Related errors
- Received incomplete data for clipboard
- Ignoring OSC 52 clipboard write request as it is not valid b
- Received OSC %s packet from terminal with invalid base64 enc
- Malformed OSC 5522: could not decode a metadata value. Error
- Malformed OSC 5522: read request payload is not valid base64
AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27).
Data as JSON: /api/errors/a6d0547d97cd178e.
Report an issue: GitHub.