claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

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

Open elfenlieds7 opened this issue 2 weeks ago • 1 comments

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.

elfenlieds7 avatar Dec 09 '25 10:12 elfenlieds7

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/13447
  2. https://github.com/anthropics/claude-code/issues/5153
  3. https://github.com/anthropics/claude-code/issues/12470

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Dec 09 '25 10:12 github-actions[bot]

This issue has been automatically closed as a duplicate of #13447.

If this is incorrect, please re-open this issue or create a new one.

🤖 Generated with Claude Code

github-actions[bot] avatar Dec 13 '25 09:12 github-actions[bot]

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

github-actions[bot] avatar Dec 20 '25 14:12 github-actions[bot]