VS Code Tasks Cheat Sheet

Sidebar

Programming ยท VS Code Tasks Cheat Sheet

Running builds, scripts and checks from inside VS Code: the commands, the structure of tasks.json, and the task.* settings. Exact ID, what it does, and its default. Sheet 10 in the VS Code series.

Running Tasks

Ctrl+Shift+BRun the default build task
Tasks: Run TaskCommand Palette: pick any task to run
Tasks: Run Test TaskRun the default test task
Tasks: Configure Default Build TaskChoose which task Ctrl+Shift+B runs
Tasks: Configure TaskCreate or edit an entry in tasks.json
Tasks: Terminate TaskStop a running task
Tasks: Rerun Last TaskRun the last task again
Tasks: Restart Running TaskStop and start a running task
Tasks: Show Running TasksList the tasks that are running now
Tasks: Open User TasksEdit tasks that apply to every project

tasks.json Basics

.vscode/tasks.jsonThe file in your project that holds the tasks
"version": "2.0.0"The version field at the top
labelThe task's name in the list (also how other tasks refer to it)
typeshell (runs in your shell) or process (runs the program directly)
command / argsThe program to run and its arguments (an array)
detailExtra text shown under the label in the task list
group{ "kind": "build", "isDefault": true }; kind is build or test
optionscwd (working folder), env (variables), shell (which shell)
windows / linux / osxPlatform blocks that override command, args and so on

Presentation (how the terminal looks)

presentation.revealalways, silent, never: show the terminal panel
presentation.focusMove the cursor into the terminal (default false)
presentation.echoEcho the command being run (default true)
presentation.panelshared, dedicated, new: reuse a terminal or open another
presentation.clearClear the terminal before the task runs
presentation.closeClose the terminal when the task ends
presentation.showReuseMessageShow the 'Terminal will be reused' message
presentation.revealProblemsnever, onProblem, always: open the Problems panel
presentation.groupName a group to show tasks as split terminals

Problem Matchers & Watch Tasks

problemMatcherTurns output lines into entries in the Problems panel; [] means none
$tsc / $tsc-watchTypeScript compiler, normal / watch mode
$eslint-stylish / $eslint-compactESLint output formats
$jshint / $go / $mscompileJSHint, Go and Microsoft compiler output
$lessc / $node-sassLess and Sass compilers
isBackgroundtrue for tasks that never end, such as watch or dev servers
background.activeOnStartTreat the task as active from the start
background.beginsPattern / endsPatternRegular expressions that mark when a watch run starts and finishes

Dependencies & Run Options

dependsOnLabels of tasks to run first, e.g. ["Build", "Lint"]
dependsOrderparallel (default) or sequence
runOptions.runOndefault or folderOpen: start automatically when the folder opens
runOptions.reevaluateOnRerunRe-resolve variables when the task is rerun
runOptions.instanceLimitHow many copies may run at once
runOptions.instancePolicyprompt, silent, terminateNewest, terminateOldest, warn

Variables in Tasks

${workspaceFolder}The folder you opened in VS Code
${file}The file in the active editor
${fileBasename}That file's name with extension
${env:NAME}An environment variable
${config:setting.id}The value of a VS Code setting
${command:id}The result of a command, e.g. python.interpreterPath
${input:id}A value you type or pick when the task starts (defined in an inputs array)

Task Settings (task.*)

task.saveBeforeRunSave files first: always (default), never, prompt
task.allowAutomaticTasksAllow folderOpen tasks to start by themselves: off (default) or on
task.autoDetectFind tasks from npm scripts, Gulp and so on: on (default) or off
task.quickOpen.historyRecently run tasks kept at the top of the list (default 30)
task.quickOpen.detailShow the detail text in the list (default true)
task.quickOpen.skipSkip the list when only one task exists (default false)
task.quickOpen.showAllShow every task instead of only recent ones (default false)
task.reconnectionReconnect to running tasks after a reload (default true)
task.problemMatchers.neverPromptNever ask to pick a problem matcher (default false)
task.slowProviderWarningWarn when finding tasks is slow (default true)
task.verboseLoggingExtra logging for diagnosing task problems (default false)

Tasks to Copy (examples)

{ "label": "Run file", "type": "shell", "command": "python", "args": ["${file}"] }Runs the file in the active editor with Python
{ "label": "Astro build", "type": "shell", "command": "npm run build", "options": { "cwd": "${workspaceFolder}/astro-site" } }Runs an npm script in a subfolder (adjust the path to yours)
{ "label": "All", "dependsOn": ["Lint", "Test"], "dependsOrder": "sequence" }A task that only runs other tasks, one after another
"runOptions": { "runOn": "folderOpen" }Start a task when the folder opens (needs task.allowAutomaticTasks)
"problemMatcher": []Add this if VS Code keeps asking which problem matcher to use
My automatic task didn't start
A task with "runOn": "folderOpen" only runs if automatic tasks are allowed. The setting task.allowAutomaticTasks is off by default, and it only takes effect in a trusted workspace. Use Tasks: Manage Automatic Tasks in Folder to allow or disallow them for the current folder.
Quoting problems on Windows: try type process
With "type": "shell" the command goes through your default shell (PowerShell on Windows unless you changed it), so spaces and quotes in arguments can behave unexpectedly. With "type": "process" the program is started directly and each entry in args is passed as it is.