# VSCode / Claude Code SSH Fix Guide ## The Problem Claude Code runs inside VSCode's integrated terminal, which uses Git Bash on Windows. Git Bash ships its own SSH binary at: ``` C:\Program Files\Git\usr\bin\ssh.exe ``` This binary resolves **before** Windows' native OpenSSH in the PATH: ``` $ which ssh /usr/bin/ssh ← Git Bash SSH (BROKEN for our use) $ where ssh C:\Program Files\Git\usr\bin\ssh.exe ← resolves first C:\Windows\System32\OpenSSH\ssh.exe ← Windows native (WORKS) ``` Git Bash's SSH does **not** have access to the Windows SSH Agent (`ssh-agent` service). This means SSH key authentication fails silently — commands return exit code 0 or 141 with no output captured, making it extremely confusing to debug. Windows' native OpenSSH (`C:\Windows\System32\OpenSSH\ssh.exe`) connects to the Windows SSH Agent service and has access to your stored keys. ## Fix 1: VSCode Settings (Recommended — Permanent) Open VSCode Settings JSON (`Ctrl+Shift+P` → "Preferences: Open User Settings (JSON)") and add `GIT_SSH` to the terminal environment: ```json { "terminal.integrated.env.windows": { "GIT_SSH": "C:\\Windows\\System32\\OpenSSH\\ssh.exe" } } ``` This tells Git (and any tool that respects `GIT_SSH`) to use Windows' native OpenSSH. However, this only fixes `git` operations — direct `ssh` calls in the terminal still resolve to Git Bash's binary. To fix that too, prepend Windows OpenSSH to the PATH: ```json { "terminal.integrated.env.windows": { "GIT_SSH": "C:\\Windows\\System32\\OpenSSH\\ssh.exe", "PATH": "C:\\Windows\\System32\\OpenSSH;${env:PATH}" } } ``` After changing this setting: 1. **Close all terminals** in VSCode (kill them, don't just hide) 2. **Reload the window** (`Ctrl+Shift+P` → "Developer: Reload Window") 3. Open a new terminal and verify: ``` which ssh ``` Should now show `/c/Windows/System32/OpenSSH/ssh` (or similar Windows path). ## Fix 2: Per-Session Variable (Workaround) If you don't want to change VSCode settings, set this at the start of every Claude Code session (or tell Claude to do it): ```bash SSH=/c/Windows/System32/OpenSSH/ssh.exe ``` Then use `$SSH` instead of `ssh` in all commands: ```bash $SSH kisfenyo@192.168.0.162 "docker ps" ``` This is what CLAUDE.md now documents for the build/deploy workflow. ## Fix 3: Shell Profile (Alternative Permanent Fix) Add to your `~/.bashrc` or `~/.bash_profile` (Git Bash profile): ```bash # Prefer Windows native OpenSSH over Git Bash's bundled SSH alias ssh='/c/Windows/System32/OpenSSH/ssh.exe' alias ssh-add='/c/Windows/System32/OpenSSH/ssh-add.exe' alias scp='/c/Windows/System32/OpenSSH/scp.exe' ``` This works for interactive shells but may not apply to all VSCode terminal contexts. ## Verifying the Fix After applying any fix, test with: ```bash # Check which binary resolves which ssh # Test actual connectivity ssh kisfenyo@192.168.0.162 "echo OK" ``` Expected output for a working setup: ``` OK ``` If you see no output, empty response, or exit code 141/255, the wrong SSH binary is still being used. ## Why This Happens - Windows SSH Agent (`ssh-agent` Windows service) stores SSH keys added via `ssh-add` from PowerShell/CMD - Git Bash's SSH uses its own agent protocol (Unix socket) which is separate from the Windows service - When VSCode spawns a Git Bash terminal, the PATH has Git's `/usr/bin` before `C:\Windows\System32\OpenSSH`, so Git's SSH wins - The Git Bash SSH binary can't talk to the Windows SSH Agent, so key-based auth fails — but it fails silently (no error message, broken pipe on stdout) ## Windows SSH Agent Setup (if keys aren't loaded) If SSH still fails after fixing the binary path, ensure the Windows SSH Agent has your keys: 1. Open **Services** (`Win+R` → `services.msc`) 2. Find **OpenSSH Authentication Agent** → set to **Automatic** → **Start** 3. In PowerShell (not Git Bash): ```powershell ssh-add C:\Users\User\.ssh\id_ed25519 ``` 4. Verify: ```powershell ssh-add -l ``` Should list your key fingerprint.