How to Reset VS Code Remote Connections
Environment
Visual Studio Code
Remote SSH extension
Remote Tunnel extension
Linux/Unix remote systems
Issue
Unable to establish VS Code tunnel connection with error
could not fetch remote environment
Failed to connect to the remote extension host server (Error: WebSocket close with status code 1006)Fail to connect after updating local or remote VS Code version
Resolution
Tip
Try the quick clean-up steps below and retry establishing connection. If issues persist, follow the complete reset procedure.
Quick Clean-up
Note
You must terminate VS Code processes on all servers sharing the same $HOME
directory.
Terminate all VS Code server processes on the remote system
pgrep -u $USER -f '(code|node)\s' | xargs -r -t -i kill {}
Close VS Code on your local machine
Attempt to reestablish connection on remote as usual.
Hint
It is best to separate tunnel connections by hostname or identifiers to avoid conflicts in case of having multiple server instances running.
Here is an example of how to start a new tunnel with isolated configuration. You can
replace $(hostname) with any unique identifier.
code --use-version stable \
--user-data-dir ~/.vscode-server/vscode-$(hostname)/user-data \
--disable-telemetry tunnel \
--cli-data-dir ~/.vscode-server/vscode-$(hostname) \
--server-data-dir ~/.vscode-server/vscode-$(hostname)/server-data \
--extensions-dir ~/.vscode-server/vscode-$(hostname)/server-data/extensions
Complete Reset Procedure
If the quick solution doesn’t resolve the issue, follow these steps
Warning
This procedure will remove all VS Code configuration files and extensions. Ensure you have a backup of your settings and extensions before proceeding.
You will need to re-establish tunnels from scratch after following these steps.
Terminate all VS Code server processes on the remote system
Remove all VS Code configuration directories
rm -rf ~/.vscode*
Re-create tunnels using this best practice command
code --use-version stable \ --user-data-dir ~/.vscode-server/vscode-$(hostname)/user-data \ --disable-telemetry tunnel \ --cli-data-dir ~/.vscode-server/vscode-$(hostname) \ --server-data-dir ~/.vscode-server/vscode-$(hostname)/server-data \ --extensions-dir ~/.vscode-server/vscode-$(hostname)/server-data/extensions
Attempt to reestablish connection on remote as usual.
Root Cause
VS Code remote sessions can leave behind stale processes and configuration files when connections fail. These remnants can interfere with new connection attempts.
It is also a known bug that updating VS Code can cause connection issues due to version mismatch between local and remote instances.