{"id":13815667,"url":"https://github.com/chvolkmann/code-connect","last_synced_at":"2026-03-03T23:33:07.745Z","repository":{"id":40439019,"uuid":"338500770","full_name":"chvolkmann/code-connect","owner":"chvolkmann","description":"Open a file in your locally running Visual Studio Code instance from arbitrary terminal connections.","archived":false,"fork":false,"pushed_at":"2025-03-08T13:38:32.000Z","size":98,"stargazers_count":92,"open_issues_count":2,"forks_count":29,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-15T09:41:49.166Z","etag":null,"topics":["visual-studio-code","vscode","vscode-remote"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chvolkmann.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-02-13T05:01:39.000Z","updated_at":"2025-03-24T11:12:49.000Z","dependencies_parsed_at":"2025-05-15T09:46:46.780Z","dependency_job_id":null,"html_url":"https://github.com/chvolkmann/code-connect","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/chvolkmann/code-connect","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chvolkmann%2Fcode-connect","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chvolkmann%2Fcode-connect/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chvolkmann%2Fcode-connect/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chvolkmann%2Fcode-connect/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chvolkmann","download_url":"https://codeload.github.com/chvolkmann/code-connect/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chvolkmann%2Fcode-connect/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30065831,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-03T18:21:05.932Z","status":"ssl_error","status_checked_at":"2026-03-03T18:20:59.341Z","response_time":61,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["visual-studio-code","vscode","vscode-remote"],"created_at":"2024-08-04T04:03:50.953Z","updated_at":"2026-03-03T23:33:07.729Z","avatar_url":"https://github.com/chvolkmann.png","language":"Shell","funding_links":[],"categories":["Shell"],"sub_categories":[],"readme":"# code-connect\n\n![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/chvolkmann/code-connect?label=version\u0026style=flat-square)\n\nOpen a file in your locally running Visual Studio Code instance from arbitrary terminal connections.\n\n## Motivation\n\nVS Code supports opening files with the terminal using `code /path/to/file`. While this is possible in [WSL sessions](https://code.visualstudio.com/docs/remote/wsl) and [remote SSH sessions](https://code.visualstudio.com/docs/remote/ssh) if the integrated terminal is used, it is currently not possible for arbitrary terminal sessions, e.g. [Windows Terminal](https://github.com/microsoft/terminal) or [kitty](https://github.com/kovidgoyal/kitty).\n\nLet's say you have just SSH'd into a remote server using your favorite terminal and would like to view a webserver config in your local VS Code instance. So you type `code nginx.conf`, which doesn't work in this terminal. If you try to run `code nginx.conf` in the integrated terminal however, VS Code opens the file just fine.\n\nThe aim of this project is to make the `code` CLI available to _any_ terminal, not only to VS Code's integrated terminal. \n\n## Prerequisites\n\n- **Linux** - we make assumptions on where VS Code stores its data based on Linux\n\n  \u003e Macs could also support everything out of the box, confirmation needed. Please don't hesitate to come into contact if you have any information to share.\n\n- **Python 3.9+**\n- **socat** - used for checking whether a socket is alive\n  ```bash\n  apt-get install socat\n  ```\n\n### Visual Studio Code Server\n\nYou need to set up the server component of VS Code on the machine before using this utility. For this, [connect to your target in a remote SSH session](https://code.visualstudio.com/docs/remote/ssh).\n\nAfterwards, you should have a folder `.vscode-server` in your home directory.\n\n## Installation\n\n### [Fish](https://fishshell.com/)\n\n#### Installing\n\nWith [fisher](https://github.com/jorgebucaran/fisher)\n\n```fish\nfisher install chvolkmann/code-connect\n```\n\nThis downloads [`code_connect.py`](./bin/code_connect.py) along with two functions. See [`functions/code.fish`](./functions/code.fish) and [`functions/code-connect.fish`](./functions/code-connect.fish)\n\nYou can autocomplete the repository name in subsequent commands, e.g. `fisher update code\u003cTAB\u003e`\n\n#### Updating\n\n```fish\nfisher update chvolkmann/code-connect\n```\n\n#### Uninstalling\n\n```fish\nfisher remove chvolkmann/code-connect\n```\n\n### Bash\n\n#### Installing \u0026 Updating\n\nWith [`bash/install.sh`](./bash/install.sh)\n\n```bash\ncurl -sS https://raw.githubusercontent.com/chvolkmann/code-connect/main/bash/install.sh | bash\n```\n\nThis downloads [`code_connect.py`](./bin/code_connect.py) along with two scripts and sets up aliases in your `.bashrc` for you. See [`bash/code.sh`](./bash/code.sh) and [`bash/code-connect.sh`](./bash/code-connect.sh)\n\n#### Uninstalling\n\nWith [`bash/uninstall.sh`](./bash/uninstall.sh)\n\n```bash\ncurl -sS https://raw.githubusercontent.com/chvolkmann/code-connect/main/bash/uninstall.sh | bash\n```\n\nDeletes the aliases from `~/.bashrc` and removes the folder `~/.code-connect`\n\n## Usage\n\nUse `code` as you would normally!\n\nIf you have VS Code installed on your remote machine as well (i.e. a `code` executable already exists), you can use `code` for your local instance and `code-connect` for an IPC connected instance.\n\n```\nUsage: code [options][paths...]\n\nTo read from stdin, append '-' (e.g. 'ps aux | grep code | code -')\n\nOptions\n  -d --diff \u003cfile\u003e \u003cfile\u003e           Compare two files with each other.\n  -a --add \u003cfolder\u003e                 Add folder(s) to the last active window.\n  -g --goto \u003cfile:line[:character]\u003e Open a file at the path on the specified line and character position.\n  -n --new-window                   Force to open a new window.\n  -r --reuse-window                 Force to open a file or folder in an already opened window.\n  -w --wait                         Wait for the files to be closed before returning.\n  -h --help                         Print usage.\n\nTroubleshooting\n  -v --version Print version.\n  -s --status  Print process usage and diagnostics information.\n```\n\n## Changelog\n\nSee [CHANGELOG.md](./CHANGELOG.md)\n\n## How it works\n\n### VS Code Remote under the hood\n\nVS Code uses datagram sockets to communicate between a terminal and the rendering window.\n\nThe integrated terminal as well as the WSL terminal spawn an IPC socket. You also create one when connecting through a remote SSH session. These sockets can be found in the folders of VS Code Server.\n\nEach time you connect remotely, the VS Code client instructs the server to fetch the newest version of itself. These releases are stored in folders under `~/.vscode-server/cli/servers/Stable-*/`. The `code` executable can be found in `~/.vscode-server/cli/servers/Stable-*/bin/code`. To run it, the envvar `VSCODE_IPC_HOOK_CLI` needs to be set to the path of a socket.\n\nVS Code's IPC sockets are located under `/run/user/\u003cuserid\u003e/vscode-ipc-\u003cUUID\u003e.sock`, where `\u003cuserid\u003e` is the [current user's UID](https://en.wikipedia.org/wiki/User_identifier) and `\u003cUUID\u003e` is a unique ID. VS Code does not seem to clean up all stale connections, so some of these sockets are active, some are not.\n\nThus the first socket that is listening and that was accessed within a timeframe of 4 hours by default is chosen.\n\nVS Code communicates the presence of an active IPC connection with the environment variable `VSCODE_IPC_HOOK_CLI` which stores the path to the socket.\n\nYou can verify this by opening a connection to your remote machine. In one case, you use VS Code's integrated terminal. In the other case, you use any other terminal.\n\nRun\n\n```bash\necho $VSCODE_IPC_HOOK_CLI\n```\n\nwhich displays an output in the integrated terminal, but not on the other one.\n\nIn order, every socket is checked to see if it is listening. For this, the following snippet based on [this answer on StackOverflow](https://unix.stackexchange.com/a/556790) was used.\n\n```bash\nsocat -u OPEN:/dev/null UNIX-CONNECT:/path/to/socket\n```\n\nThis returns `0` if and only if there's something listening.\n\n### `code-connect` under the hood\n\nThe script `code_connect.py` performs all of the above steps and runs the VS Code `code` executable\nas a child process with `VSCODE_IPC_HOOK_CLI` set properly, making it a drop-in replacement for `code`.\n\nWhen we already have a `code` executable available, we don't need to search for it ourselves using `code_connect.py`. So we introduce two more scripts:\n\n- `code-connect`  \n  Direct alias to `code_connect.py`\n- `code`  \n  Checks whether there is a `code` executable locally installed already and tries to use it if available. Otherwise, `code-connect` will be used.\n\n## Contributing\n\nSee [CONTRIBUTING.md](./CONTRIBUTING.md)\n\n## Credit\n\n- Based on an [answer on StackOverflow](https://stackoverflow.com/a/60949722) by [stabledog](https://stackoverflow.com/users/237059/Stabledog)\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchvolkmann%2Fcode-connect","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchvolkmann%2Fcode-connect","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchvolkmann%2Fcode-connect/lists"}