How to Open VS Code from the macOS Terminal with the code Command
Once you get used to it, code . becomes muscle memory: one line in the terminal and the current folder opens straight in VS Code. But right after a fresh install, you usually hit this:
zsh: command not found: code
That just means the code command isn't in your PATH yet. Registering it takes a minute. Let's walk through it.
Option 1: Register from the Command Palette (recommended)
This is the simplest and most official approach.
- Open VS Code.
- Open the Command Palette with
Cmd + Shift + P. - Type
Shell Command: Install 'code' command in PATHand run it. - Restart your terminal.
This creates a symlink at /usr/local/bin/code. Since /usr/local/bin is already on your PATH by default, the command works right away.
Option 2: Add it to PATH manually
If Option 1 doesn't work or you prefer to wire it up yourself, add VS Code's bin directory to your shell config. macOS ships with zsh these days, so add this to ~/.zshrc:
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
Then reload the config:
source ~/.zshrc
Verify it works
Confirm the command is registered:
which code # prints a path if it worked
code . # open the current folder
code ~/projects/my-app # open a specific folder
When it still doesn't work
If command not found: code keeps showing up after you installed it, it's almost always one of these two things.
1. Your shell and config file don't match
You're on zsh, but you added the PATH to ~/.bash_profile or ~/.bashrc. Check which shell you're actually running:
echo $SHELL
If it returns /bin/zsh, your config belongs in ~/.zshrc. If it's /bin/bash, use ~/.bash_profile.
2. VS Code isn't in /Applications
If you're running VS Code from your Downloads folder or Desktop, the path above won't resolve. Move VS Code into /Applications, then run Option 1 again.
Wrap-up
- The easiest path is the Command Palette's
Shell Command: Install 'code' command in PATH. - If that fails, check your shell type (
echo $SHELL) and where VS Code is installed (/Applications). - Restarting the terminal after registering is required.
Set it up once and code . becomes second nature. Going back to dragging folders onto the Dock icon never quite feels the same.