Since my development environment is WSL, my projects are stored inside the WSL filesystem. When I open them from Windows File Explorer, the normal Open in VS Code option doesn't open the project in the WSL environment.
Normally, I have to open the project in a WSL terminal and run:
code .
This can be simplified by adding an Open in VS Code (WSL) option to the Windows context menu.
1. Create the Registry File
Create a file named:
open_in_vscode_wsl.reg
Open it with Notepad and add:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\shell\VSCodeWSL]
@="Open in VS Code (WSL)"
"Icon"="\"C:\\Users\\%USERNAME%\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\""
[HKEY_CLASSES_ROOT\Directory\shell\VSCodeWSL\command]
@="wsl.exe code ."
[HKEY_CLASSES_ROOT\Directory\Background\shell\VSCodeWSL]
@="Open in VS Code (WSL)"
"Icon"="\"C:\\Users\\%USERNAME%\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe\""
[HKEY_CLASSES_ROOT\Directory\Background\shell\VSCodeWSL\command]
@="wsl.exe code ."
Make sure the file is saved as .reg, not .reg.txt.
2. Apply the Registry Changes
Double-click:
open_in_vscode_wsl.reg
Confirm the Windows Registry prompts.
Now, when right-clicking a project folder in File Explorer, you will see:
Open in VS Code (WSL)
Selecting it opens the project in VS Code's WSL environment, equivalent to running:
code .
from the WSL terminal.