How to restore “Open with Code” after installing VS Code without shell integration

If Visual Studio Code is already installed but Open with Code is missing from the Windows right-click menu, the usual cause is simple: the Explorer integration option was not selected during installation.

The fix is straightforward. You can add the missing Explorer entries yourself with a short PowerShell script and no reinstall.

This guide uses a per-user registry setup, so it does not need an elevated PowerShell session.

What this adds

It creates Explorer context menu entries for:

  • Right-clicking a folder
  • Right-clicking empty space inside a folder
  • Right-clicking a drive

All three entries point to the existing Code.exe installation.

PowerShell script

Save this as enable-open-with-code-context-menu.ps1 and run it in a normal PowerShell window:

$ErrorActionPreference = 'Stop'

$codePathCandidates = @(
    "$env:LOCALAPPDATA\Programs\Microsoft VS Code\Code.exe",
    "$env:ProgramFiles\Microsoft VS Code\Code.exe",
    "${env:ProgramFiles(x86)}\Microsoft VS Code\Code.exe"
)

$codeExe = $codePathCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1

if (-not $codeExe) {
    throw "VS Code was not found in the standard install locations."
}

$menuText = 'Open with Code'
$iconValue = '"' + $codeExe + '",0'

$entries = @(
    @{
        KeyPath = 'HKCU:\Software\Classes\Directory\shell\VSCode'
        Command = '"' + $codeExe + '" "%1"'
    },
    @{
        KeyPath = 'HKCU:\Software\Classes\Directory\Background\shell\VSCode'
        Command = '"' + $codeExe + '" "%V"'
    },
    @{
        KeyPath = 'HKCU:\Software\Classes\Drive\shell\VSCode'
        Command = '"' + $codeExe + '" "%1"'
    }
)

foreach ($entry in $entries) {
    New-Item -Path $entry.KeyPath -Force | Out-Null
    New-ItemProperty -Path $entry.KeyPath -Name '(default)' -Value $menuText -PropertyType String -Force | Out-Null
    New-ItemProperty -Path $entry.KeyPath -Name 'Icon' -Value $iconValue -PropertyType String -Force | Out-Null

    $commandKey = Join-Path $entry.KeyPath 'command'
    New-Item -Path $commandKey -Force | Out-Null
    New-ItemProperty -Path $commandKey -Name '(default)' -Value $entry.Command -PropertyType String -Force | Out-Null
}

Write-Output "Registered Explorer context menu entries."

Run it with:

powershell -ExecutionPolicy Bypass -File .\enable-open-with-code-context-menu.ps1

Why this works

Windows Explorer reads shell menu entries from the registry. For a per-user setup, these keys are enough:

  • HKCU:\Software\Classes\Directory\shell\VSCode
  • HKCU:\Software\Classes\Directory\Background\shell\VSCode
  • HKCU:\Software\Classes\Drive\shell\VSCode

The command subkey defines what Explorer launches:

  • "%1" passes the selected folder or drive path
  • "%V" passes the current folder when you right-click the folder background

Remove it later

If you want to undo the change:

Remove-Item 'HKCU:\Software\Classes\Directory\shell\VSCode' -Recurse -Force
Remove-Item 'HKCU:\Software\Classes\Directory\Background\shell\VSCode' -Recurse -Force
Remove-Item 'HKCU:\Software\Classes\Drive\shell\VSCode' -Recurse -Force

Notes

  • This is the exact fix for the case where VS Code was installed without the Explorer integration option.
  • If VS Code is installed in a custom location, update the script to point at the correct Code.exe.
  • On Windows 11, this usually appears under Show more options unless you also add modern context menu integration through other tooling.

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *