{"record":{"id":"c1ac9827b33c55ad","repo":"kovidgoyal/kitty","slug":"invalid-kitty-pid-env-var-not-an-integer-v","errorCode":null,"errorMessage":"Invalid KITTY_PID env var not an integer: %#v","messagePattern":"Invalid KITTY_PID env var not an integer: %#v","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kittens/ssh/main.go","lineNumber":677,"sourceCode":"\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\n\tif use_kitty_askpass {\n\t\tneed_to_request_data = set_askpass(hostname_for_match, uname, overrides)\n\t}\n\tmaster_is_functional := func() bool {\n\t\tif master_checked {\n\t\t\treturn master_is_alive\n\t\t}\n\t\tmaster_checked = true\n\t\t// slices.Insert can mutate cmd's backing array in place; clone so cmd stays intact","sourceCodeStart":659,"sourceCodeEnd":695,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/ssh/main.go#L659-L695","documentation":"With ShareConnections enabled the kitten builds ssh ControlMaster arguments keyed by the parent kitty PID, reading KITTY_PID from the environment. strconv.Atoi failed, so the variable is missing/empty or non-numeric and connection sharing cannot be set up.","triggerScenarios":"run_ssh with host_opts.ShareConnections true while KITTY_PID is unset, empty, or contains non-digits — typically when the kitten is exec'd outside a kitty terminal or the env var was stripped.","commonSituations":"Running kitty +kitten ssh from a plain xterm/SSH session or cron/systemd; env -i or sanitizing wrappers dropping KITTY_PID; wrappers like env WORDSIZE changing the variable; older/newer kitty version mismatch between launcher and kitten.","solutions":["Run the kitten from inside a kitty window so KITTY_PID is set by the terminal","Verify: echo $KITTY_PID inside the same shell before invoking","Disable Share_connections for that host in ssh.conf if you must run outside kitty","Fix wrappers/scripts that scrub the environment (remove KITTY_PID from any unset list)"],"exampleFix":"# before (from a non-kitty terminal)\nkitty +kitten ssh user@host   # with share_connections yes\n# after\n# inside kitty:\nkitty +kitten ssh user@host\n# or in ssh.conf for that host:\nshare_connections no","handlingStrategy":"validation","validationCode":"if pid, err := strconv.Atoi(os.Getenv(\"KITTY_PID\")); err != nil || os.Getenv(\"KITTY_PID\") == \"\" {\n    // disable share_connections or bail with a clear message\n}","typeGuard":"func insideKitty() bool {\n    p := os.Getenv(\"KITTY_PID\")\n    _, err := strconv.Atoi(p)\n    return err == nil && p != \"\"\n}","tryCatchPattern":"if _, err := run_ssh(...); err != nil && strings.Contains(err.Error(), \"KITTY_PID\") {\n    // rerun without connection sharing\n}","preventionTips":["Only enable share_connections when launched from kitty","Ensure wrappers preserve KITTY_PID","Provide a fallback path when the env var is absent"],"tags":["ssh-kitten","environment-variable","connection-sharing"],"backgroundTag":"missing-env-var","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}