VS Code

How to Open VSCode from Terminal Commands

How to Open VSCode from Terminal Commands

Type code . in a terminal while you’re inside your project folder, and VS Code opens on that folder. The code launcher comes bundled with the editor and takes files, folders or workspaces as arguments.

It won’t run until the VS Code bin folder is on PATH, though. On Windows the Add to PATH option in the installer handles that. On macOS you need a Shell Command run from the Command Palette first, per the VS Code documentation (November 2026).

After that, flags decide what happens. “-r” forces the last active window and “-n” opens a new one. You can jump to a line with “-g”, or get a diff editor with “-d”.

How Do You Open VS Code From the Terminal?

YouTube player

Open a terminal, cd into the project, run code .. The dot is just the current working directory.

Once the launcher is on PATH, it doesn’t care which shell you’re in. You give it a path and it passes that to the editor.

  1. Open a terminal (Terminal on macOS, Command Prompt or PowerShell on Windows, any shell on Linux).
  2. Move into the project with cd path/to/project.
  3. Run code . and press Enter.
  4. Check that the VS Code window opens with the folder loaded in the Explorer.

Opening files, paths and several folders at once

You don’t have to cd anywhere first. code your/path opens that location directly, and code index.html style.css opens both files in one go.

Pass it more than one folder and VS Code builds a multi-root workspace with all of them in it.

Paths that don’t exist are where it gets odd. VS Code creates the file plus any missing intermediate folders, then marks the file as edited. So a typo in a folder name doesn’t throw an error. You just get a new empty file in the wrong place (I’ve lost a few minutes to this more than once).

If you’re already inside the editor and only need a shell, the built-in terminal is a different route, covered in a guide to opening the terminal inside VS Code.

On the Insiders build, the command is code-insiders instead of code.

Code Command Flags That Control Window, Diff and Profile

Day to day, you’ll mostly reach for -n, -r, -g, -d and -w. There’s also --add, for when a second folder needs to join the window you already have open.

FlagWhat it doesExample
-nOpens a new window instead of restoring the previous sessioncode -n .
-rForces the folder or file into the last active windowcode -r .
-gJumps to file:line[:character]code -g src/app.js:42:7
-dOpens a diff editor, needs two file pathscode -d old.conf new.conf
-wWaits until the files are closed before returningcode -w notes.txt

Choosing between -r and -n

According to the CLI docs, a new window is the default. The page dated November 18, 2026 doesn’t attach a default to -r.

I use -r whenever I’m switching projects and only want one window on screen. If two projects have to stay open side by side, go with -n.

Diff, goto and wait in practice

-d takes exactly two file paths. It’s handy with script output, say a build step that writes a new config next to the old one and you want to see what changed.

If you’re already in the editor and would rather click than type, this walkthrough on comparing two files in VS Code covers that route.

Give -g a file:line:character and it lands right on a stack trace position. -w works differently. It keeps the shell waiting until you close the file, which matters when some other program is waiting on your edit.

And –add appends folders to the last active window as a multi-root workspace.

Profile and extension flags

--profile "name" opens a folder or workspace with a named profile. If no profile has that name, you get a new empty one. So a misspelled profile name hands you a blank profile instead of an error, same as the missing-path behavior above and just as easy to miss.

For extensions, --install-extension accepts a publisher.extension ID or a VSIX path. Add @version to pin a release, or –force to skip prompts. --list-extensions prints what’s installed, and –show-versions adds the version numbers.

--disable-extensions starts VS Code with every extension off. Useful when you suspect one of them is the problem.

Run –list-extensions on one machine, feed the result to –install-extension on another, and you end up with the same set of VS Code extensions on both.

Adding the Code Command to PATH on macOS, Windows and Linux

Nothing above works until the VS Code bin folder is on PATH. Windows does it through an installer checkbox and Linux packages usually do it for you. macOS is the odd one out, since you have to run a command from the Command Palette.

OSMethodPATH locationNew terminal needed
macOSCommand Palette command or manual export~/.zprofile (zsh), ~/.bash_profile (bash)Yes
WindowsAdd to PATH option in the installer%LOCALAPPDATA%\Programs\Microsoft VS Code\bin (User setup)Yes
Linuxapt, dnf or Snap package/usr/bin/code, /snap/bin/codeNot stated in the docs

macOS

In VS Code, press Cmd+Shift+P and run “Shell Command: Install ‘code’ and optionally ‘copilot’ commands in PATH”. That’s the label as of the November 2026 docs.

You’ll get a prompt about GitHub Copilot CLI. Yes installs it and adds code. No adds only code, and Escape dismisses the prompt without installing either. If AI features are hidden or your organization blocks the Copilot CLI install, the label stays “Shell Command: Install ‘code’ command in PATH”.

For a dotfiles repo or a provisioning script, the manual route makes more sense. Append this line to your shell’s profile file:

export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"

For zsh that file is ~/.zprofile. Bash uses ~/.bash_profile.

Plenty of guides tell you to edit bashrc or zshrc. The macOS setup page documents the two files above, though, and I’d stick with those.

Open a new terminal after changing PATH. If an older code alias is still sitting in your shell profile, remove it and rerun the Shell Command.

Windows

Setup adds VS Code to the %PATH% environment variable. The catch is the Add to PATH checkbox, which is easy to click past.

If you missed it, rerun the installer and tick Add to PATH on the Select Additional Tasks step. User setup puts the bin folder at %LOCALAPPDATA%\Programs\Microsoft VS Code\bin. System setup uses C:\Program Files\Microsoft VS Code\bin instead and needs administrator permissions.

Newly added environment variables only reach terminal windows opened after the installation completes. Close the old console and open a fresh one. Then run code –version, followed by code . in a folder.

Linux

The package install handles PATH, so you rarely edit it yourself.

On Debian and Ubuntu that’s sudo apt update && sudo apt install code, or sudo apt install ./file.deb for a downloaded package. Fedora and RHEL use dnf check-update && sudo dnf install code once you’ve added the yum repository. With Snap it’s sudo snap install --classic code.

The editor-alternatives commands on the setup page point at /usr/bin/code, or /snap/bin/code for Snap. The CLI page is vaguer. It says to add the VS Code binaries location to $PATH when code is missing, but never names the folder.

Setting up a fresh machine? A walkthrough for installing VS Code on an Ubuntu machine covers the apt route from start to finish.

How to Open VS Code From WSL, SSH and Remote Machines

For WSL, run code . from the WSL terminal. SSH takes an extra step: connect through the Remote-SSH extension first, then use code from the terminal in that window. And if you can’t reach the machine directly, start code tunnel on it.

Either way, the editor stays on your own machine while VS Code Server runs on the remote side.

WSL

The WSL extension handles the setup, so the command is the same one you already use.

  1. Open a WSL terminal from the Start menu, or type wsl in Command Prompt or PowerShell.
  2. Navigate to the folder, including Windows mounts such as /mnt/c.
  3. Run code .. The first run fetches the components VS Code needs inside WSL, so expect a short delay.
  4. Look for the WSL indicator in the bottom-left status bar.

The server only installs once, and it’s separate from any VS Code that might already be inside the distribution. WSL 1 has known limitations. Its file-watcher problem doesn’t exist on WSL 2.

Check these are in place before you start:

  • WSL extension (ms-vscode-remote.remote-wsl) installed
  • VS Code installed on Windows, not inside WSL
  • Outbound HTTPS on port 443 to update.code.visualstudio.com, marketplace.visualstudio.com and two other hosts

If code is missing in WSL, suspect the Add to PATH option on the Windows install first. A broken ~/.vscode-server/server-env-setup script can also block the server. Renaming it from a regular WSL shell clears that. WSL: Show Log tells you what failed.

Remote-SSH hosts

You don’t start Remote-SSH from a shell command. Install the extension (ms-vscode-remote.remote-ssh), confirm the connection works with ssh user@hostname in a terminal, and then run Remote-SSH: Connect to Host from the Command Palette.

After the window connects, the code command in its terminal opens files and folders on the remote host.

The docs don’t quite agree here. The CLI page lists --remote ssh-remote+server path as a way in from the shell. Meanwhile the Remote-SSH page only documents the Command Palette route, so test the flag on your version before you script anything around it.

The Remote-SSH page asks for 1 GB of RAM at minimum, with 2 GB and a 2-core CPU recommended. Its Linux minimums (kernel 3.10, glibc 2.17, libstdc++ 3.4.18) are out of date, though. Since VS Code 1.99 the prebuilt server needs kernel 4.18, glibc 2.28 and libstdc++ 3.4.25 or later, per the Remote Development with Linux prerequisites. Run ldd --version on the host to check glibc.

Some setups just won’t work:

  • Alpine Linux and other non-glibc hosts are unsupported
  • PuTTY does not work on Windows
  • Passphrase-protected keys can make pull and sync hang on the remote
  • ARM hosts may not run extensions with x86 native code

A dedicated guide to connecting through VS Code Remote-SSH goes deeper on host config and authentication.

Tunnels with code tunnel

Running code tunnel downloads and starts VS Code Server on the machine, creates a tunnel to it, and prints a vscode.dev URL. Hosting and connecting both require the same GitHub or Microsoft account on each end. No desktop install? The standalone CLI runs as ./code instead of code.

Each account is capped at 10 registered tunnels. Past that, the CLI removes a random unused one, which seems like a strange way to handle it. The docs note the limit may change.

A server instance serves one user or client at a time, and the machine stays reachable only while VS Code runs on it. To keep a tunnel up after you log out, run it as a service with code tunnel service install. Add code tunnel --no-sleep to stop the machine from going to sleep.

Why Does the Terminal Say “code” Is Not Recognized or Not Found?

It’s PATH. The shell can’t find the VS Code bin folder. Command Prompt reports 'code' is not recognized as an internal or external command, while Bash and zsh report code: command not found.

Go through these in order. Most of the time you’re done by step two.

  1. Run code --version. A printout of the version, commit ID and architecture means the command works.
  2. Close the terminal and open a new one, because new PATH entries only reach windows opened afterward.
  3. Print PATH with echo $PATH on macOS and Linux, or echo %PATH% in Command Prompt, and look for the VS Code bin folder.
  4. Redo the step for your OS. That means the Shell Command on macOS, a reinstall with Add to PATH on Windows, or a package reinstall on Linux.

When a correct PATH still fails

Hand-edited entries are the ones that go stale, so skip them whenever the standard step works.

A report in the VS Code issue tracker describes terminals launched by VS Code, embedded or external, holding on to the old PATH. Quit VS Code fully, then relaunch.

Shell startup files can also contain commands that fail or exit the shell. The docs suggest testing with --noprofile --norc in Bash or -NoProfile in PowerShell.

Look at terminal.integrated.env.<platform> too. Values set there shouldn’t point PATH at an outdated installation.

VS Code may start an interactive login shell to resolve its environment, and it sets VSCODE_RESOLVING_ENVIRONMENT to 1 while it does. A profile script that assumes a person is typing can check that variable.

WinPTY support was removed in version 1.109, so older Windows terminal fixes that toggle it no longer apply. WSL failures usually trace back to the Windows install, covered in the WSL section above.

Code Command FAQ

Which Windows shells can run the code command?

Any shell that reads the %PATH% entry Windows setup adds. The setup page just says to restart your console and run code . without naming specific shells. Git Bash isn’t mentioned at all, so open a fresh window and check with code –version.

Which command opens VS Code Insiders from the terminal?

Swap code for code-insiders. It installs from the same Linux repositories (sudo apt install code-insiders, or sudo dnf install code-insiders), and its links use the vscode-insiders:// prefix.

How do I make Git open VS Code for commit messages?

Run git config –global core.editor “code –wait” in a terminal, as GitHub Docs describes. Without –wait, Git wouldn’t hold until you close the file, and it needs to so it can read your finished message.

Can I pipe terminal output into VS Code?

Yes. A lone hyphen makes the code command read from stdin, so git log –oneline | code – sends that output to VS Code.

Making the Code Command Open the Right Window and Profile

Plain “code .” falls back on the documented default, which is a new window. If you want something else, you have to say so on every launch.

Pick the build first, code or code-insiders. Then the window flag (-r or -n), and after that –profile “name” if you use profiles. Each choice narrows the next one.

The downside is a longer command, something like code -r –profile “Work” ., typed every time.

This was checked against the VS Code CLI documentation dated November 18, 2026, and it shifts if the default window behavior changes. A VS Code workflow cheat sheet is the next reference worth keeping open.

Bogdan Sandu

Stay sharp. Ship better code.

Every week: one curated article, one tool worth knowing, one tip you can use tomorrow. No noise, no padding.