Text of code.visualstudio.com › docs › reference › variables-reference as Styx crawled it on Nov 18, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Variables reference

AI agents: See llms.txt for documentation discovery and navigation. Documentation articles are also available as Markdown by appending .md to the article URL. Join VS Code at Microsoft Ignite or catch the sessions online. A year of VS Code, wrapped. Explore the highlights. Variables reference View as Markdown Ask in VS Code Ask in VS Code Insiders Visual Studio Code supports variable substitution in Debugging and Task configuration files, and for some select settings.

Variable substitution is supported inside some key and value strings in launch.json and tasks.json files by using the ${variableName} syntax. Predefined variables The following predefined variables are supported: Variable Description ${userHome} Path of the user's home folder ${workspaceFolder} Path of the folder opened in VS Code ${workspaceFolderBasename} Name of the folder opened in VS Code without any slashes (/) ${file} Currently opened file ${fileWorkspaceFolder} Currently opened file's workspace folder ${relativeFile} Currently opened file relative to workspaceFolder ${relativeFileDirname} Currently opened file's dirname relative to workspaceFolder ${fileBasename} Currently opened file's basename ${fileBasenameNoExtension} Currently opened file's basename with no file extension ${fileExtname} Currently opened file's extension ${fileDirname} Currently opened file's folder path ${fileDirnameBasename} Currently opened file's folder name ${cwd} Task runner's current working directory upon the startup of VS Code ${lineNumber} Currently selected line number in the active file ${columnNumber} Currently selected column number in the active file ${selectedText} Currently selected text in the active file ${execPath} Path to the running VS Code executable ${defaultBuildTask} Name of the default build task ${pathSeparator} Character used by the operating system to separate components in file paths ${/} Shorthand for ${pathSeparator} Predefined variables example Suppose that you have the following conditions: A file located at /home/your-username/your-project/folder/file.ext opened in your editor; The directory /home/your-username/your-project opened as your root workspace.

This leads to the following values for each of the variables: ${userHome} : /home/your-username ${workspaceFolder} : /home/your-username/your-project ${workspaceFolderBasename} : your-project ${file} : /home/your-username/your-project/folder/file.ext ${fileWorkspaceFolder} : /home/your-username/your-project ${relativeFile} : folder/file.ext ${relativeFileDirname} : folder ${fileBasename} : file.ext ${fileBasenameNoExtension} : file ${fileExtname} : .ext ${fileDirname} : /home/your-username/your-project/folder ${fileDirnameBasename} : folder ${lineNumber} : line number of the cursor ${columnNumber} : column number of the cursor ${selectedText} : text selected in your code editor ${execPath} : location of Code.exe ${pathSeparator} : / on macOS or linux, \ on Windows Tip Use IntelliSense inside string values for tasks.json and launch.json to get a full list of predefined variables.

Platform and workspace considerations Platform-specific behavior Some predefined variables may resolve differently depending on the operating system: On Windows , file paths use backslashes ( \ ). When composing paths in JSON files such as tasks.json or launch.json , ensure backslashes are properly escaped (for example: "${workspaceFolder}\\subdir" ). On macOS and Linux , file paths use forward slashes ( / ). It's recommended to use ${pathSeparator} or ${/} to make configurations portable across platforms.

Variables that contain spaces Variable substitution replaces a variable with its string value. It doesn't add quotes or split the result on spaces. The configuration property that contains the variable determines how the resolved value is interpreted. For an array property such as args in many launch.json configurations, define each argument as a separate array element. A variable-based path that contains spaces remains one string in its array element: { "type" : "node" , "request" : "launch" , "name" : "Launch Program" , "program" : "${workspaceFolder}/app.js" , "args" : [ "--input" , "${workspaceFolder}/data folder/input.txt" ] } For shell tasks in tasks.json , shell-specific quoting rules also apply.

Learn more about handling spaces and special characters in custom tasks . Variables scoped per workspace folder By appending the root folder's name to a variable (separated by a colon), it is possible to reach into sibling root folders of a workspace. Without the root folder name, the variable is scoped to the same folder where it is used. For example, in a multi root workspace with folders Server and Client , a ${workspaceFolder:Client} refers to the path of the Client root.

Environment variables You can reference environment variables with the ${env:Name} syntax. For example, ${env:USERNAME} references the USERNAME environment variable. { "type" : "node" , "request" : "launch" , "name" : "Launch Program" , "program" : "${workspaceFolder}/app.js" , "cwd" : "${workspaceFolder}" , "args" : [ "${env:USERNAME}" ] } Configuration variables To reference VS Code settings ( configurations ), use the ${config:Name} syntax.

For example, ${config:editor.fontSize} references the editor.fontSize setting. Command variables You can use any VS Code command as a variable with the ${command:commandID} syntax. A command variable is replaced with the (string) result from the command evaluation. The implementation of a command can range from a simple calculation with no UI, to some sophisticated functionality based on the UI features available via VS Code's extension API.

If the command returns anything other than a string, then the variable replacement will not complete. Command variables must return a string. An example of this functionality is in VS Code's Node.js debugger extension, which provides an interactive command extension.pickNodeProcess for selecting a single process from the list of all running Node.js processes. The command returns the process ID of the selected process.

This makes it possible to use the extension.pickNodeProcess command in an Attach by Process ID launch configuration in the following way: { "configurations" : [ { "type" : "node" , "request" : "attach" , "name" : "Attach by Process ID" , "processId" : "${command:extension.pickNodeProcess}" } ] } When using a command variable in a launch.json configuration, the enclosing launch.json configuration is passed as an object to the command via an argument.

This enables commands to know the context and parameters of the specific launch.json configuration when they are called. Input variables Command variables are already powerful but they lack a mechanism to configure the command being run for a specific use case. For example, it is not possible to pass a prompt message or a default value to a generic "user input prompt". This limitation is solved with input variables , which have the syntax ${input:variableID} .

The variableID refers to entries in the inputs section of launch.json and tasks.json , where additional configuration attributes are specified. Nesting of input variables is not supported. The following example shows the overall structure of a tasks.json that makes use of input variables: { "version" : "2.0.0" , "tasks" : [ { "label" : "task name" , "command" : "${input:variableID}" // ... } ], "inputs" : [ { "id" : "variableID" , "type" : "type of input variable" // type specific configuration attributes } ] } Currently VS Code supports three types of input variables: promptString : shows an input box to get a string from the user. pickString : shows a Quick Pick dropdown to let the user select from several options. command : runs an arbitrary command.

Each type requires additional configuration attributes: promptString : description : shown in the quick input, provides context for the input. default : default value that will be used if the user doesn't enter something else. passwo

The rest of this page is on the live site.