Open a File or Folder in VS Code from Finder on Mac
In this article
To open a file or folder in Visual Studio Code directly from Finder on a Mac, drag the item onto the VS Code icon in the Dock, or right-click it and choose Open with Code (if the option is installed). The fastest method is to use the code command in Terminal, but the Finder drag-and-drop method requires no setup and works immediately.
Why You Need This
Visual Studio Code (VS Code) is a popular code editor for macOS. While you can always launch the app and use its File > Open menu, that takes several clicks and forces you to navigate through the Finder dialog every time. Opening a project directly from Finder saves time and keeps you in your workflow, especially if you work with multiple projects or frequently switch between folders. The techniques below work on all current versions of macOS (Big Sur, Monterey, Ventura, Sonoma, and later) and with the standard VS Code build (not the Insiders or open-source variants, though the steps are similar).
Method 1: Drag and Drop (No Setup)
- Make sure VS Code is running (or at least in the Dock).
- In Finder, locate the file or folder you want to open.
- Click and hold on the item, then drag it onto the VS Code icon in the Dock.
- Release the mouse button when the icon highlights.
VS Code will open the item in a new window. If you drag a folder, it opens as a workspace (the Explorer sidebar shows the folder tree). If you drag a file, it opens in a new tab, and the folder containing that file is not automatically added to the Explorer—only the file itself is opened. To open the whole folder, drag the folder itself, or drag the file while holding Option (this forces VS Code to open the containing folder as the workspace).
Method 2: Right-Click Context Menu (Requires One-Time Setup)
If you right-click (or Control-click) a file or folder in Finder, you may see an Open with Code option. If you don’t, you need to enable it. This is done through VS Code’s built-in shell command installer.
- Open VS Code.
- Press Cmd+Shift+P to open the Command Palette.
- Type “shell command” and select Shell Command: Install ‘code’ command in PATH.
- Close and reopen VS Code (or just wait a few seconds). The Finder context menu option should now appear.
After this, right-click any file or folder in Finder and choose Open with Code. For a folder, it opens as a workspace; for a file, it opens the file in a new window (but not the whole folder). To open the containing folder from a file, right-click the file, hold Option, and the menu changes to Open with Code and Reveal in Finder? Actually, the Option key does not alter the context menu in this case. Instead, after opening the file, you can use the Explorer sidebar to open the folder manually.
Method 3: Using the Terminal
The code command is the most flexible way. Once the shell command is installed (as above), you can open any file or folder from Terminal:
code /path/to/folder
code /path/to/file.txt
If you are already in the folder you want to open, just type code . (the dot means “current directory”). You can also open multiple files at once: code file1.js file2.py. To open a file in a new window (instead of reusing an existing one), add the -n flag: code -n file.txt.
How to Choose the Right Method
- Drag and drop is best for occasional use and requires no setup. It works even if the
codecommand isn’t installed. - Right-click is fastest when you’re already using the mouse and the item is on screen. It requires the one-time shell command installation.
- Terminal is ideal if you’re already working in a terminal window, or if you need to open multiple files or specific paths quickly.
Common Problems and Fixes
“Open with Code” is missing from the right-click menu. Re-run the shell command installer. If it still doesn’t appear, try restarting Finder (hold Option and right-click the Finder icon in the Dock, then choose “Relaunch”) or restarting your Mac. The option is added by VS Code, so ensure you have the latest version.
Dragging a file opens the file but not the folder. That’s expected behavior. To open the folder, drag the folder itself, or use the Terminal command code . from inside the folder.
VS Code opens a blank window when you drag a folder. This can happen if the folder is empty or if VS Code is already open with a different workspace. Try closing all VS Code windows first, or use code -n . to force a new window.
The code command is not found. This means the shell command wasn’t installed, or your shell’s PATH doesn’t include it. Re-run the installer from VS Code’s Command Palette. If you use a custom shell (like zsh with a custom PATH), you may need to add the VS Code binary location manually—usually /Applications/Visual Studio Code.app/Contents/Resources/app/bin.
Comparison: Finder vs. Other Methods
Opening from Finder is convenient, but you can also open a folder by launching VS Code and using File > Open (or Cmd+O). That method is slower but works even if you don’t have the shell command installed. Another option is to use Spotlight (Cmd+Space) to type the folder name and then drag it onto the VS Code icon. None of these are “better” universally—it depends on whether you prefer keyboard, mouse, or a mix.
Frequently Asked Questions
How do I open a folder in VS Code from Finder without dragging?
Right-click the folder and select Open with Code (if installed). If that option isn’t there, open Terminal, type cd followed by a space, drag the folder onto the Terminal window to paste its path, press Enter, then type code . and press Enter.
Why is “Open with Code” not showing up in my right-click menu?
The shell command hasn’t been installed, or Finder hasn’t refreshed. Open VS Code, press Cmd+Shift+P, type “shell command”, and select Shell Command: Install ‘code’ command in PATH. Then relaunch Finder (Option+right-click the Finder icon in the Dock > Relaunch).
Can I open a file in VS Code from Finder without opening the whole folder?
Yes. Drag the file onto the VS Code icon, or right-click the file and choose Open with Code. The file opens in a new tab, but the Explorer sidebar will not show the folder unless you open the folder itself.
Does the drag-and-drop method work with multiple files?
Yes. Select multiple files in Finder and drag them all onto the VS Code icon. They will open as separate tabs in the same window.
Is there a way to open a folder in VS Code from the Finder toolbar?
Not directly, but you can add a custom toolbar button using macOS Shortcuts or Automator. Create a new Quick Action that receives files or folders, and have it run a shell script with code "$@". Then assign it to the Finder toolbar via System Settings > Privacy & Security > Extensions > Finder.
What if I use VS Code Insiders or another fork?
The steps are similar, but the command name differs. For Insiders, the shell command is code-insiders. The right-click menu option is also added by that version. If you have both, make sure you install the shell command from the version you want to use.