If you see zsh: command not found: code, VS Code's command line tool isn't in your PATH.
Here's the fix:
- Open VS Code
- Press
Command + Shift + P - Type "shell command"
- Select "Shell Command: Install 'code' command in PATH"
Now code works from Terminal.
Test It
code --version
code . # Opens current folder in VS Code
code file.txt # Opens a specific file
If VS Code Isn't Installed
Download it from code.visualstudio.com.
After installing, move VS Code to your Applications folder, then run the shell command install from above.
Manual Installation
If the command palette method doesn't work, add VS Code to your PATH manually:
echo 'export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"' >> ~/.zshrc
source ~/.zshrc
Common Uses
| Command | What it does |
|---|---|
code . |
Open current folder |
code file.txt |
Open a file |
code -n . |
Open in new window |
code -r . |
Open in current window |
code --diff file1 file2 |
Compare two files |
code -g file.txt:10 |
Open file at line 10 |
Open From Finder
You can also right-click a folder in Finder and select "Open with Code" if you've installed the shell command.
VS Code Insider
If you use VS Code Insiders, the command is code-insiders:
code-insiders .
Install it the same way: Command Palette → "Shell Command: Install 'code-insiders' command in PATH"
If It Stops Working After an Update
Sometimes macOS updates or VS Code updates break the PATH link. Reinstall:
- Open VS Code
Command + Shift + P- "Shell Command: Install 'code' command in PATH"
Alternative: Use open
You can always open VS Code with the open command:
open -a "Visual Studio Code" .
open -a "Visual Studio Code" file.txt
This works without any setup but is more typing.
Create an Alias
If the code command keeps breaking, create an alias that always works:
echo 'alias code="open -a \"Visual Studio Code\""' >> ~/.zshrc
source ~/.zshrc
Now code . uses the open command under the hood.
Check the Installation
which code
Should return something like /usr/local/bin/code.
If it returns nothing, the shell command isn't installed.
Uninstall the Shell Command
If you need to remove it:
sudo rm /usr/local/bin/code
Or from VS Code: Command Palette → "Shell Command: Uninstall 'code' command from PATH"
Keep Learning
Opening your editor from Terminal is just one way command line improves your workflow. The free course covers more.
Check it out at Mac Terminal for Humans.