code . is not working in on the command line for Visual Studio Code on OS X/Mac
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
When code . does not work on macOS, it almost always means the VS Code shell command is not installed in your system PATH. The fix takes 10 seconds: open VS Code, press Cmd+Shift+P, type "Shell Command: Install 'code' command in PATH", and run it. If that does not resolve the issue, the problem is usually a shell configuration or permissions conflict that requires a manual PATH update.
What the code Command Actually Does
The code command is a shell script that launches the VS Code Electron app and passes arguments to it. When you run code ., it tells VS Code to open the current directory as a workspace. When you run code myfile.py, it opens that specific file.
This shell script lives at a path like /usr/local/bin/code (Intel Macs) or the VS Code application bundle. The "Install 'code' command in PATH" action creates a symbolic link from /usr/local/bin/code to the actual script inside the VS Code .app bundle:
If this symlink is missing or broken, the terminal cannot find the code command.
Fix 1: Install the Shell Command from VS Code
This is the official and most reliable method:
- Open Visual Studio Code (from Spotlight, Dock, or Applications folder).
- Press
Cmd+Shift+Pto open the Command Palette. - Type
Shell Command: Install 'code' command in PATH. - Click the result and enter your password if prompted.
- Open a new terminal window (existing windows will not pick up the change).
- Run
code .in any directory.
Fix 2: Add VS Code to PATH Manually
If the Command Palette method fails due to permissions or a non-standard installation path, add the VS Code binary directory to your PATH manually.
For zsh (default shell on macOS Catalina and later):
For bash (default on older macOS versions):
If you installed VS Code somewhere other than /Applications, adjust the path accordingly.
Fix 3: Recreate the Symlink Manually
Sometimes the symlink at /usr/local/bin/code exists but points to a stale location (for example, after moving VS Code between directories or upgrading). Remove it and recreate:
Fix 4: Resolve Permission Issues
On macOS, /usr/local/bin may not exist or may have restricted permissions, especially on a fresh system. Create it and set proper ownership:
If macOS System Integrity Protection (SIP) is preventing writes to /usr/local/bin, the manual PATH approach (Fix 2) is the better alternative since it does not require writing to protected directories.
Fix 5: VS Code Insiders or Multiple Installations
If you use VS Code Insiders instead of the stable release, the command is code-insiders, not code:
To install the Insiders shell command, open VS Code Insiders and use the same Command Palette method. The symlink will be created as /usr/local/bin/code-insiders.
If you have both stable and Insiders installed and want code to always point to one of them, set an alias:
Diagnosing the Problem
When none of the fixes work, run these diagnostic commands to understand the state of your system:
| Symptom | Likely Cause | Solution |
command not found: code | Shell command not installed | Fix 1 or Fix 2 |
code opens wrong application | Another code binary in PATH | Check which code and adjust PATH order |
| Command works in one terminal but not another | Different shells or config files | Add PATH export to the correct rc file |
Permission denied when running Command Palette install | /usr/local/bin is not writable | Fix 4 |
Symlink exists but code fails | Symlink points to old installation path | Fix 3 |
Homebrew Users
If you installed VS Code via Homebrew Cask, the code command should be set up automatically. If it is not, reinstall:
Homebrew creates the symlink during installation. If it was removed, reinstalling recreates it.
Common Pitfalls
Not opening a new terminal after installing the shell command. The PATH change only takes effect in new shell sessions. Existing terminal tabs or windows still use the old PATH. Always open a fresh terminal window after running the install command.
Editing the wrong shell config file. macOS Catalina and later default to zsh, but some developers have switched back to bash or use fish. Run echo $SHELL to confirm which shell you are using, then edit the corresponding config file.
Having a stale alias or function named code. If an alias or shell function named code was defined in your shell config, it takes precedence over the binary in PATH. Run type code to check. If it shows an alias, remove it from your rc file.
Installing the command for one user but running as another. The /usr/local/bin symlink is system-wide, but PATH modifications in ~/.zshrc only affect the user whose home directory contains that file. This matters on shared machines or when using sudo.
Moving VS Code after installing the shell command. Dragging VS Code from ~/Downloads to /Applications after running the shell command install breaks the symlink. Reinstall the shell command after moving the app.
Summary
The code . command not working on macOS is almost always a PATH issue. The fastest fix is using VS Code's built-in Command Palette to install the shell command (Cmd+Shift+P, then "Shell Command: Install 'code' command in PATH"). For cases where that fails, manually adding the VS Code binary directory to your shell's PATH in ~/.zshrc or ~/.bash_profile is a reliable alternative. After any fix, always open a new terminal window to pick up the changes.

