Open Projects in VS Code from the Terminal

Published: Tuesday, July 12, 2022

Greetings, friends! Many developers like working from the terminal and opening up projects from there. We can use the special code command to open directories or files in VS Code from the terminal! Before we can use this command, however, we need to add it to our computer's $PATH.

In VS Code, open the Command Palette using Command + Shift + P (on Macs) or Ctrl + Shift + P (on Windows). Then, search for shell command. Select the option that says Install 'code' command in PATH. This will now enable the code command in the terminal. Whenever I get a new machine, I usually forget to do this step and wonder why my code command isn't working 😅.

Now, we can go to our terminal and run the following command to open the current directory in VS Code.

shell
Copied! ⭐️
code .

If you want to open a directory, then you can specify the path to that directory.

shell
Copied! ⭐️
code path/to/directory

We can also open up single files in VS Code.

shell
Copied! ⭐️
code name_of_file

The code command is a simple quality of life improvement. Instead of opening VS Code and then searching for a directory or file, we can just open up VS Code from the terminal!