Open Code in VS Code: Terminal Command Guide
Updated Jul 2026
Some links on this page are affiliate links. If you buy through them we may earn a small commission at no extra cost to you. We only recommend what we'd use.
- Launch projects instantly with `code .`
- Jump directly to file lines using CLI syntax
- Configure shell aliases to save keystrokes
- Fix "command not found" PATH errors across operating systems

The Core Command: Launching VS Code from the Terminal
Executecode . in your terminal to launch Visual Studio Code immediately in your current working directory. If you want to open a different directory without navigating there first, pass the relative or absolute folder path directly after the command, such as code /path/to/project.
The code executable serves as the entry point for Visual Studio Code's command-line interface. When you run it alongside a period, your shell tells VS Code to initialize a workspace focused on the current directory context. This keeps you in your terminal flow without forcing you to switch windows and click through menus.
🛍 Ready to buy? Check current prices on Amazon for the picks in this guide.
For this command to work seamlessly, your operating system needs to know where the binary lives. During installation on Windows and Linux, the installer typically handles this setup. macOS users, however, often need to trigger a quick one-time installation step inside the editor itself. You can verify that your shell recognizes the executable by checking its version number:
code --version
If that command returns a version string alongside a commit hash, your environment is ready to go. If it returns an error, your system PATH needs a quick adjustment.
Opening Specific Files and Folders

code binary. Typing code main.py opens an individual file in your active workspace, while code ../other-project opens a completely separate directory in your current editor window without cluttering your system with manual file navigation.
Targeting files directly from the CLI is standard practice when inspecting logs, editing scripts, or updating configuration files. You aren't restricted to single items, either. You can pass multiple arguments separated by spaces to open several files at once:
code index.html styles.css app.js
Keep in mind how your operating system handles file paths. Linux and macOS filesystems treat file paths as case-sensitive, meaning code App.js and code app.js target two different files. Windows is generally case-insensitive, but sticking to exact casing prevents cross-platform script errors. If a file or folder name contains spaces, enclose the full path in quotation marks (code "My Documents/Project") so your shell doesn't treat the spaces as argument separators.
Opening a File at a Specific Line
To open a file and instantly position your cursor at a target line and column, append:line or :line:column to the file path using code path/to/file.ext:42:10. This command opens file.ext, jumps directly to line 42, and places the cursor at column 10 for rapid debugging.
This syntax saves time when working with stack traces, linter outputs, or compiler error messages. Instead of opening a script and manually scrolling through hundreds of lines, you can copy the location string directly from your terminal output into the command.
For example, if an error log points to a failure in a server file, you can jump straight to the source of the issue:
code src/server.ts:128
If you want to view a file without shifting focus away from your active terminal, add the -g (or --goto) flag along with the line syntax to make jumping through code locations seamless.
Creating Custom Terminal Aliases for Speed
Setting up terminal aliases replaces repetitive typing with short, memorable triggers tailored to your shell environment. You can define shortcuts in your shell configuration files—such as.zshrc on macOS, .bashrc on Linux, or PowerShell profiles on Windows—mapping custom words to specific VS Code commands and flags.
If you find yourself constantly opening projects or wanting shorter commands, shell aliases let you reduce typing significantly. Open your shell configuration file in your preferred editor to set them up.
For Zsh or Bash users (macOS/Linux):
Add these lines to your ~/.zshrc or ~/.bashrc file:
# Quick open current directory
alias c='code .'
# Open in a new isolated window
alias cn='code -n .'
After saving the file, reload your profile by running source ~/.zshrc or source ~/.bashrc.
For PowerShell users (Windows):
Open your PowerShell profile (notepad $PROFILE) and add a function or alias mapping:
Set-Alias -Name c -Value "code"
Custom shortcuts reduce context switching and help you jump directly into active projects without breaking momentum.
Fixing "code: command not found" Errors
The command not found error occurs when your terminal cannot locate thecode executable within your system PATH environment variable. On macOS, resolve this using the Command Palette shortcut within VS Code; on Windows or Linux, add the installation directory bin folder directly to your PATH settings.
This issue is common, particularly after fresh OS installs or manual app migrations. The quickest fix depends on your operating system.
macOS Resolution:
- Launch Visual Studio Code normally through your Applications folder or Spotlight search.
- Open the Command Palette by pressing
Cmd + Shift + P. - Type
shell commandinto the prompt. - Select Shell Command: Install 'code' command in PATH.
- Restart your terminal application for the change to take effect.
Windows Resolution:
If the installer didn't configure your variables automatically, you can manually update your environment settings:
- Open the Start Menu, search for "environment variables," and select Edit the system environment variables.
- Click the Environment Variables button near the bottom.
- Under System Variables (or User Variables), locate
Pathand click Edit. - Add the path to your VS Code installation folder. The default location is typically:
%LocalAppData%\Programs\Microsoft VS Code\bin - Save your changes and restart any open terminal windows.
Using the Integrated Terminal in VS Code
Accessing the integrated terminal viaCtrl + ` (or Cmd + ` on macOS) lets you run shell commands directly inside your active workspace. Executing code commands from this built-in terminal spawns new windows or opens files directly in your running instance without leaving your editor interface.
The integrated terminal inherits the environment settings of your underlying system shell, giving you full access to git workflows, build tools, and CLI scripts without switching application windows. You can open multiple terminal split panels or switch between Zsh, Bash, PowerShell, and WSL instances easily.
Running the code command within the integrated terminal is useful for side-by-side work. For instance, typing code file.json inside an integrated shell opens that file in an editor tab alongside your working code, maintaining your project context.
Useful Command-Line Flags and Arguments
Advanced CLI flags give you granular control over editor instances, performance testing, and workspace isolation. Key flags include--new-window (or -n) to force a fresh window, --reuse-window (or -r) to keep existing windows, --diff to compare files, and --disable-extensions for quick troubleshooting.
VS Code offers robust CLI flags designed to streamline shell automation and help diagnose application issues:
code -n /path/to/folder: Opens a folder in a completely new window, leaving your existing workspace intact.code -r /path/to/folder: Forces the specified folder to open in your current, active window.code --diff file1.txt file2.txt: Launches VS Code directly into a side-by-side diff view to compare two files.code --disable-extensions: Starts the editor with all third-party plugins disabled, which is ideal for troubleshooting performance drops or UI crashes.code --status: Outputs diagnostic details regarding CPU load, memory usage, and open window stats to your terminal stdout.
Combining these arguments within automation scripts allows you to build custom dev-environment bootstrap tools tailored to your workflow.
Comparing CLI Capabilities Across Popular Code Editors
Most modern code editors provide dedicated command-line utilities to launch projects, perform file diffs, or open specific directories directly from your terminal prompt. While VS Code usescode, alternative tools rely on custom executables like subl for Sublime Text, zed for Zed, or launcher scripts in JetBrains IDEs.
Command-line launchers vary in syntax, setup steps, and resource overhead across different development environments:
| Editor | CLI Binary | Primary Use Case | Key CLI Advantage |
|---|---|---|---|
| VS Code | code |
General web and software development | Extensive flag options, built-in diff mode, remote development support |
| Sublime Text | subl |
Lightweight editing and rapid text manipulationFAQHow do I open a file in VS Code from the command line?Use the command `code .` to open the current directory, or `code filename.ext` to open a specific file. You can also use `code path/to/file` for files in other locations. What if the `code` command isn't recognized?Ensure VS Code is in your system's PATH environment variable. You may need to add the VS Code installation directory to your PATH manually. Can I open multiple files at once with the command line?Yes, you can! Simply list the filenames after the `code` command: `code file1.txt file2.py file3.html`. VS Code will open all specified files. 🛍 See today's best prices on Amazon and grab the option that fits you. More from us: Kiruruchiki — more tips & how-to guides
|