How To Open Visual Studio Code From Terminal On Any Operating System

Why Opening VS Code From Terminal Is a Game Changer

You’re deep in a terminal session, navigating your project’s directory structure. You’ve just cloned a repository, run a build command, or maybe you’re sifting through logs. Suddenly, you need to examine a file more closely, edit a configuration, or just open the entire project in a proper editor. The old way would be to minimize your terminal, hunt for the VS Code icon in your dock or start menu, click it, and then use File > Open to navigate back to the exact folder you were just in.

That context switch breaks your flow. It’s a tiny friction point that, over hundreds of coding sessions, adds up to a significant drain on your focus and productivity. The modern developer’s workflow is integrated. Your terminal and your editor shouldn’t be separate silos; they should be different views into the same workspace. This is exactly why learning to launch Visual Studio Code directly from your command line is such a fundamental skill.

It transforms VS Code from a standalone application into a powerful command-line tool. You can open files at specific line numbers, compare differences, or launch the editor with a particular set of extensions disabled for debugging. It’s the difference between treating your editor as a destination and treating it as a seamless part of your development pipeline.

Understanding the Core Command: `code`

At the heart of this functionality is a simple command: code. When installed correctly, typing code . in your terminal will open the current directory in a new VS Code window. Typing code filename.js will open that specific file. This command is the bridge, and setting it up is a one-time process that pays endless dividends.

This command isn’t magic. It’s a shell command installed by VS Code itself. On Windows, it’s typically a batch file or PowerShell script added to your system’s PATH. On macOS and Linux, it’s a shell script placed in a directory that your terminal knows to look in for executable commands. The setup process ensures this script is accessible from any terminal session.

Prerequisites Before You Begin

Before we dive into the setup for your specific operating system, let’s cover the universal prerequisites. First, you must have Visual Studio Code installed. This might seem obvious, but it’s worth confirming. Second, you need a terminal application. On Windows, that could be Command Prompt, PowerShell, or Windows Terminal. On macOS, it’s Terminal or iTerm2. On Linux, it’s GNOME Terminal, Konsole, or your distribution’s default.

Finally, you need to know how to open a terminal and navigate to a directory. Basic commands like cd (change directory) and pwd (print working directory on Mac/Linux) or cd without arguments (on Windows) are essential. If you’re comfortable with these, you’re ready to proceed.

Setting Up the `code` Command on Windows

Windows users have a straightforward path, especially if you used the standard installer. The setup is often automatic, but let’s verify and fix it if needed.

Method 1: Using the VS Code Installer (Recommended)

The easiest method is to re-run the Visual Studio Code installer. During installation, the setup wizard includes a critical checkbox labeled “Add to PATH” or “Add ‘Open with Code’ action to Windows Explorer context menu.” If you missed this the first time, simply download the installer again from the official VS Code website, run it, and ensure this box is checked. Choose the “Modify” option if you’re updating an existing installation. This will add the necessary entries to your system’s PATH environment variable.

Method 2: Manual PATH Configuration

If you prefer not to re-run the installer, you can manually add VS Code to your PATH. First, you need to find where VS Code is installed. The default location is C:\Users\[YourUsername]\AppData\Local\Programs\Microsoft VS Code.

Open the Start menu, search for “Environment Variables,” and select “Edit the system environment variables.” Click the “Environment Variables” button. In the “System variables” section, find and select the “Path” variable, then click “Edit.” Click “New” and add the full path to the VS Code bin folder. This is typically C:\Users\[YourUsername]\AppData\Local\Programs\Microsoft VS Code\bin.

Click OK on all dialogs to save. For this change to take effect in any already-open Command Prompt or PowerShell windows, you must close and reopen them. New terminal sessions will immediately recognize the code command.

Testing Your Windows Setup

Open a new PowerShell or Command Prompt window. Type the following command and press Enter:

code --version

If the setup is successful, you will see the version number of your VS Code installation printed to the terminal, such as 1.96.0. This confirms the code command is active. Now, navigate to any project folder using cd and try code . to open it.

Setting Up the `code` Command on macOS

On a Mac, the process is managed through the Command Palette within VS Code itself, which is often the most reliable method.

Using the Command Palette

First, open Visual Studio Code through your Applications folder or Spotlight. Once it’s running, press Cmd+Shift+P to open the Command Palette. This is your gateway to nearly every VS Code feature. Start typing “shell command” and you should see an option called “Shell Command: Install ‘code’ command in PATH.” Select this option.

You may be prompted for your administrator password. This is because the command installs a symbolic link in /usr/local/bin, a directory that requires elevated permissions to modify. Enter your password and the process will complete silently.

Verifying the Installation

Open your Terminal application. You can find it in Applications > Utilities. Type the following command:

which code

This command tells you the file path of the executable that will run when you type code. You should see an output like /usr/local/bin/code. Next, test it with the version check:

how to open vsc from terminal

code --version

Seeing the version number confirms success. You can now use code . from any directory in your terminal to launch VS Code with that folder as the workspace.

Setting Up the `code` Command on Linux

The process for Linux varies slightly depending on your distribution and how you installed VS Code (via package manager, Snap, or direct download). The Command Palette method is usually the most universal.

Standard Method via Command Palette

Just like on macOS, open VS Code. Press Ctrl+Shift+P to open the Command Palette. Type “shell command” and select “Shell Command: Install ‘code’ command in PATH.” This will create the necessary symlink, typically in a directory like /usr/local/bin that is already in your shell’s PATH.

Alternative for Debian/Ubuntu (.deb package)

If you installed VS Code by downloading the .deb package from the website and installing it with sudo dpkg -i, the code command might already be installed. You can test with code --version. If it’s not found, the Command Palette method above should resolve it.

Alternative for Snap Installations

If you installed VS Code as a Snap package (sudo snap install code --classic), the command is slightly different. The Snap system often uses a different command name to avoid conflicts. In this case, the command to launch VS Code from the terminal is typically code as well, but if it fails, try snap run code. You can create an alias in your shell configuration file (like ~/.bashrc or ~/.zshrc) for convenience: add the line alias code='snap run code'.

Testing Your Linux Setup

Open a new terminal window. Run which code to see the path. Then, run code --version. A successful output means you’re ready to go. Navigate to a project directory and execute code . to see your new workflow in action.

Powerful Usage Patterns and Command-Line Arguments

Now that the code command is working, let’s move beyond simply opening a folder. The real power lies in the command-line arguments that let you control exactly how VS Code starts.

Opening Specific Files and Directories

The basic syntax is flexible. You can open a single file, multiple files, or a directory.

code index.html opens just that file.

code script.js styles.css opens both files in the same editor window.

code /home/user/projects/myapp opens the specified absolute path.

code .. opens the parent directory of your current location.

Going to a Specific Line and Column

This is incredibly useful when a compiler error or log output references a specific line. You can jump directly to it.

code -g script.js:10 opens script.js and places the cursor on line 10.

code -g script.js:10:5 opens the file and goes to line 10, column 5.

Opening in a New Window or Reusing an Existing One

By default, code . might reuse an existing VS Code window. You can control this behavior.

code -n . forces a new window to open.

code -r . forces the folder to open in the most recent window, preventing clutter.

Disabling Extensions for Performance or Debugging

If VS Code is running slowly or an extension is causing issues, you can launch a clean session.

how to open vsc from terminal

code --disable-extensions . opens the folder with all extensions disabled. This is a great first step for troubleshooting strange behavior.

You can be more specific: code --disable-extension publisher.extensionid . disables a single extension by its full identifier.

Comparing Files (Diff View)

You can launch VS Code directly into a diff view to compare two files, which is handy after generating patches.

code --diff file_v1.js file_v2.js

Troubleshooting Common `code` Command Issues

Even with correct setup, you might encounter issues. Here are the most common problems and their solutions.

Command Not Found

This is the most frequent error. The system cannot find the code executable in any directory listed in your PATH.

Windows: Re-check the Environment Variables setup. Ensure the path to the bin folder is correct and that you’ve restarted your terminal. Try the “Repair” option in the VS Code installer.

macOS/Linux: Run echo $PATH in your terminal. Do you see /usr/local/bin in the output? If not, your shell configuration might be overriding the PATH. Check files like ~/.bash_profile, ~/.zshrc, or ~/.bashrc. Also, ensure the Command Palette installation succeeded; you may need to run it again.

The Terminal Opens But VS Code Doesn’t Launch

This can happen, especially on Linux with certain desktop environments. The code command might be launching the process in the background. Try adding the --wait flag, which makes the terminal command wait until the opened file or folder is closed before returning. While this is designed for scripting, it can sometimes force the window to the foreground: code --wait ..

Permission Denied Errors on macOS/Linux

If you see “Permission denied” when running code, the symlink or script lacks execute permissions. You can fix this by manually setting the permission. First, find the path with which code, then run sudo chmod +x /usr/local/bin/code (use the actual path from which).

Opening WSL or Remote Folders

If you use Windows Subsystem for Linux (WSL), you can open a Linux folder from your Windows terminal in VS Code running on Windows. The command is slightly different. From your WSL bash prompt, you can type code .. The first time you do this, it will prompt you to install a small server component on the Linux side, after which it works seamlessly, blending both environments.

Integrating `code` Into Your Daily Developer Workflow

With the command working reliably, let’s cement it into your habits. Here are practical scenarios where it shines.

After cloning a new Git repository: Instead of navigating away, simply run cd cloned-repo && code .. You’re now inspecting the code within seconds.

When a test fails and outputs a file path and line number: Copy that path, and in your terminal, run code -g /copied/path/to/file:lineNumber. You’re immediately at the scene of the error.

Quick editing of configuration files: Need to edit .gitconfig or a shell profile? Use code ~/.gitconfig or code ~/.zshrc from anywhere in your system.

Creating and opening a new project structure: mkdir my-new-project && cd my-new-project && code .. The new folder is created, and you’re inside it in VS Code, ready to create your first file.

The goal is to make the transition between the command line, where you control your environment and run tools, and the graphical editor, where you write and navigate code, feel instantaneous and natural. It removes a layer of cognitive overhead, keeping you in the problem-solving zone.

Your Actionable Next Steps

Don’t let this remain a theoretical exercise. Choose the section for your operating system above and follow the steps to install the code command right now. The entire process takes less than two minutes. Once it’s done, test it immediately. Open your terminal, navigate to a small project or any folder, and type code ..

Feel the difference. That seamless launch is your new standard. Commit to using it for the rest of the day. Force yourself to open files from the terminal instead of your dock or desktop. By tomorrow, it will start to feel automatic. By next week, you’ll wonder how you ever worked any other way. You’ve just upgraded one of the most fundamental interactions in your development toolkit, and the payoff in sustained focus and streamlined workflow will compound with every single use.

Leave a Comment

close