VS Code Command Line Interface Guide: How to Use the Code Command

Use the code command to open VS Code from the terminal. Open files and folders, install extensions, diff files, start chat sessions, and control launch behavior from the command line.

5 min read

The code command lets you launch VS Code and control its behavior directly from your terminal. You can open files, folders, diff editors, install extensions, change the display language, start chat sessions, and more without touching the mouse.

If you have not used the integrated terminal yet, start with how to open and use the integrated terminal.

Make sure code is on your PATH

Before using the code command, confirm it is available. Open a terminal and type:

bashbash
code --version

If you see a version number, you are ready. If you see "command not found," the VS Code binary is not on your system PATH.

On macOS, open VS Code, press Cmd+Shift+P, and run Shell Command: Install 'code' command in PATH. This adds the code binary to your shell's PATH so it works from any terminal.

On Windows and Linux, the installer normally adds code to your PATH automatically. If it did not, reinstall VS Code and make sure the "Add to PATH" option is selected. For the Insiders build, the command is code-insiders with the same options.

Open files and folders

The most common use of the code command is opening a project from the terminal. Run code . to open the current directory, or pass file and folder paths.

bashbash
code .                        # Open current directory
code ~/projects/my-app        # Open a specific folder
code src/index.ts             # Open a file
code pkg.json tsconfig.json   # Open multiple files

If you specify a file that does not exist, VS Code creates it and opens an empty editor tab. Intermediate folders are also created if needed.

If you specify multiple folders, VS Code opens them as a multi-root workspace. Use this to work on related projects in one window.

Jump to a line and column

Open a file with the cursor at a specific position using the -g (goto) flag. It tells VS Code to parse the trailing :line:column as a position instead of treating it as part of the filename.

bashbash
# Open at line 42
code -g src/app.ts:42
 
# Open at line 42, column 10
code -g src/app.ts:42:10

VS Code opens the file and places the cursor exactly where you specified.

Compare two files

Open the diff editor directly from the command line to compare two files side by side.

bashbash
code --diff old-version.ts new-version.ts

The diff editor highlights additions, deletions, and changes between the two files. This is useful for reviewing git diffs outside of the source control view.

Control the launch behavior

Several flags control how VS Code opens or reuses windows.

bashbash
# Open in a new window (do not restore previous session)
code -n .
 
# Reuse the last active window
code -r .
 
# Wait for files to be closed before returning to the terminal
code -w file.txt

The -w (wait) flag is useful in scripts where you want the terminal to pause until you close the file in VS Code.

Open VS Code with a specific profile

Launch VS Code with a named profile using the --profile flag.

bashbash
code ~/projects/web-app --profile "Web Development"

If the profile name does not exist, VS Code creates a new empty profile with that name. Learn more about creating and switching between profiles.

Core CLI options reference

FlagWhat it does
-h, --helpPrint usage information
-v, --versionPrint version, commit ID, and architecture
-n, --new-windowOpen a new window instead of restoring the previous session
-r, --reuse-windowOpen the file or folder in the last active window
-g, --gotoOpen a file at a specific line and optional column
-d, --diffOpen the diff editor with two files
-m, --mergePerform a three-way merge
-w, --waitWait for files to close before returning
--localeSet the display language for the session, such as en-US

Start a Copilot chat from the command line

You can start a chat session directly from the terminal with the chat subcommand.

bashbash
# Ask a question in agent mode
code chat "Find and fix all untyped variables"
 
# Use a specific mode
code chat -m ask "Explain this project structure"

Available modes: ask, edit, agent, or the identifier of a custom agent.

Add files as context with the -a flag:

bashbash
code chat -a package.json "What dependencies are outdated?"

You can also pipe the output of another command directly into a chat session. Add a dash at the end of the chat subcommand to read from stdin:

bashbash
python app.py | code chat "Why does this fail?" -

This is separate from Copilot inline suggestions, which work inside the editor rather than the terminal.

Install and manage extensions from the CLI

You can install, uninstall, list, and update extensions without opening the Extensions view. This is especially useful for scripting and automated setups.

Install and uninstall extensions with a single command. You can also list installed extensions and check their versions from the terminal:

bashbash
code --install-extension esbenp.prettier-vscode
code --uninstall-extension esbenp.prettier-vscode
code --list-extensions
code --list-extensions --show-versions

For a full guide on extension management from the command line, see how to install and manage extensions from the command line.

Open files with vscode:// URLs

VS Code registers the vscode:// URL protocol on your system. You can use it from browsers, file explorers, or other applications.

plaintextplaintext
vscode://file/c:/myProject/package.json
vscode://file/c:/myProject/package.json:5:10
vscode://settings/editor.wordWrap

On Windows, prefix the URL with start in the command prompt, for example start vscode://file/c:/myProject/. For Insiders builds, use the vscode-insiders:// prefix instead.

Rune AI

Rune AI

Key Insights

  • Open the current folder with code . or any file with code filename.
  • Jump to a specific line with code -g file:line:column.
  • Compare two files with code --diff file1 file2.
  • Install an extension from the terminal with code --install-extension publisher.name.
  • Start a chat session with code chat 'your question'.
  • Use code --help to see all available options.
RunePowered by Rune AI

Frequently Asked Questions

Why does my terminal say 'code: command not found'?

On macOS, open VS Code and run the Shell Command: Install 'code' command in PATH command from the Command Palette. On Windows and Linux, the installer normally adds code to your PATH. If not, reinstall VS Code or manually add the VS Code bin directory to your PATH environment variable.

What is the difference between code and code-insiders?

code launches the stable version of VS Code. code-insiders launches the Insiders preview build. Both support the same CLI options. Use code-insiders if you installed the Insiders edition alongside the stable release.

Can I use the code command to open a file at a specific line and column?

Yes. Use code -g filename:line:column. For example, code -g src/app.ts:42:10 opens src/app.ts with the cursor at line 42, column 10. The -g flag is needed because some operating systems treat the colon in filenames differently.

Conclusion

The code command turns your terminal into a VS Code launcher. Open projects with code ., jump to specific lines with -g, diff files with -d, install extensions with --install-extension, and start Copilot chat with code chat. Run code --help to see every available option.