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 taskTasks: Run TaskCommand Palette: pick any task to runTasks: Run Test TaskRun the default test taskTasks: Configure Default Build TaskChoose which task Ctrl+Shift+B runsTasks: Configure TaskCreate or edit an entry in tasks.jsonTasks: Terminate TaskStop a running taskTasks: Rerun Last TaskRun the last task againTasks: Restart Running TaskStop and start a running taskTasks: Show Running TasksList the tasks that are running nowTasks: Open User TasksEdit tasks that apply to every projecttasks.json Basics
.vscode/tasks.jsonThe file in your project that holds the tasks"version": "2.0.0"The version field at the toplabelThe 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 listgroup{ "kind": "build", "isDefault": true }; kind is build or testoptionscwd (working folder), env (variables), shell (which shell)windows / linux / osxPlatform blocks that override command, args and so onPresentation (how the terminal looks)
presentation.revealalways, silent, never: show the terminal panelpresentation.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 anotherpresentation.clearClear the terminal before the task runspresentation.closeClose the terminal when the task endspresentation.showReuseMessageShow the 'Terminal will be reused' messagepresentation.revealProblemsnever, onProblem, always: open the Problems panelpresentation.groupName a group to show tasks as split terminalsProblem 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 compilersisBackgroundtrue for tasks that never end, such as watch or dev serversbackground.activeOnStartTreat the task as active from the startbackground.beginsPattern / endsPatternRegular expressions that mark when a watch run starts and finishesDependencies & Run Options
dependsOnLabels of tasks to run first, e.g. ["Build", "Lint"]dependsOrderparallel (default) or sequencerunOptions.runOndefault or folderOpen: start automatically when the folder opensrunOptions.reevaluateOnRerunRe-resolve variables when the task is rerunrunOptions.instanceLimitHow many copies may run at oncerunOptions.instancePolicyprompt, silent, terminateNewest, terminateOldest, warnVariables 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, prompttask.allowAutomaticTasksAllow folderOpen tasks to start by themselves: off (default) or ontask.autoDetectFind tasks from npm scripts, Gulp and so on: on (default) or offtask.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 useMy 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.