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:
code --versionIf 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.
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 filesIf 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.
# Open at line 42
code -g src/app.ts:42
# Open at line 42, column 10
code -g src/app.ts:42:10VS 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.
code --diff old-version.ts new-version.tsThe 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.
# 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.txtThe -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.
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
| Flag | What it does |
|---|---|
-h, --help | Print usage information |
-v, --version | Print version, commit ID, and architecture |
-n, --new-window | Open a new window instead of restoring the previous session |
-r, --reuse-window | Open the file or folder in the last active window |
-g, --goto | Open a file at a specific line and optional column |
-d, --diff | Open the diff editor with two files |
-m, --merge | Perform a three-way merge |
-w, --wait | Wait for files to close before returning |
--locale | Set 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.
# 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:
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:
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:
code --install-extension esbenp.prettier-vscode
code --uninstall-extension esbenp.prettier-vscode
code --list-extensions
code --list-extensions --show-versionsFor 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.
vscode://file/c:/myProject/package.json
vscode://file/c:/myProject/package.json:5:10
vscode://settings/editor.wordWrapOn 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
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.
Frequently Asked Questions
Why does my terminal say 'code: command not found'?
What is the difference between code and code-insiders?
Can I use the code command to open a file at a specific line and column?
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.
More in this topic
How to Use VS Code with WSL 2 on Windows
Run VS Code connected to Windows Subsystem for Linux so you can develop in a full Linux environment with native tools, terminals, and debugging, all from Windows.
20 Best VS Code Extensions for Web Developers in 2026
Twenty carefully chosen VS Code extensions every web developer should know. Covers formatting, linting, frameworks, debugging, Git, and developer experience.
How to Install, Disable, Update, and Uninstall VS Code Extensions
Learn how to install, disable, update, and uninstall VS Code extensions from the Marketplace and the command line. Step-by-step instructions for every action.