kovidgoyal/kitty · error

invalid --ssh-connection-data: need at least binary and host

Error message

invalid --ssh-connection-data: need at least binary and hostname

What it means

parse_conn_data requires the JSON array in --ssh-connection-data to contain at least two items: the ssh binary and the hostname. With fewer than 2 elements it rejects the input with this message.

Source

Thrown at kittens/remote_file/ssh.go:31

// Must match kittens/remote_file/main.py is_ssh_kitten_sentinel
const is_ssh_kitten_sentinel = `!#*&$#($ssh-kitten)(##$`

type SSHConnectionData struct {
	Binary           string
	Hostname         string
	Port             int
	IdentityFile     string
	IsSSHKitten      bool
	SSHKittenCmdline []string
}

func parse_conn_data(raw string) (*SSHConnectionData, error) {
	var items []any
	if err := json.Unmarshal([]byte(raw), &items); err != nil {
		return nil, fmt.Errorf("invalid --ssh-connection-data: %w", err)
	}
	if len(items) < 2 {
		return nil, fmt.Errorf("invalid --ssh-connection-data: need at least binary and hostname")
	}
	first, _ := items[0].(string)
	ans := &SSHConnectionData{}
	if first == is_ssh_kitten_sentinel {
		// Python: SSHConnectionData(sentinel, cli_data[-1], -1, identity_file=json.dumps(cli_data[1:]))
		// with the cmdline stripped of -t flags and its last two items.
		ans.IsSSHKitten = true
		ans.Hostname, _ = items[len(items)-1].(string)
		cmdline := make([]string, 0, len(items)-1)
		for _, x := range items[1:] {
			s, _ := x.(string)
			if s != "-t" {
				cmdline = append(cmdline, s)
			}
		}
		// Python: sk_cmdline[:-2] always removes last 2, or returns empty if fewer items
		if len(cmdline) >= 2 {
			cmdline = cmdline[:len(cmdline)-2]

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Include at least [ssh_binary, hostname] in the array
  2. Check the argument was not truncated by quoting/word-splitting
  3. Update test fixtures to include both elements

Example fix

// before
["/usr/bin/ssh"]
// after
["/usr/bin/ssh","user@host"]
Defensive patterns

Strategy: validation

Validate before calling

var items []any
if json.Unmarshal([]byte(raw), &items) == nil && len(items) >= 2 { /* ok */ }

Type guard

func hasBinaryAndHost(raw string) bool { var v []any; return json.Unmarshal([]byte(raw), &v) == nil && len(v) >= 2 }

Prevention

When it happens

Trigger: Passing a JSON array like ["/usr/bin/ssh"] or [] as --ssh-connection-data.

Common situations: Truncation of the argument by shell splitting or quoting bugs, or test fixtures that only include the binary.

Related errors


AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27). Data as JSON: /api/errors/54ab343f2856e4ed. Report an issue: GitHub.