How to add "Open Folder with VS Code" to the right-click menu in Windows 11

Windows 11: Add “Open with Visual Studio Code” to the Right-Click Context Menu

Expected Result

After completing the setup, you can open a directory in VS Code using either of the following two methods:

  1. Open a folder and right-click on an empty area inside it, then select “Open with Visual Studio Code.”
  2. Right-click directly on a folder and select “Open with Visual Studio Code.”

In Windows 11, menu items for traditional applications may appear under “Show more options.” You can also press Shift + F10 to open the full context menu.

How I Set It Up

First, I confirmed the actual installation path of VS Code:

C:\Users\www\AppData\Local\Programs\Microsoft VS Code\Code.exe

Then, I created two context menu entries under the current user’s registry:

Usage Scenario Registry Path Path Parameter Passed to VS Code
Right-click on an empty area inside a folder HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\VSCode %V, representing the currently opened directory
Right-click directly on a folder HKEY_CURRENT_USER\Software\Classes\Directory\shell\VSCode %1, representing the clicked folder

Using HKEY_CURRENT_USER affects only the current Windows user and typically does not require administrator privileges.

One-Click Setup Command

Open PowerShell, paste, and execute the following command:

$codeExe = "$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe"

if (-not (Test-Path -LiteralPath $codeExe)) {
    throw "VS Code not found: $codeExe. Please verify the VS Code installation path first."
}

# Right-click on an empty area inside an already-opened folder
$backgroundKey = 'Registry::HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\VSCode'
$backgroundCommandKey = "$backgroundKey\command"

New-Item -Path $backgroundCommandKey -Force | Out-Null
Set-Item -LiteralPath $backgroundKey -Value 'Open with Visual Studio Code'
New-ItemProperty `
    -LiteralPath $backgroundKey `
    -Name 'Icon' `
    -Value ('"' + $codeExe + '"') `
    -PropertyType String `
    -Force | Out-Null
Set-Item -LiteralPath $backgroundCommandKey -Value ('"' + $codeExe + '" "%V"')

# Right-click directly on a folder
$directoryKey = 'Registry::HKEY_CURRENT_USER\Software\Classes\Directory\shell\VSCode'
$directoryCommandKey = "$directoryKey\command"

New-Item -Path $directoryCommandKey -Force | Out-Null
Set-Item -LiteralPath $directoryKey -Value 'Open with Visual Studio Code'
New-ItemProperty `
    -LiteralPath $directoryKey `
    -Name 'Icon' `
    -Value ('"' + $codeExe + '"') `
    -PropertyType String `
    -Force | Out-Null
Set-Item -LiteralPath $directoryCommandKey -Value ('"' + $codeExe + '" "%1"')

Write-Host 'Setup completed.' -ForegroundColor Green

Key Parts of the Command

Taking the context menu entry for right-clicking on an empty area inside a folder as an example, the final launch command is:

"C:\Users\www\AppData\Local\Programs\Microsoft VS Code\Code.exe" "%V"
  • The first part is the full path to the VS Code executable.
  • %V is replaced by Windows with the path of the current folder.
  • Double quotes around the path ensure correct handling of folders whose names contain spaces.
  • The Icon property causes the context menu to display the VS Code icon.

When right-clicking directly on a folder, the command uses %1, and Windows passes the path of the clicked folder to VS Code.

Verifying the Setup

  1. Open File Explorer and navigate to any folder.
  2. Right-click on an empty area inside the folder.
  3. If the option does not appear in the top-level menu, select “Show more options.”
  4. Click “Open with Visual Studio Code” and confirm that VS Code opens the current folder.
  5. Right-click on any folder to test the second context menu entry.

Registry-based context menu entries usually take effect immediately. If they do not appear, try closing and reopening File Explorer; if still missing, log out and back into Windows.

Removing These Menu Entries

If you no longer need them, run the following in PowerShell:

Remove-Item `
    -LiteralPath 'Registry::HKEY_CURRENT_USER\Software\Classes\Directory\Background\shell\VSCode' `
    -Recurse `
    -Force `
    -ErrorAction SilentlyContinue

Remove-Item `
    -LiteralPath 'Registry::HKEY_CURRENT_USER\Software\Classes\Directory\shell\VSCode' `
    -Recurse `
    -Force `
    -ErrorAction SilentlyContinue

Write-Host 'VS Code context menu entries removed.' -ForegroundColor Green

These removal commands delete only the two VSCode registry entries added in this tutorial—they do not uninstall VS Code nor delete any project files.

Alternative Setup Method

If you reinstall the official VS Code installer, you can check options similar to the following:

  • Add “Open with Code” action to Windows Explorer folder context menus.
  • Add “Open with Code” action to Windows Explorer file context menus.

However, this tutorial uses the registry method, which avoids reinstalling VS Code and allows separate control over the context menu entries for empty folder areas versus folders themselves.