Run Repeatable Commands with VS Code Workspace Tasks
Define shell commands in .vscode/tasks.json so your team runs the same build, lint, or test task from the VS Code Command Palette.
04 Mar 2026, 08:08 UTC

Desired outcome
You want every developer on a team to run the same build, lint, or test command from the same folder, without memorizing flags or copying commands between terminals. VS Code workspace tasks store that command in .vscode/tasks.json so it appears in the Command Palette and runs in the integrated terminal.
Useful takeaway: commit tasks.json to version control, and anyone who clones the workspace can run the same task from the Command Palette.
Prerequisites
- VS Code installed with a workspace folder open.
- The command you want to automate is installed and available in your shell, for example
npm,make, ordotnet. - You know the shell command and arguments you currently run manually.
Create .vscode/tasks.json
A task definition tells VS Code which program to run, where to run it, and how to interpret errors. Create .vscode/tasks.json at the workspace root. The version field must be "2.0.0".
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "npm",
"args": ["run", "build"],
"problemMatcher": ["$tsc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
label is the name shown in the Command Palette. type selects the shell task provider. command is the executable, and args passes arguments to it. problemMatcher tells VS Code how to scan terminal output for errors; $tsc is a built-in matcher for TypeScript compiler output. group.isDefault makes the task the default build task.
Run the task
- Open the Command Palette (
Ctrl+Shift+Pon Windows and Linux,Cmd+Shift+Pon macOS). - Run Tasks: Run Task.
- Select build.
VS Code opens an integrated terminal and runs npm run build in the workspace folder. Confirm that the terminal shows the command starting and completing. If the command fails, read the exit code and output in that terminal.
Where to run: Command Palette or integrated terminal. Permissions: none beyond normal file access. Risk: a running task holds its terminal until it finishes or you stop it. Editing tasks.json does not affect an already running task.
Handle platform differences
The default shell is the configured default Windows shell on Windows, and shell on Linux and macOS. Command paths and argument syntax can differ. Override fields per platform if needed:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "npm",
"args": ["run", "build"],
"windows": {
"command": "npm.cmd",
"args": ["run", "build"]
}
}
]
}
Chain tasks with dependsOn
Use dependsOn to run prerequisite tasks first. This example runs lint before build:
{
"version": "2.0.0",
"tasks": [
{
"label": "lint",
"type": "shell",
"command": "npm",
"args": ["run", "lint"]
},
{
"label": "build",
"type": "shell",
"command": "npm",
"args": ["run", "build"],
"dependsOn": ["lint"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
VS Code starts lint and waits for it to complete before starting build. If lint fails, build does not start.
Expected checks
- The integrated terminal opens and executes the intended command in the workspace folder.
- The task appears under Tasks: Run Task after saving
tasks.json. - With a problem matcher, matching errors appear in the Problems panel and link to source lines.
- After committing
.vscode/tasks.json, a teammate can clone the workspace and run the same task.
Limitations and recovery
- Task terminal output is not persisted by default. Redirect output to a file if you need a lasting log.
- Changes to
tasks.jsondo not affect a running task. Stop the task first using the stop button in the terminal panel. - Shell syntax and executable names differ across operating systems; test on each target platform.
To remove a task, edit or delete .vscode/tasks.json. There is no database or persistent state to roll back beyond the file itself.