You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VSCode集成终端中MSYS2启动目录与独立启动不一致的解决方法

让VSCode中MSYS2 UCRT64终端启动目录与直接运行ucrt64.exe一致

你当前在VSCode的settings.json中配置了MSYS2 UCRT64作为集成终端:

"terminal.integrated.profiles.windows": {
    "MSYS2 UCRT64": {
        "path": [
            "C:\\msys64\\usr\\bin\\bash.exe",
        ],
        "args": [
            "--login",
            "-i"
        ],
        "env": {
            "MSYSTEM": "UCRT64",
            "CHERE_INVOKING": "1",
            "MSYS2_PATH_TYPE": "inherit"
        }
    },
},
"terminal.integrated.defaultProfile.windows": "MSYS2 UCRT64",

但启动VSCode终端时,默认目录是/c/Users/shumbow,而直接运行C:\msys64\ucrt64.exe时启动目录是/home/shumbow,要让两者一致,可通过以下方式修改:

解决方法:移除CHERE_INVOKING环境变量

问题根源在于CHERE_INVOKING=1这个环境变量,它会强制bash继承VSCode当前的工作目录(也就是你的Windows用户目录)。而直接运行ucrt64.exe时,并没有设置这个变量,bash会默认进入MSYS2的用户主目录/home/shumbow。

修改settings.json中的env配置,删掉CHERE_INVOKING这一行:

"terminal.integrated.profiles.windows": {
    "MSYS2 UCRT64": {
        "path": [
            "C:\\msys64\\usr\\bin\\bash.exe",
        ],
        "args": [
            "--login",
            "-i"
        ],
        "env": {
            "MSYSTEM": "UCRT64",
            "MSYS2_PATH_TYPE": "inherit"
        }
    },
},
"terminal.integrated.defaultProfile.windows": "MSYS2 UCRT64",

可选方案:指定固定启动目录(保留CHERE_INVOKING时)

如果你需要保留CHERE_INVOKING的其他作用,也可以在settings.json中添加terminal.integrated.cwd配置,指定MSYS2的用户主目录路径:

"terminal.integrated.cwd": "C:\\msys64\\home\\shumbow",
"terminal.integrated.profiles.windows": {
    "MSYS2 UCRT64": {
        "path": [
            "C:\\msys64\\usr\\bin\\bash.exe",
        ],
        "args": [
            "--login",
            "-i"
        ],
        "env": {
            "MSYSTEM": "UCRT64",
            "CHERE_INVOKING": "1",
            "MSYS2_PATH_TYPE": "inherit"
        }
    },
},
"terminal.integrated.defaultProfile.windows": "MSYS2 UCRT64",

修改后重启VSCode终端,启动目录就会和直接运行ucrt64.exe时一致,默认进入/home/shumbow。

内容的提问来源于stack exchange,提问作者マスターヨーダー

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 21:15:36