{"record":{"id":"01d5312e02ce7dce","repo":"cli/cli","slug":"error-opening-visual-studio-code-w","errorCode":null,"errorMessage":"error opening Visual Studio Code: %w","messagePattern":"error opening Visual Studio Code: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/cmd/codespace/code.go","lineNumber":58,"sourceCode":"\t}\n\n\tbrowseURL := vscodeProtocolURL(codespace.Name, useInsiders)\n\tif useWeb {\n\t\tbrowseURL = codespace.WebURL\n\t\tif useInsiders {\n\t\t\tu, err := url.Parse(browseURL)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tq := u.Query()\n\t\t\tq.Set(\"vscodeChannel\", \"insiders\")\n\t\t\tu.RawQuery = q.Encode()\n\t\t\tbrowseURL = u.String()\n\t\t}\n\t}\n\n\tif err := a.browser.Browse(browseURL); err != nil {\n\t\treturn fmt.Errorf(\"error opening Visual Studio Code: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc vscodeProtocolURL(codespaceName string, useInsiders bool) string {\n\tapplication := \"vscode\"\n\tif useInsiders {\n\t\tapplication = \"vscode-insiders\"\n\t}\n\treturn fmt.Sprintf(\"%s://github.codespaces/connect?name=%s&windowId=_blank\", application, url.QueryEscape(codespaceName))\n}\n","sourceCodeStart":40,"sourceCodeEnd":71,"githubUrl":"https://github.com/cli/cli/blob/0eeec0b92edbe70199f9768522f831d3534f41ad/pkg/cmd/codespace/code.go#L40-L71","documentation":"`gh codespace code` failed at the final step: after building the vscode.dev (or insider) browse URL, the OS-default browser could not be opened via browser.Browse. Everything upstream (codespace resolution) succeeded; only launching the browser failed.","triggerScenarios":"No default browser configured on the machine (common on headless Linux/servers/containers), BROWSER env var pointing to a broken executable, or the open/exec of the browser binary returning an error.","commonSituations":"SSH into a remote box or CI container without a display server or xdg-open; BROWSER set to a nonexistent command; Windows/WSL browser registration issues.","solutions":["Set BROWSER to a working executable, e.g. `BROWSER=firefox gh codespace code -c NAME`, or use `--browser` if a specific browser flag exists for your version.","On headless machines use the web flow elsewhere or forward X; alternatively run `gh codespace ssh` instead.","Check xdg-settings/getters: `xdg-settings get default-web-browser` on Linux.","Print the URL instead of opening: open the vscode.dev URL manually if the command prints it."],"exampleFix":"# before (headless box)\ngh codespace code -c monalisa-dotfiles-abc123\n# error opening Visual Studio Code: exec: \"xdg-open\": executable file not found in $PATH\n\n# after\nBROWSER=none gh codespace code -c monalisa-dotfiles-abc123   # or copy the URL manually\ngh codespace ssh -c monalisa-dotfiles-abc123                  # terminal alternative","handlingStrategy":"fallback","validationCode":"# Detect headless environments before invoking the browser flow\nif [ -z \"$DISPLAY\" ] && [ -z \"$WAYLAND_DISPLAY\" ] && [ -z \"$BROWSER\" ]; then\n  echo \"no GUI browser available\" >&2; exit 1\nfi","typeGuard":null,"tryCatchPattern":"gh codespace code -c \"$NAME\" || {\n  # fallback: open the URL manually or use the terminal path\n  gh codespace ssh -c \"$NAME\"\n}","preventionTips":["Set BROWSER to a known-good executable in scripts.","Prefer `gh codespace ssh` in headless/SSH contexts.","Keep xdg-open installed and a default browser registered on desktop Linux."],"tags":["codespace","browser","desktop-integration"],"backgroundTag":null,"analyzedSha":"0eeec0b92edbe70199f9768522f831d3534f41ad","analyzedAt":"2026-08-15T12:31:05.478Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}