Visual Studio Code tasks are a powerful way to automate common actions like running scripts, building projects, or performing maintenance operations. One lesser-known but very useful feature is the ability to pass dynamic input variables to tasks — allowing you to prompt for user input, select from lists, or even use system values at runtime.
Let’s walk through how this works.
In your .vscode/tasks.json
, you can define a special top-level key called inputs
.
This key contains an array of all possible parameters your tasks may use.
Each input must have an id
, which is later referenced inside the task using the syntax ${input:<id>}
.
For example:
{
"version": "2.0.0",
"tasks": [
{
"label": "Echo param",
"type": "shell",
"command": "echo ${input:param1}",
"problemMatcher": []
},
{
"label": "Echo without param",
"type": "shell",
"command": "echo Hello",
"problemMatcher": []
}
],
"inputs": [
{
"id": "param1",
"description": "Param1:",
"default": "Hello",
"type": "promptString"
}
]
}
How it works:
- When you run the “Echo param” task, VS Code opens a prompt asking for
Param1
. - The value you enter is then substituted wherever
${input:param1}
appears — in this case, passed to theecho
command. - The “Echo without param” task does not use any input variables, so it simply prints “Hello”.
VS Code supports several kinds of input sources:
promptString
– Prompts the user for a text value.pickString
– Displays a dropdown of predefined options.command
– Executes a VS Code command to retrieve a value (useful for things like workspace paths or Git info).
For example, a dropdown input could look like this:
{
"id": "environment",
"type": "pickString",
"description": "Select environment:",
"options": ["development", "staging", "production"],
"default": "development"
}
You could then use it in a task like:
"command": "npm run build -- --env=${input:environment}"
By defining reusable inputs in your tasks.json
, you can make your VS Code tasks much more flexible and interactive.
This is especially useful when you want to run the same command with different parameters — without editing the task each time.
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.