preview_start: autoPort always fails on Windows/Git Bash with "port in use" for all free ports
Resolved 💬 0 comments Opened Jun 12, 2026 by hidamiki Closed Jun 12, 2026
Environment
- OS: Windows 10 Home China 10.0.19045
- Shell: Git Bash (MSYS2 MINGW64_NT-10.0-19045)
- Claude Code: 2.1.139
- lsof available: No (
which lsofreturns nothing,ss -tlnpproduces empty output) - netstat available: Yes (
netstat -anoworks correctly)
Bug Description
preview_start consistently reports "Port X is in use" for ALL ports, even when the port is confirmed free by both netstat -ano and PowerShell Get-NetTCPConnection.
Reproduction Steps
- Ensure no process is running on port 52358 (verify with
netstatandGet-NetTCPConnection) - Create a minimal launch.json:
{
"version": "0.0.1",
"configurations": [
{
"name": "test-server",
"runtimeExecutable": "python",
"runtimeArgs": ["-m", "http.server", "52358", "--bind", "127.0.0.1"],
"cwd": "${workspaceFolder}",
"port": 52358
}
]
}
- Call
preview_startwith name "test-server"
Expected Behavior
Server starts on port 52358 (which is confirmed free).
Actual Behavior
preview_start reports: Port 52358 is in use by another process (not a preview server).
Additional Details
- Using
autoPort: true+port: 0does NOT help — autoPort selects different ports each time, but ALL are falsely reported as "in use" - Direct
Bashstartup (python -m http.server <port>) works fine — the port binding succeeds - This suggests the port detection logic inside
preview_startrelies onlsof/sswhich don't work properly in Git Bash on Windows - The only time
preview_startcorrectly identified a port as occupied was when a node.exe process was actively LISTENING on port 12345 — in that case it correctly reported the PID and process name
Potential Root Cause
The port detection likely uses lsof or ss on Unix, which are non-functional in MSYS2/Git Bash on Windows. The fallback to netstat (which DOES work) may not be implemented or is failing silently.