Windows: IDE connection fails due to subprocess PATH inheritance issue (venv workaround found)

Resolved 💬 3 comments Opened Dec 9, 2025 by elfenlieds7 Closed Dec 13, 2025

Problem

Claude Code on Windows fails to connect to VSCode IDE with:

IDE: ✘ Error installing VS Code extension: 1: 1 'code' is not recognized as an internal or external command,
      operable program or batch file.

This occurs even when:

  • The code command works directly in the terminal
  • The VSCode extension is already installed
  • PATH is correctly configured

Root Cause

Claude Code's subprocess handling on Windows doesn't correctly inherit the PATH environment variable when spawning cmd.exe.

Key finding: Running cmd.exe /c 'code --version' directly in the same PowerShell terminal works fine, but Claude Code's internal subprocess call fails. This confirms the issue is in subprocess environment inheritance, not the terminal environment.

Workaround Found

Activating a Python virtual environment before running Claude Code fixes the issue:

# Create venv (only needs to be done once)
python -m venv .venv

# Activate before running claude
.venv\Scripts\Activate.ps1
claude

Why it works

The venv Activate.ps1 script modifies the PowerShell environment in a way that properly configures subprocess inheritance. The exact mechanism is unclear, but the workaround is reliable.

Important: A real Python venv is required. A fake/empty .venv folder doesn't work - the actual Activate.ps1 script generated by python -m venv is what fixes the subprocess environment.

VSCode Auto-Activation

Configure VSCode to auto-activate venv on terminal open:

{
    "terminal.integrated.profiles.windows": {
        "PowerShell (Auto venv)": {
            "source": "PowerShell",
            "args": ["-NoExit", "-Command", "if (Test-Path '.venv/Scripts/Activate.ps1') { & '.venv/Scripts/Activate.ps1' }"]
        }
    },
    "terminal.integrated.defaultProfile.windows": "PowerShell (Auto venv)"
}

Multi-Project Setup

For running multiple Claude Code terminals in different projects from a single VSCode window:

  1. Create venv in parent folder: python -m venv ~/projects/.venv
  2. Add PowerShell profile to auto-switch venv on cd:
# ~\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
function Find-And-Activate-Venv {
    if (Test-Path ".venv\Scripts\Activate.ps1") {
        & ".venv\Scripts\Activate.ps1"
        return
    }
    $p = (Get-Location).Path
    while ($p) {
        $venvPath = Join-Path $p ".venv\Scripts\Activate.ps1"
        if (Test-Path $venvPath) {
            & $venvPath
            return
        }
        $parent = Split-Path $p -Parent
        if ($parent -eq $p) { break }
        $p = $parent
    }
}

$script:originalSetLocation = Get-Command Set-Location -CommandType Cmdlet
function Set-Location {
    param([string]$Path, [switch]$PassThru)
    if ($PassThru) { & $script:originalSetLocation -Path $Path -PassThru }
    else { & $script:originalSetLocation -Path $Path }
    Find-And-Activate-Venv
}
Set-Alias -Name cd -Value Set-Location -Option AllScope -Force
Find-And-Activate-Venv

Environment

  • Windows 11
  • PowerShell 7.x / Windows PowerShell 5.1
  • VSCode with Claude Code extension
  • Claude Code CLI (latest)

Related Issues

  • #13447 - VSCode integrated terminal cannot detect 'code' command

Suggested Fix

Investigate how Python venv activation affects subprocess environment inheritance on Windows. The fix should ensure Claude Code's subprocess calls properly inherit PATH regardless of venv status.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗