Open folder in VS Code from Windows Explorer
Asked Answered
S

8

59

While installing the VS Code, we get an option to tick for Open with Code. I gave the tick mark for only files but not for folders. So how to turn it on after installation?

When I'm opening a file:

When I'm opening a file(IMG)

When I'm opening a folder :

(IMG)

I want the Open with Code option on right-click in the folder just like it shows on files.

Supposing answered 21/10, 2020 at 10:10 Comment(3)
This post may helpNorrisnorrv
All three answers by Erick Petrucelli, dqureshiumar and Carlos Luis Rivera work.Octamerous
Note that is the way to do if you downloaded the zip (portable) code instead of running the installer.Snake
H
105

TLDR

Save this contents to a new .reg file:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\VSCode]
@="Open with Code"
"Icon"="\"%LocalAppData%\\Programs\\Microsoft VS Code\\Code.exe\""

[HKEY_CLASSES_ROOT\Directory\shell\VSCode\command]
@=hex(2):22,00,25,00,4c,00,6f,00,63,00,61,00,6c,00,41,00,70,00,70,00,44,00,61,\
  00,74,00,61,00,25,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,73,00,\
  5c,00,4d,00,69,00,63,00,72,00,6f,00,73,00,6f,00,66,00,74,00,20,00,56,00,53,\
  00,20,00,43,00,6f,00,64,00,65,00,5c,00,43,00,6f,00,64,00,65,00,2e,00,65,00,\
  78,00,65,00,22,00,20,00,22,00,25,00,56,00,22,00,00,00

Run the file and that's it.

Detailed

The answer from @dqureshiumar is correct, if you already checked that option during VS Code installation. But maybe you haven't checked it and don't want or can't reinstall it right now. Or maybe you just need more flexibility about the actions shown when right clicking a folder.

So of course we have a lot of people in comments and/or in other answers here talking about how easy it's to run the installer again. Yes, it is! Just use this solution if you want to do by hand what the installer will do for you, or use this solution as a learning opportunity to understand better how Windows manage context menu actions on directories, to be able to customize what you want for other use cases.

Disclaimer

Dealing with regedit can be dangerous. Use it with caution and create a .reg backup before starting if you're not so experienced on it.

Instructions

So you are able to create your own folder actions at the Windows Registry:

  • Press ⊞ Win + R and type regedit.
  • Navigate to the path HKEY_CLASSES_ROOT\Directory\shell.
  • Right click and create a new Key named vscode.
  • At the (Default) REG_SZ, put the desired text, like Open with Code.
  • Optionally, create an Icon key pointing to the Code.exe path (most likely "C:\Users\%UserName%\AppData\Local\Programs\Microsoft VS Code\Code.exe").

At this point, something like this:

Added new Directory/shell Action on regedit

Yet inside regedit, go ahead:

  • Create another new Key named command inside the vscode one.
  • At the (Default) REG_SZ, put the action to open the current path ("%V") based on your Code.exe path (most likely "C:\Users\%UserName%\AppData\Local\Programs\Microsoft VS Code\Code.exe" "%V").

Now, see something like this:

Added new command key inside vscode action on regedit

Finally, go ahead to Windows Explorer and right click any folder:

enter image description here

It's updated on demand, so you can also play with text, icon and command to try your own custom actions, if you want. The VS Code Command Line Interface reference could be helpful if you want to play with another possibilites, like adding the clicked folder to the current Workspace.

Permission Error

If you try to "Open with Code" a folder from a different drive than your VS Code installation (most likely C:), maybe you'll receive an error message starting with "You do not have permission to...". This is because a REG_SZ record can be wrongly interpreted in cases it contains multiple strings inside the value. Unfortunately the Windows Registry Editor UI doesn't offer a way to convert REG_SZ to REG_EXPAND_SZ on (Default) keys. If you face this problem, just use my TLDR solution with the hex(2) value, which will automatically create the REG_EXPAND_SZ type.

Hamitosemitic answered 21/10, 2020 at 10:59 Comment(10)
Fantastic! This words great. You could even replace the "%LocalAppData%\Programs\Microsoft VS Code\Code.exe" to "C:\Program Files\Microsoft VS Code\Code.exe". Nice work ErickStanfield
@SameerPusegaonkar in fact it depends on how you installed VS Code. I installed for the current user only, so it's inside "%LocalAppData%\Programs\Microsoft VS Code\Code.exe". For a multi-user install, it's most probably inside "C:\Program Files\Microsoft VS Code\Code.exe" as you already pointed.Hamitosemitic
@ErickPetrucelli Great.. ThanksLeash
@ErickPetrucelli could you please tell me what does "%1" stands for in "%LocalAppData%\Programs\Microsoft VS Code\Code.exe" "%1"Czechoslovak
@Czechoslovak it's passing a code.exe command line option to the define that the path to open is the first argument (%1) sent by file explorer. More on this syntax that comes from DOS age here: tek-tips.com/viewthread.cfm?qid=382878.Hamitosemitic
I have this problem when I try to open a folder with "Open with Code": "windows cannot access the specified device path or file you may not have appropriate permissions" is it necessary to give permissions?Mylan
@Mylan I had this same problem. I was able to solve by manually entering in the path to code.exe. Which looked like this "C:\Users\TechnoM4ncer\AppData\Local\Programs\Microsoft VS Code\Code.exe" "%1" Just replace my username with yours and that should fix the issue.Py
I tried this method but every time I right-click and click "Open with Code", I get an error along the lines of "You do not have permission to...". I finally used the next 30 secs to double click on the installer, check the 2 boxes to open in vs code, and done. I still upvoted this answer.Becharm
A nice quick way to get back the 'Open with Code' options in the installer is to use WinGet to request an interactive installation like this: winget install --id Microsoft.VisualStudioCode -iCeramic
I installed Code with Chocolatey, and therefore I wasn't given this option at installation time. Thank you very much for a simple fix of something that has been annoying me for months! Glad I have finally searched about this issue.Curitiba
G
25

As Marc L. has already pointed out, reinstallation is the easiest way to activate Open with Code. The reinstallation does not affect the settings and extensions you previously had.

  1. Just download VScode here;
  2. Run the installer;
  3. In the installer, click to activate the following two options:
    • Add "Open with Code" action to Windows Explorer file context menu
    • Add 'Open with Code" action to Windows Explorer directory context menu
Goatee answered 8/8, 2021 at 1:6 Comment(0)
J
14

During the installation you have to check the option to Open With Code.

To open a folder in Visual Studio Code there are two ways possible.

  1. Right Click on the Folder on inside the folder area and Click on open with code.

enter image description here

  1. The Second way to open with code can be using terminal. Go to your folder path using cmd and just hit code .. Your folder will be open in Visual Studio Code

enter image description here

Jecoa answered 21/10, 2020 at 10:21 Comment(3)
I enjoy mucking about in the registry as much as the next guy, but let's honest: VS Code is lightweight enough that reinstallation is the far easier solution.Glynnis
To open your folder in command line just type cmd in the folder address bar.Octamerous
This works for the old context menu, not for Windows 11. Any workaround?Brainless
H
8

much more sample way to do that (same solution of @Erick Petrucelli)

  1. Create a file with ".reg" extension
  2. Apply the following code
Windows Registry Editor Version 5.00

; Open files [HKEY_CLASSES_ROOT\*\shell\Open with VS Code] @="Edit with VS Code"
"Icon"="%LocalAppData%\\Programs\\Microsoft VS Code\\Code.exe,0"

[HKEY_CLASSES_ROOT\*\shell\Open with VS Code\command]
@="\"%LocalAppData%\\Programs\\Microsoft VS Code\\Code.exe\" \"%1\""

; This will make it appear when you right click ON a folder
; The "Icon" line can be removed if you don't want the icon to appear
[HKEY_CLASSES_ROOT\Directory\shell\vscode]
@="Open in VS Code"
"Icon"="\"%LocalAppData%\\Programs\\Microsoft VS Code\\Code.exe\",0"

[HKEY_CLASSES_ROOT\Directory\shell\vscode\command]
@="\"%LocalAppData%\\Programs\\Microsoft VS Code\\Code.exe\" \"%1\""

; This will make it appear when you right click INSIDE a folder
; The "Icon" line can be removed if you don't want the icon to appear
[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode]
@="Open in VS Code"
"Icon"="\"%LocalAppData%\\Programs\\Microsoft VS Code\\Code.exe\",0"

[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode\command]
@="\"%LocalAppData%\\Programs\\Microsoft VS Code\\Code.exe\" \"%V\""
  1. Open that file by double click / hit Enter. It will ask for permission, after that, it will apply a new context to right click in Windows Explorer. It will save time and improve productivity.

source

Handsaw answered 1/4, 2022 at 18:41 Comment(1)
This currently only shows icon and will not execute VSCode. It needs the hex REG_EXPAND_SZ trick from @Erick PetrucelliLustrum
G
2

Save all your works and re-run your vs-code set up file, that's the .exe program, then tick all the checkboxes at the add desktop to the Taskbar region automatically, once you have done done, click on install, all your histories will be restored back... vs-code is just soft

Grumous answered 22/7, 2022 at 15:9 Comment(0)
F
0

I have an easy decision of the problem with @Erick Petrucelli method.

Just edit this step (described by @Erick Petrucelli):

Create another new Key named command inside the vscode one. At the (Default) REG_SZ, put the action to open the current path ("%1") based on your Code.exe path (most likely "%LocalAppData%\Programs\Microsoft VS Code\Code.exe" "%1"

Instead of "%1" you should set "."

Now, it should work. Enjoy!

Fye answered 19/4, 2022 at 22:4 Comment(0)
M
0

For VSCodium add this text to created file. (AddVscodiumToPath.reg)

    Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\VSCode]
@="Open with Code"
"Icon"="\"C:\\Program Files\\VSCodium\\VSCodium.exe\""

[HKEY_CLASSES_ROOT\Directory\shell\VSCode\command]
@=hex(2):22,00,43,00,3a,00,5c,00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,20,\
  00,46,00,69,00,6c,00,65,00,73,00,5c,00,56,00,53,00,43,00,6f,00,64,00,69,00,\
  75,00,6d,00,5c,00,56,00,53,00,43,00,6f,00,64,00,69,00,75,00,6d,00,2e,00,65,\
  00,78,00,65,00,22,00,20,00,22,00,25,00,56,00,22,00,00,00
Michaelson answered 24/3, 2024 at 10:39 Comment(0)
T
0

If you installed vscode via scoop the installer has two registry files, install-context being Open with Code on contextual menu:

scoop install vscode
reg import "<SCOOP>\apps\vscode\current\install-context.reg"
reg import "<SCOOP>\apps\vscode\current\install-associations.reg"
Toler answered 3/7, 2024 at 15:2 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.