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

Windows下Git Bash中VS Code的code命令无法使用求助

Fixing the bash: code: command not found Error in Git Bash for VS Code

Hey there, I’ve run into this exact frustrating issue before after a system reset, so let’s walk through some targeted fixes to get your code command working again:

1. Double-Check Your VS Code Path (You Might Have the Wrong One!)

Looking at your echo $PATH output, I notice you have /Applications/Visual Studio Code.app/Contents/Resources/app/bin listed — that’s the MacOS path for VS Code, but your PATH clearly shows you’re on Windows (with /c/ drives, Windows system folders, etc.). That’s almost certainly a key part of the problem!

To find the correct Windows path:

  • Open VS Code, go to Help > About
  • Look for the "Installation Path" field (it should look like C:\Program Files\Microsoft VS Code)
  • The code command lives in the bin subfolder, so the Git Bash-compatible path would be /c/Program Files/Microsoft VS Code/bin

2. Re-Register the code Command Directly from VS Code

VS Code has a built-in tool to set up the code command correctly, which is way more reliable than manually editing PATH:

  • Open VS Code
  • Press Ctrl+Shift+P to open the command palette
  • Search for and run Shell Command: Install 'code' command in PATH
  • Close all Git Bash windows, then reopen one and test the code command

3. Verify Git Bash is Loading the Correct PATH

Sometimes Git Bash doesn’t pull in your full Windows system PATH, or a custom bash config file is overriding it:

  • In Git Bash, run echo $PATH again and confirm the correct Windows VS Code bin path is present
  • If it’s missing, temporarily add it manually to test:
    export PATH="$PATH:/c/Program Files/Microsoft VS Code/bin"
    
  • If code works after this, add that line to your ~/.bashrc or ~/.bash_profile file (create it if it doesn’t exist) so the path loads every time you open Git Bash

4. Check for Permission or Corruption Issues

If the above steps don’t work:

  • Try running Git Bash as Administrator (right-click the icon > Run as administrator) and test code
  • Uninstall VS Code, delete any leftover folders (like C:\Program Files\Microsoft VS Code and %APPDATA%\Code), then reinstall it fresh
  • Make sure you’re using the official Git for Windows build, not a third-party port that might have PATH quirks

内容的提问来源于stack exchange,提问作者Tomáš Čikovský

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 08:16:47