问题:Windows在WSL2(Ubuntu)下运行Claude Code,在REPL终端内打字卡顿(尤其新开Claude Code窗口前1分钟)

原因:

WSL2 会将 Windows 的 Path 追加到 Linux 的PATH,发现 powershell.exe 后,会反复调用它获取 Windows 用户目录。但 WSL2 中从 Linux 启动 Windows 程序延迟高,导致每次按键都需等待该调用,引发周期性卡顿。

解决方案 (亲测有效):在wsl中执行如下命令,直接复制粘贴到ubuntu终端内运行

mkdir -p ~/bin

cat << 'EOF' > ~/bin/powershell.exe
#!/bin/bash
if [[ "$1" == "-Command" && "$2" == "\$env:USERPROFILE" ]]; then
  echo "C:\\Users\\Administrator"
else
  /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe "$@"
fi
EOF

chmod +x ~/bin/powershell.exe

if [[ "$SHELL" == */zsh ]]; then
  echo 'export PATH="$HOME/bin:$PATH"' >> ~/.zshrc
  SHELL_CONFIG_FILE=~/.zshrc
elif [[ "$SHELL" == */bash ]]; then
  echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
  SHELL_CONFIG_FILE=~/.bashrc
else
  SHELL_CONFIG_FILE="your shell config file (e.g., ~/.bashrc or ~/.zshrc)"
fi

export PATH="$HOME/bin:$PATH"

echo ""
echo "✅ 修复完成!"

参考:https://linux.do/t/topic/956128