跳到主要内容

修复 Cursor WSL 连接错误

Cursor WSL Fix

从 Cursor 3.0.9 开始,许多用户遇到了一个令人沮丧的 WSL 连接错误:Directory not found: --classic。这是因为 Cursor 使用的 WSL shim 在 Glass(Agent)界面更新后损坏。本指南提供了一个可靠的修复方法。

了解问题

当你尝试从终端在 Cursor 中打开 WSL 文件夹时,你可能会看到:

Directory not found: --classic

发生这种情况的原因是:

  • Cursor 3.0.9+ 引入了 Glass(Agent)界面
  • WSL shim 脚本未正确更新
  • --classic 标志被误解为文件夹名称

修复方法:创建智能包装脚本

步骤 1:找到你的 Cursor 可执行文件

找到 Cursor 在 Windows 上的安装位置:

# 常见位置:
C:\Users\<username>\AppData\Local\Programs\cursor\Cursor.exe
# 或
C:\Program Files\Cursor\Cursor.exe

步骤 2:创建包装脚本

在 WSL 主目录(~/.local/bin/)中创建一个名为 cursor-wsl 的文件:

mkdir -p ~/.local/bin
cat > ~/.local/bin/cursor-wsl << 'EOF'
#!/bin/bash
# Smart wrapper for Cursor WSL connection
# Fixes the --classic directory error

WINDOWS_CURSOR="/mnt/c/Users/$(cmd.exe /c 'echo %USERNAME%' 2>/dev/null | tr -d '\r')/AppData/Local/Programs/cursor/Cursor.exe"

if [ ! -f "$WINDOWS_CURSOR" ]; then
WINDOWS_CURSOR="/mnt/c/Program Files/Cursor/Cursor.exe"
fi

if [ ! -f "$WINDOWS_CURSOR" ]; then
echo "Error: Could not find Cursor.exe"
echo "Please update WINDOWS_CURSOR path in this script"
exit 1
fi

# Convert WSL path to Windows path
WSL_PATH="$(wslpath -w "$PWD")"

# Launch Cursor with the correct path
"$WINDOWS_CURSOR" --classic "$WSL_PATH" "$@"
EOF

chmod +x ~/.local/bin/cursor-wsl

步骤 3:添加到 PATH

将此添加到你的 ~/.bashrc~/.zshrc

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

然后重新加载:

source ~/.bashrc  # 或 ~/.zshrc

步骤 4:创建便捷的别名

添加到你的 shell 配置:

alias cursor='cursor-wsl'
alias c.='cursor-wsl .'

替代修复:直接 Windows 路径方法

如果包装脚本不起作用,请使用以下直接方法:

# 添加到 ~/.bashrc
cursor() {
local win_path
win_path=$(wslpath -w "${1:-$PWD}")
/mnt/c/Users/$(cmd.exe /c 'echo %USERNAME%' | tr -d '\r')/AppData/Local/Programs/cursor/Cursor.exe --classic "$win_path"
}

验证修复

测试你的设置:

# 导航到项目
cd ~/my-project

# 在 Cursor 中打开
cursor .

# 或使用别名
c.

现在 Cursor 应该可以打开而不会出现 --classic 错误。

其他提示

自动更新 Cursor 路径

如果你的 Windows 用户名更改或 Cursor 移动:

# 自动查找 Cursor
find /mnt/c -name "Cursor.exe" -type f 2>/dev/null | head -1

处理路径中的空格

如果你的 Windows 用户名包含空格,请引用路径:

"$WINDOWS_CURSOR" --classic "$WSL_PATH"

WSL2 特定设置

对于 WSL2,确保你的 /etc/wsl.conf 允许 Windows 互操作:

[interop]
enabled = true
appendWindowsPath = true

然后重启 WSL:

wsl --shutdown

故障排除

问题解决方案
command not found: cursor-wsl确保 ~/.local/bin 在你的 PATH 中
Cursor.exe not found更新脚本中的路径以匹配你的安装位置
启动缓慢对于 WSL→Windows 互操作,这是正常的;考虑使用 VS Code Remote WSL
文件监视器问题在 Cursor 设置中添加 "files.watcherExclude" 模式

相关资源