问题:
WSL2,Ubuntu,claude code 最新版。
非 root 用户下运行 claude code,在程序内打字会卡顿。
原因:
WSL2 会将 Windows 的 Path 追加到 Linux 的 $PATH,使 Linux 终端可直接运行 powershell.exe 等 Windows 程序。而 Claude Code 会检测 $PATH,发现 powershell.exe 后,会反复调用它获取 Windows 用户目录。但 WSL2 中从 Linux 启动 Windows 程序延迟高,导致每次按键都需等待该调用,引发周期性卡顿。
解决方法(任选一种):
- 复制到 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 "✅ 修复完成!"
- Ubuntu 中不加载 Windows 的环境变量(不推荐)
sudo tee -a /etc/wsl.conf >/dev/null << EOF
[interop]
appendWindowsPath = false
EOF