Skip to content

Instantly share code, notes, and snippets.

@mbartelsm
Last active April 13, 2025 11:45
Show Gist options
  • Save mbartelsm/be2a8ea761e5358cd04e3777d107b186 to your computer and use it in GitHub Desktop.
Save mbartelsm/be2a8ea761e5358cd04e3777d107b186 to your computer and use it in GitHub Desktop.
VSCode context menu to open WSL

I'm tired of always struggling to open a folder in VSCode using WSL. You normally have to open the current folder in Code, wait for it to load, then reopen in the remote, which closes and reopens Code, so you have to wait for it to load everything once more. The alternative is to open a WSL shell, which takes it's good time too, navigate via the terminal to the folder you want, then open Code.

I just want to right click and be done. So I arranged a little something.

DISCLAIMER Before you proceed, back up your registry. If something breaks, that's on you for not having a backup.

This registry file will delete the current context menu entry for VSCode and replace is with a submenu that lets you choose wether to open it up normally, or via WSL. It only works when right clicking on a folder or on the background.

Something you might want to do before running it is to verify that the installation paths are the same ones you have in your set-up. If you don't have WSL in your PATH, you will either need to edit the file, or add it. This also assumes that Code is on your path on the WSL side of things, so check up on that.

If you don't want a sub-menu, there are plenty of guides online on how to add a context-menu entry.

Windows Registry Editor Version 5.00
; Delete old entries
[-HKEY_CLASSES_ROOT\Directory\shell\VSCode]
[-HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode]
; Add a sub-menu for right click on a folder
[HKEY_CLASSES_ROOT\Directory\shell\VSCode]
"MUIVerb"="Visual Studio Code"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\VSCode"
"Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe"
; Add a sub-menu for right click on the background
[HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode]
"MUIVerb"="Visual Studio Code"
"ExtendedSubCommandsKey"="Directory\\ContextMenus\\VSCode"
"Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe"
[HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode]
[HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode\shell]
; Set up text and icons
[HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode\shell\open]
"MUIVerb"="Open folder"
"Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe"
[HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode\shell\openwsl]
"MUIVerb"="Open folder in WSL"
"Icon"="C:\\Program Files\\Microsoft VS Code\\Code.exe"
; Set up commands
[HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode\shell\open\command]
@="\"C:\\Program Files\\Microsoft VS Code\\Code.exe\" \"%V\""
[HKEY_CLASSES_ROOT\Directory\ContextMenus\VSCode\shell\openwsl\command]
@="wsl.exe --cd \"%V\" code ."
; This will open the current folder WSL-side, and then run code from there
@matuszykrafa
Copy link

https://github.com/matuszykrafa/open-with-code-in-wsl
If you want to open a file in WSL, here you go
sample

@Ripper346
Copy link

Do you think it is possible to add another one that opens the folder in its default dev container?

@stalingino
Copy link

stalingino commented Aug 19, 2023

A quick alternate would be to open the directory and type below in the address bar and press enter:

wsl code .

Just typing wsl would open the current directory in WSL bash.
Typing pwsh would open windows powershell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment