{"record":{"id":"96f7417881263e25","repo":"kovidgoyal/kitty","slug":"could-not-parse-delegate-command-v-with-error","errorCode":null,"errorMessage":"Could not parse delegate command: %#v with error: %w","messagePattern":"Could not parse delegate command: %#v with error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kittens/ssh/main.go","lineNumber":668,"sourceCode":"\t}\n\thost_opts, bad_lines, err := load_config(hostname_for_match, uname, overrides)\n\tif err != nil {\n\t\treturn 1, err\n\t}\n\t// check the secrets syntax here as askpass has no good way to report errors to\n\t// the user\n\tif err = resolve_secrets(host_opts, true); err != nil {\n\t\treturn 1, err\n\t}\n\tif len(bad_lines) > 0 {\n\t\tfor _, x := range bad_lines {\n\t\t\tfmt.Fprintf(os.Stderr, \"Ignoring bad config line: %s:%d with error: %s\", filepath.Base(x.Src_file), x.Line_number, x.Err)\n\t\t}\n\t}\n\tif host_opts.Delegate != \"\" {\n\t\tdelegate_cmd, err := shlex.Split(host_opts.Delegate)\n\t\tif err != nil {\n\t\t\treturn 1, fmt.Errorf(\"Could not parse delegate command: %#v with error: %w\", host_opts.Delegate, err)\n\t\t}\n\t\treturn 1, unix.Exec(utils.FindExe(delegate_cmd[0]), utils.Concat(delegate_cmd, ssh_args, server_args), os.Environ())\n\t}\n\tmaster_is_alive, master_checked := false, false\n\tvar control_master_args []string\n\tif host_opts.Share_connections {\n\t\tkpid, err := strconv.Atoi(os.Getenv(\"KITTY_PID\"))\n\t\tif err != nil {\n\t\t\treturn 1, fmt.Errorf(\"Invalid KITTY_PID env var not an integer: %#v\", os.Getenv(\"KITTY_PID\"))\n\t\t}\n\t\tcontrol_master_args, err = connection_sharing_args(kpid)\n\t\tif err != nil {\n\t\t\treturn 1, err\n\t\t}\n\t\tcmd = slices.Insert(cmd, insertion_point, control_master_args...)\n\t}\n\tuse_kitty_askpass := host_opts.Askpass == Askpass_native || (host_opts.Askpass == Askpass_unless_set && os.Getenv(\"SSH_ASKPASS\") == \"\")\n\tneed_to_request_data := true","sourceCodeStart":650,"sourceCodeEnd":686,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/ssh/main.go#L650-L686","documentation":"run_ssh shlex-splits the host's delegate command and the split itself failed, so the configured delegate (a command that replaces ssh, like mossh or et) could not be turned into an argv. The raw string and the parse error are included.","triggerScenarios":"A ssh kitten Delegate option whose value contains unbalanced quotes, stray backslashes, or other shell-lexing errors; shlex.Split returns an error for malformed quoting.","commonSituations":"Hand-edited kitty.conf/ssh config with missing closing quote ('delegate \"mossh'); Windows-style paths with backslashes; copy-pasting a shell line containing characters the simple lexer rejects; empty first token after a weird split.","solutions":["Check the Delegate value in your config for unmatched quotes/backslashes and fix them","Test the lexing: kitty +kitten ssh with the value echoed, or run shlex-equivalent (python3 -c 'import shlex; print(shlex.split(...))')","Quote the whole delegate command once and avoid nested quotes","After fixing, rerun the kitten to confirm exec proceeds"],"exampleFix":"# before\n.delegate \"my-wrapper --flag 'value\n# after\n.delegate \"my-wrapper --flag value\"","handlingStrategy":"validation","validationCode":"if _, err := shlex.Split(delegateCmd); err != nil {\n    // reject/repair the config line before running\n}","typeGuard":null,"tryCatchPattern":"if _, err := run_ssh(...); err != nil && strings.Contains(err.Error(), \"Could not parse delegate command\") {\n    // surface config file and line to the user\n}","preventionTips":["Lint delegate lines with shlex.Split at config load time","Keep delegate commands simple; avoid nested quotes","Test delegate values in a scratch config before committing"],"tags":["ssh-kitten","delegate","quoting","configuration"],"backgroundTag":"shell-quoting-parse-error","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}