Master VS Code CLI Commands | Generated by AI

Home 2026.02

Question: Provide a comprehensive introduction to VS Code’s code command line options.

Answer:

The code command is the command-line interface (CLI) for Visual Studio Code. It allows you to launch VS Code, open files/folders, install extensions, compare files, set preferences, and more — all from the terminal or scripts.

First Step: Make code Available in Your Terminal

After this step you can simply type code in any terminal.

Check it works:

code --version
# or
code -v

Get the Full List of Options

The most up-to-date list is always available by running:

code --help

This shows version, usage examples, and all current flags (new options appear in new VS Code releases).

Most Commonly Used Options (Core CLI Flags)

Flag / Short Long form Description / Typical Use Case
-h --help Show all available options
-v --version Show VS Code version + commit ID
. (no flag) code . → open current directory
file.txt (no flag) code README.md → open specific file(s)
-n --new-window Force new window (even if VS Code is already open)
-r --reuse-window Force open in the last active window (most common when you already have VS Code open)
-g --goto Open file at specific location: code -g file.py:42:10 (line 42, column 10)
--diff --diff file1 file2 Open diff editor between two files
-w --wait Wait until the opened files are closed before returning to terminal (useful in git editors)
--locale --locale=es Force display language (en, es, zh-cn, etc.)
--user-data-dir --user-data-dir <path> Use custom user data folder (great for testing / portable setups / multiple instances)
--extensions-dir --extensions-dir <path> Custom extensions folder
--disable-extensions Start without any extensions (very useful for troubleshooting)
--disable-gpu Disable hardware acceleration (helps with some graphics/driver issues)
--status --status Print detailed status information

Opening Files at Specific Locations

# Open file and jump to line 15
code main.py:15

# Line 30, column 5
code src/App.tsx:30:5

# Multiple files + goto
code -g index.html:10 src/styles.css

Useful Everyday Examples

# Open current folder in new window
code . -n

# Open project in already open VS Code window
code ~/projects/my-app -r

# Compare two files
code --diff old-version.py new-version.py

# Open file from stdin (very powerful with pipes)
echo "Hello" | code -

# Wait for file to be closed (great for git commit message editor)
git config --global core.editor "code --wait"

# Open folder with specific profile
code ~/work/project --profile "Work"

# Troubleshoot: start clean
code --disable-extensions --user-data-dir=/tmp/vscode-test

Extension Management from CLI

# Install extension
code --install-extension ms-python.python

# Uninstall
code --uninstall-extension ms-python.python

# List installed extensions
code --list-extensions

# List with versions
code --list-extensions --show-versions

Advanced / Less Common Flags (from –help)

For the absolute latest and complete list (including any new flags added after 2025), always run:

code --help

The official documentation page is continuously updated:

References:


Back Donate