The quickest way to open VS Code from terminal
The fastest way to open VS Code from your terminal is to type code followed by a file or folder name, then press Enter. If you want to open the current folder you're in, type code . — the period means "this folder". If you want to open a specific file, type code filename.js (or whatever your file is called).
This command works on Windows, Mac, and Linux, but only if you've set up the code command in your system's PATH. PATH is the list of locations your terminal checks when you type a command. If you haven't done this setup yet, the terminal will say "command not found" when you try it. The next section walks through how to set it up.
Once the command is ready, you can open VS Code from any folder on your computer without clicking anything — just type and press Enter. This saves time if you're already working in the terminal and want to edit code without switching windows.
Key Takeaways
- Type code . in your terminal to open VS Code in the current folder, or code filename.js to open a specific file.
- The code command only works after you've added VS Code to your system's PATH, which is a one-time setup.
- On Mac, you can set up the command through VS Code's Command Palette by searching for "Shell Command: Install 'code' command in PATH".
- On Windows, the installer usually adds the command automatically, but you may need to restart your terminal or computer for it to work.
- On Linux, the setup depends on how you installed VS Code, but most package managers add the command during installation.
Setting up the code command on Mac
On Mac, VS Code includes a built-in way to add the command to your PATH. Open VS Code, then press Command + Shift + P to open the Command Palette — this is a search box that runs VS Code's internal commands. Type "shell command" and look for the option that says "Shell Command: Install 'code' command in PATH". Click it or press Enter.
VS Code will ask for your password because adding a command to PATH requires permission. Type your password and press Enter. The command is now installed. Close VS Code and open a new terminal window, then type code . to test it. If it works, VS Code will open in the current folder.
If you ever want to remove the command, open the Command Palette again and search for "Shell Command: Uninstall 'code' command from PATH", then click it. This is useful if you're uninstalling VS Code or switching to a different editor.
Setting up the code command on Windows
On Windows, the VS Code installer usually adds the code command to your PATH automatically. If you installed VS Code through the official installer from the VS Code website, the command should already work. Open a terminal (Command Prompt, PowerShell, or Windows Terminal) and type code . to test it.
If the command doesn't work, your terminal may not have reloaded the PATH yet. Close the terminal completely and open a new one. If it still doesn't work, restart your computer — Windows sometimes needs a restart to apply PATH changes. After restarting, open a terminal and try code . again.
If you installed VS Code through the Microsoft Store instead of the official installer, the setup is different. The Store version may not add the command automatically. In this case, open Settings in VS Code (File > Preferences > Settings on Windows), search for "code command", and look for an option to enable it. If you don't see this option, reinstalling VS Code from the official website is the most reliable fix.
Setting up the code command on Linux
On Linux, the setup depends on how you installed VS Code. If you installed it through your system's package manager (like apt on Ubuntu, pacman on Arch, or dnf on Fedora), the code command should already be in your PATH. Open a terminal and type code . to test it.
If you downloaded VS Code as a .tar.gz file and extracted it manually, you'll need to add the command yourself. Navigate to the folder where you extracted VS Code, then look for a file called bin/code. You can either add this folder to your PATH, or create a symbolic link so the command works from anywhere. For most users, reinstalling through your package manager is simpler than doing this manually.
If you're using a minimal Linux setup or a custom distribution, check your distribution's documentation for how to install VS Code. Most distributions have VS Code in their official repositories, which makes installation and PATH setup automatic.
Opening files and folders with the code command
Once the code command is working, you can use it in several ways. Type code . to open the current folder. Type code foldername to open a specific folder. Type code filename.js to open a single file. You can also type code filename1.js filename2.js to open multiple files at once — VS Code will open them all in separate tabs.
You can combine the command with other terminal operations too. For example, if you're in one folder and want to open a different folder, type code ../otherfolder to go up one level and open a folder there. Or type code ~/Desktop/myproject to open a folder from your home directory. The command works with any valid folder path.
If you want to open VS Code but stay in the terminal (so you can keep typing commands), add an ampersand at the end: code . &. On Windows, you can also type code . --new-window to open the folder in a new VS Code window instead of the current one.
Troubleshooting when the code command doesn't work
If you type code . and get "command not found", the most common reason is that VS Code hasn't been added to your PATH yet. Go back to the setup section for your operating system and follow those steps. After you finish, close your terminal completely and open a new one — the terminal needs to reload to see the new command.
If you've already done the setup and it still doesn't work, check that VS Code is actually installed. On Mac and Linux, type which code in the terminal — if it returns a path, the command is installed. If it returns nothing, VS Code isn't in your PATH. On Windows, type where code instead. If either command returns nothing, repeat the setup steps for your operating system.
Another common issue is that you're in a folder you don't have permission to access. If you type code . and nothing happens, try typing code ~/Desktop instead to open a folder you know you can access. If that works, the problem is folder permissions, not the command itself.
Frequently Asked Questions
Can I use a different command name instead of "code"?
On Mac and Linux, you can create an alias — a custom name for the command. Open your terminal configuration file (usually ~/.bash_profile, ~/.bashrc, or ~/.zshrc depending on your shell), add a line like alias vs='code', save it, and restart your terminal. Then you can type vs . instead of code .. On Windows, this is more complicated and usually not worth the effort.
What if I want to open VS Code but I'm not in a terminal?
You can click the VS Code icon in your applications menu or desktop shortcut, just like any other program. The terminal command is only faster if you're already working in the terminal. On Mac, you can also type code in Spotlight search to open it quickly.
Does the code command work in Git Bash on Windows?
Yes, if you installed VS Code through the official Windows installer, the command works in Git Bash, PowerShell, and Command Prompt. If it doesn't work, try restarting your computer or reinstalling VS Code from the official website.
Can I open VS Code with a specific line number?
Yes. Type code filename.js:10 to open the file and jump to line 10. You can also type code filename.js:10:5 to jump to line 10, column 5. This is useful when an error message tells you exactly where the problem is.