# How to open a folder from the terminal in VS Code on Mac: step by step

> How to open a folder from the terminal in VS Code on Mac: install the code command, run code . in your project, and fix zsh errors.

URL: https://www.lazur.app/how-to/open-a-folder-from-the-terminal-in-vs-code
Updated: 2026-11-09

To open a folder from the terminal in VS Code on Mac, install the code command once, then type code followed by a dot inside your project folder. Install it by opening the Command Palette with ⇧⌘P, running the Shell Command that adds code to PATH, and restarting Terminal.

## Quick answer

- Press ⇧⌘P in VS Code, run the Shell Command that installs code in PATH, then restart Terminal.
- In Terminal, cd into your project folder, then type code and a dot to open it in VS Code.
- If you see zsh: command not found: code, rerun the install, open a new Terminal window, or add the PATH line to ~/.zprofile.
- Add -r to reuse the last active window, or -n to open a new session instead.

Applies to: VS Code on macOS, desktop app, zsh and bash (macOS 10.15 and later). Time: 5 min. Difficulty: Easy.

## What you need

- A Mac running a current macOS release, with VS Code installed in Applications
- The Terminal app, found at Applications > Utilities > Terminal
- A project folder you want to open, for example ~/Projects/invoice-api
- VS Code 1.145 or later, or any current stable build

## How to Open a folder from the terminal in VS Code in VS Code on a Mac

1. **Open the Command Palette in VS Code.** (View > Command Palette) Shortcut: ⇧⌘P. Bring the VS Code window to the front, so you are not on Finder. Press ⇧⌘P, which means Shift, Command and P together. The Command Palette drops down from the top of the window. You can also choose View > Command Palette from the menu bar. Tip: If the keys do nothing, click inside the editor first, then press them again.
2. **Run the Shell Command that installs code.** Type shell command into the palette. Pick the entry Shell Command: Install 'code' command in PATH, or Install 'code' and optionally 'copilot' commands in PATH, depending on your build. Press Return. The official docs give no menu-bar path for this entry. Tip: Both titles install the code command. Pick whichever your build shows.
3. **Answer the Copilot CLI prompt.** If VS Code asks about Copilot CLI, read the choice before you click. Yes installs Copilot CLI in an integrated terminal and adds code to PATH. No adds only code. Escape installs neither, so the code command stays missing. Tip: The success message for code does not confirm that Copilot CLI finished installing. Watch the terminal output if you chose Yes.
4. **Quit and reopen Terminal.** (Terminal > Quit Terminal) Shortcut: ⌘Q. Quit Terminal fully with ⌘Q, then open it again. A new session reads the updated PATH. The VS Code docs say to restart the terminal, and quitting is the surest way to do that. Reopen Terminal from Spotlight by pressing ⌘Space and typing Terminal. Tip: Closing only the window is not the same as quitting the app.
5. **Test that the command exists.** In the new Terminal window, type which code and press Return. If the command is installed, Terminal prints a path to it. If it prints nothing or says not found, skip to the troubleshooting list below. Tip: Run this test before you move on. It tells you whether the rest of the steps will work.
6. **Move into your project folder.** Shortcut: Tab. Type cd, add a space, then the folder path. For example, cd ~/Projects/invoice-api. Press Return. Then type pwd and press Return to confirm where you are. Tip: Press Tab after the first few letters of a folder name, and the shell completes it.
7. **Open the current folder with code.** Type code, a space, then a dot. Press Return. VS Code opens the folder you are in as a window. The dot means the current folder, not a file. Tip: If you run code . from the wrong folder, VS Code opens that folder instead. Check pwd first.
8. **Open a folder without running cd first.** You can skip cd. Type code, a space, then the full path, such as code ~/Projects/invoice-api. Press Return. This works from any folder in Terminal. Tip: Put the path in quotes if it has spaces, like code "My Project".
9. **Choose the window with flags.** Add -r to reuse the last active window, for example code -r ~/Projects/invoice-api. Add -n to open a new session instead of restoring the previous one, for example code -n ~/Projects/invoice-api. Tip: Keep the flag directly after code, as in code -n ~/Projects/invoice-api.
10. **Add code to PATH by hand if it never appears.** Shortcut: ⌘Q. Run echo $SHELL to see your shell. If it ends in zsh, append the export line to ~/.zprofile. If it ends in bash, use ~/.bash_profile instead. For zsh, run: echo 'export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"' >> ~/.zprofile. Then quit Terminal with ⌘Q and open it again. Tip: Run the line once only. A second copy adds a duplicate PATH entry, which is harmless but messy.

## What the code command does

The code command is a small launcher that comes with VS Code. Once it sits on your PATH, Terminal can start VS Code and hand it a folder. PATH is the list of places your shell checks when you type a command name. Installing the command adds VS Code to that list, so you normally do this once.

![Developer at a desk with a laptop, about to open a folder from the terminal in VS Code on Mac](https://images.lazur.app/content-images/howto/open-a-folder-from-the-terminal-in-vs-code/how-to-open-a-folder-from-the-1-5ba8be.jpg)

Which shell you use matters, because it decides which file holds your PATH change. Apple made zsh the default shell starting with macOS 10.15 Catalina. Bash was the default in macOS 10.14 and earlier. Most current Macs therefore run zsh, and the manual fix goes in ~/.zprofile. Run echo $SHELL to see yours.

## What you need before you start

- VS Code installed in your Applications folder. The official Mac install page covers this.
- Terminal, found at Applications > Utilities > Terminal, or opened from Spotlight with ⌘Space.
- A current VS Code build. The menu wording can differ in older builds, so match the names you see.
- The path to a project folder, such as ~/Projects/invoice-api. Finder shows it in the window title bar and in Get Info.

## Install the code command with the Command Palette

The official macOS install page describes this route. Press ⇧⌘P to open the Command Palette, type shell command, and pick the entry that installs code. The docs give no menu-bar path for this step, so the keyboard route is the one to use. Some builds list the longer title Install 'code' and optionally 'copilot' commands in PATH. Others show the shorter Install 'code' command in PATH.

> **Restart Terminal first:** Terminal reads PATH when it starts. A window that was open before the install keeps the old value. Quit Terminal with ⌘Q, then open it again before you test.

## Open folders with code . and its flags

The dot is the form you will use most. It means the folder you are in right now, so run cd first to get there. The CLI docs also show a named folder form, where you pass a path. Two flags control which window opens. The table lists the forms I checked in the docs.

| Command | What it does |
| --- | --- |
| code . | Opens the current folder in VS Code |
| code ~/Projects/invoice-api | Opens a named folder from any location |
| code -r . | Reuses the last active VS Code window |
| code -n . | Opens a new session instead of restoring the previous one |
| code --add ../shared-utils | Adds a folder to the last active window for a multi-root workspace |

_Forms of the code command from the official CLI docs._

The --add flag matters when you work across more than one folder. It adds a folder to the last active window. If you add a second folder without saving a .code-workspace file, VS Code creates an untitled workspace. That workspace stays until you save it, so save it if you want to keep the layout.

## Worked example: opening invoice-api from Terminal

Say your project lives at ~/Projects/invoice-api, and Terminal opens in your home folder. You have two clean options. Option one: type cd ~/Projects/invoice-api, press Return, then type code followed by a dot. Option two: stay where you are and type code ~/Projects/invoice-api. Both open the same project. Option one is handy when you also want to run git or other commands in that folder.

A typo is the usual cause of a failed cd. Terminal prints no such file or directory and stays where it is. Fix the spelling, or type cd and a space, then drag the folder from Finder into the window. Terminal fills in the path for you. Press Return, then run code .

- **1.145** Latest stable VS Code release in the official notes, dated November 4, 2026 ([source](https://code.visualstudio.com/updates/v1_145))
- **⇧⌘P** Command Palette shortcut on macOS, per the official VS Code command line docs ([source](https://code.visualstudio.com/docs/editor/command-line))
- **10.15** macOS Catalina, the release where zsh became the default shell ([source](https://support.apple.com/en-au/HT208050))
- **75.9%** Share of all 2025 Stack Overflow survey respondents who use Visual Studio Code ([source](https://survey.stackoverflow.co/2025/technology))

## Use File > Open Folder when Terminal is not an option

Terminal is not the only way in. The VS Code workspaces docs say you can open a folder from File > Open Folder, then select the folder. Use this when you do not want the command line, or when the code command is not installed yet. The docs I checked do not list a keyboard shortcut for this item, so look for one in the menu itself.

The window.openFoldersInNewWindow setting decides whether folders opened from the File menu reuse the current window or open a new one. Setting it to on always opens a new window. Go to Code > Settings > Settings, or press ⌘, to get there. Search for openFoldersInNewWindow.

## Fix command not found: code on zsh

The error comes from your shell. It cannot find a program named code anywhere on your PATH. Three causes are common. The install never ran or failed. Terminal was open during the install, so its PATH is stale. Or an old alias or PATH line overrides the command. The steps and fixes below handle each one.

![Person typing commands on a MacBook while reviewing project files in a code editor](https://images.lazur.app/content-images/howto/open-a-folder-from-the-terminal-in-vs-code/how-to-open-a-folder-from-the-2-778ad0.jpg)

## Add the VS Code folder to PATH by hand

If the Shell Command never appears, you can add VS Code's bundled bin folder to PATH yourself. The folder is /Applications/Visual Studio Code.app/Contents/Resources/app/bin. Use the file that matches your shell, shown in the table.

| Shell | File to edit | When it applies |
| --- | --- | --- |
| zsh | ~/.zprofile | Default on macOS 10.15 Catalina and later |
| bash | ~/.bash_profile | Default on macOS 10.14 and earlier, or after you switch to bash |

_Which file to edit for the manual PATH line._

Append the export line to the file, then open a new Terminal window. Test with which code. If the output shows a path, the command works. Keep the line to one copy, so the PATH stays tidy.

> **Append, do not overwrite:** Use >> to append. A single > replaces everything already in the file, including PATH lines you set earlier. Open the file in a text editor first if you are unsure.

## Web version and browser limits

The web version is a different tool. vscode.dev runs in the browser, and the VS Code web docs say the terminal and debugger are not available there. You can open local folders only in browsers with File System API support, which means Chrome or Edge. Remote repositories open through URLs such as https://vscode.dev/github/<organization>/<repo>, and that route also has no terminal.

![Programmer working on a Mac in a cafe with a code editor open on the screen](https://images.lazur.app/content-images/howto/open-a-folder-from-the-terminal-in-vs-code/how-to-open-a-folder-from-the-3-456668.jpg)

## Which VS Code version this guide matches

The latest stable release in the notes I checked is 1.145, dated November 4, 2026. Updates 1.145.1 and 1.145.2 followed it. The 1.145 release notes do not change the File menu, the Open Folder command, or how the code command treats folders. Version 1.146 appears only as an Insiders preview in the archive. If your menu labels differ, your build may be older or newer.

## Mistakes people make with the code command

- Running code . in your home folder. The window opens a huge folder, so cd to the project first.
- Typing code in a Terminal window opened before the install. Quit Terminal with ⌘Q and reopen it.
- Leaving out quotes around a path with spaces. Use code "My Project" so the shell reads it as one name.
- Typing code alone and expecting the folder to open. Add a dot or a path after code.
- Editing the wrong shell file. zsh users edit ~/.zprofile, and bash users edit ~/.bash_profile.
- Using > instead of >> when adding the export line, which wipes the file.

Once the command works, the next step is learning the editor. The guide to [changing the color theme in VS Code on Mac](https://www.lazur.app/how-to/change-the-color-theme-in-vs-code) shows the Settings path and shortcuts. For a wider setup, see [VS Code for developers on Mac](https://www.lazur.app/for/developers/vs-code).

## What to do next

Keep a short note of your project paths in one place. Then the cd step takes seconds. Test which code after every macOS update, because the PATH file stays put but Terminal settings can change.

## Shortcuts

- Open the Command Palette in VS Code: ⇧⌘P
- Quit Terminal so a new session reads PATH: ⌘Q
- Open Spotlight to find Terminal: ⌘Space
- Open VS Code Settings: ⌘,
- Autocomplete a folder name in Terminal: Tab

## If it does not work

- **zsh: command not found: code** Run the Shell Command again from the Command Palette. Quit Terminal with ⌘Q, open it again, and run which code. If it still fails, add the export line to ~/.zprofile as described above.
- **Still not found after the install** Open a new Terminal window, not just a new tab in an old session. Then check ~/.zshrc and ~/.zprofile for an old alias named code. Remove it, open a new window, and test again.
- **bash: code: command not found** You are probably running bash. Check with echo $SHELL. Add the same export line to ~/.bash_profile, then open a new Terminal window.
- **The Command Palette does not list the Shell Command** Type shell command and read the full list, because builds use different titles. Update VS Code to the latest stable release. The notes I checked list 1.145 as the current stable build.
- **code . opens my home folder** You ran the command from your home folder. Type cd followed by the project path, then run code again. Or use code with the full path from anywhere.
- **The folder opens in the wrong window** Add -r to reuse the last active window, or -n to open a new session. For folders opened from the File menu, check window.openFoldersInNewWindow in Settings.

## With Lazur

Lazur is a voice assistant for the Mac that lives in the notch. Hold ⌥ ⌘ and ask; it sees your screen, answers out loud, points at buttons and walks you through apps. Hold fn to dictate. Free for 3 days, then $18/month: https://www.lazur.app/download

- “Where is the Command Palette in VS Code?”: Lazur circles View > Command Palette on your screen and labels it. You press the keys and run the install yourself. (Points at it)

## FAQ

### Do I need to install anything extra to run code . in Terminal?

You need VS Code itself and the Shell Command that installs code in PATH. Nothing else is required. The install runs from the Command Palette, so you do not need a separate download.

### Which shell does a Mac use by default?

Starting with macOS 10.15 Catalina, zsh is the default shell. Bash was the default in macOS 10.14 and earlier. Run echo $SHELL in Terminal to see what yours uses.

### Does code . work in vscode.dev in the browser?

No. The web version has no terminal, so there is no command line to type into. You can open local folders in Chrome or Edge with File System API support, but that is not the same as running code .

### What is the difference between code . and File > Open Folder?

Both open a folder. code . starts from Terminal and works best when you already know the path. File > Open Folder works from the menu bar with no command line, as the VS Code workspaces docs describe.

### Will this still work after VS Code updates?

The 1.145 release notes do not change the File menu, the Open Folder command, or the code command's folder behavior. Menu items can still move in later updates, so check the release notes if something breaks.

### Why does my folder open in a new window every time?

Terminal behavior depends on the flags you use. Add -r to reuse the last active window, or -n for a new session. For folders opened from the File menu, check window.openFoldersInNewWindow in Settings.

## Sources

1. [Installing Visual Studio Code on macOS](https://code.visualstudio.com/docs/setup/mac), Microsoft / VS Code, checked 2026-11-09
2. [Command Line Interface (CLI)](https://code.visualstudio.com/docs/editor/command-line), Microsoft / VS Code, checked 2026-11-09
3. [Workspaces in Visual Studio Code](https://code.visualstudio.com/docs/editor/workspaces), Microsoft / VS Code, checked 2026-11-09
4. [User Interface](https://code.visualstudio.com/docs/getstarted/userinterface), Microsoft / VS Code, checked 2026-11-09
5. [FAQ](https://code.visualstudio.com/docs/supporting/FAQ), Microsoft / VS Code, checked 2026-11-09
6. [VS Code for the Web](https://code.visualstudio.com/docs/setup/vscode-web), Microsoft / VS Code, checked 2026-11-09
7. [Visual Studio Code 1.145](https://code.visualstudio.com/updates/v1_145), Microsoft / VS Code, checked 2026-11-09
8. [Release Notes Archive](https://code.visualstudio.com/updates/archive), Microsoft / VS Code, checked 2026-11-09
9. [Use zsh as the default shell on your Mac](https://support.apple.com/en-au/HT208050), Apple Support, checked 2026-11-09
10. [2025 Stack Overflow Developer Survey: Technology](https://survey.stackoverflow.co/2025/technology), Stack Overflow, checked 2026-11-09
