Skip to main content

Introduction

The Visual Studio Code CLI (code) is a powerful command-line interface built in Rust that provides comprehensive control over VS Code installations, extensions, and remote development features. The CLI enables automation, scripting, and headless operations for developers and administrators.

Installation

The VS Code CLI is automatically included with VS Code installations. You can verify the installation by running:
code --version
This will display the CLI version and commit information.

Basic Usage

The CLI follows a standard command structure:
code [options] [paths...]
code <command> [arguments] [options]

Opening Files and Folders

Open a file or folder in VS Code:
# Open current directory
code .

# Open specific file
code index.js

# Open multiple files
code file1.js file2.js

# Open file at specific line and column
code --goto index.js:10:5

Reading from stdin

You can pipe content directly into VS Code:
echo "Hello World" | code -
cat log.txt | code -

Common Use Cases

Development Workflow

# Open project in new window
code --new-window ~/projects/myapp

# Reuse existing window
code --reuse-window ~/projects/myapp

# Add folder to current workspace
code --add ~/projects/lib
# Install extension
code ext install ms-python.python

# List installed extensions
code ext list

# Uninstall extension
code ext uninstall ms-python.python
# Start a tunnel for remote access
code tunnel

# Run local web version
code serve-web --port 8000

Automation and Scripting

The CLI is ideal for automated workflows:
#!/bin/bash
# Setup script for new developers

# Install required extensions
code ext install dbaeumer.vscode-eslint
code ext install esbenp.prettier-vscode
code ext install ms-python.python

# Open project
code ~/projects/team-project

Key Features

Extension Management

Install, uninstall, and manage VS Code extensions from the command line

Remote Tunnels

Create secure tunnels to access VS Code from anywhere via vscode.dev

Version Management

Switch between different VS Code versions (stable, insiders, or specific versions)

Web Server

Run a local web version of VS Code for browser-based development

Global Options

These options are available for all commands:
--verbose
boolean
Enable verbose output for detailed logging
--log
string
Set log level: trace, debug, info, warn, error, critical, off
--cli-data-dir
string
Directory where CLI metadata should be stored (also via VSCODE_CLI_DATA_DIR environment variable)
--disable-telemetry
boolean
Disable telemetry for the current command
--telemetry-level
string
Set telemetry level: off, crash, error, all

Editor Options

When opening files or folders, you can use these options:
--diff
string[]
Compare two files side by side
code --diff file1.txt file2.txt
--goto
string
Open file at specific line and optional character position
code --goto index.js:25:10
--new-window
boolean
Force opening a new window instead of reusing existing one
code --new-window .
--reuse-window
boolean
Force reusing the last active window
code --reuse-window .
--wait
boolean
Wait for the files to be closed before returning (useful for git commit messages)
git config --global core.editor "code --wait"
--locale
string
Set the display language (e.g., en-US, zh-TW, fr-FR)
code --locale=fr-FR

Data Directories

--user-data-dir
string
Specify a custom directory for user data (allows running multiple isolated instances)
code --user-data-dir ~/.vscode-dev
--extensions-dir
string
Set a custom extensions directory
code --extensions-dir ~/.vscode-extensions
Using custom data directories allows you to maintain separate VS Code configurations for different projects or purposes.

Next Steps

Commands Reference

Explore all available CLI commands and their options

Remote Tunnels

Learn how to set up remote development with tunnels

Additional Resources

  • Run code --help for a complete list of options
  • Use code <command> --help for command-specific help
  • The CLI supports both integrated mode (with VS Code installed) and standalone mode

Build docs developers (and LLMs) love