20 July 20252 min read

Today I learned that Visual Studio Code has a powerful command-line interface (CLI) that lets you control how you launch the editor through command-line options (switches).

  • Open a file: code <file_path>. You can list multiple files separated by spaces. If a file doesn’t exist, it will be created. When opening multiple files, VS Code opens them all as tabs in a single window instance.
  • Open a folder: code <folder_path>. You can specify multiple folders separated by spaces to create a Multi-root Workspace that includes each folder and allows you to manage multiple project “roots” simultaneously.

1

Open a file at a specific line and optional column.

Terminal window
code -g, --goto path/to/file:line[:column]

Open a fresh session of VS Code instead of restoring the previous session.

Terminal window
code -n, --new-window [path/to/folder-or-file]

You can also use -r or --reuse-window to force opening a file or folder in the last active window.

Wait for the opened file to be closed before returning to the command line. This is useful for things like editing a Git commit message.

Terminal window
code -w, --wait path/to/file

Specify the directory for user data, which is useful for managing separate profiles or running as a different user.

Terminal window
code --user-data-dir "/path/to/custom/profile"

Open VS Code with all installed extensions temporarily disabled.

Terminal window
code --disable-extensions

Enables verbose logging, which is helpful for diagnosing issues.

Terminal window
code --verbose

Displays all available CLI options.

Terminal window
code --help

Alternatively, you can view the manual page:

Terminal window
man code

For a complete list of options, see the official documentation:

You can also use vscode:// URL schemes to open folders and files.

vscode://file/{full path to folder}/

vscode://file/{full path to file}

vscode://file/{full path to file}:line:column

  1. The column number for character position is optional.

𖥸
Email Me
Thanks for reading! If you found this page useful, considerbuying me a coffee
No CopyrightCC0 1.0