How to Create a Default Build Task in VS Code

Set a default build task in VS Code so Ctrl+Shift+B runs your compiler, linter, or build script instantly. Configure tasks.json with the build group and isDefault flag.

5 min read

Pressing Ctrl+Shift+B on Windows or Linux, or Shift+Cmd+B on macOS, runs your VS Code default build task. You select one build task for the workspace, then the shortcut runs it without opening the task picker.

This article assumes you already have a tasks.json file with at least one task defined.

What a default build task does

A default build task is the task that runs when you use the build shortcut or choose Terminal > Run Build Task.

Without a default, the shortcut shows a picker of available build tasks. You have to choose one every time. With one default, the shortcut runs it immediately.

The default build task is workspace-specific. Each project can have its own. If you open a different folder, its own default build task applies.

Set a default build task from the Command Palette

The fastest way does not require editing JSON. Open the Command Palette (Ctrl+Shift+P / Cmd+Shift+P) and run Tasks: Configure Default Build Task.

VS Code shows the available build tasks for the workspace. These can include detected tasks contributed by VS Code or extensions and custom tasks from tasks.json.

Select one from the list. VS Code opens (or updates) your tasks.json and adds the build group to that task:

jsonjson
{
  "label": "TypeScript build",
  "type": "shell",
  "command": "tsc",
  "group": {
    "kind": "build",
    "isDefault": true
  }
}

Now press Ctrl+Shift+B on Windows or Linux, or Shift+Cmd+B on macOS. The task runs immediately. Its terminal output or generated build artifact confirms that the selected build command ran.

This workflow follows the current official VS Code Tasks guide.

Set a default build task manually in tasks.json

If you prefer to write the configuration yourself, open .vscode/tasks.json in your workspace. If that file does not exist yet, create a task with the tasks.json guide first. Find the task you want to promote, then add the group block:

jsonjson
{
  "label": "Project build",
  "type": "shell",
  "command": "npm run build",
  "group": {
    "kind": "build",
    "isDefault": true
  }
}

The kind must be build. The isDefault flag must be true. Both are required.

If another task already has isDefault: true, change it to false or remove isDefault from that task. VS Code opens a picker when more than one build task is marked as default.

Save the file. VS Code picks up the change immediately. Press Ctrl+Shift+B to confirm the right task runs.

Choose a good default build task

Your default build task should be the command you run most often during development. Good candidates:

  • TypeScript compilation: tsc or tsc --watch for live recompilation.
  • A build script: npm run build or make.
  • A linter that blocks on errors: npm run lint so you catch problems before they reach a pull request.
  • A project build script: npm run build when the script already contains the checks required by your project.

Do not set a watch-mode task as the default unless you want it to remain active. Watch tasks do not finish on their own, so stop one with Tasks: Terminate Task when you no longer need it.

Run a non-default build task

Open the Command Palette and run Tasks: Run Task, then select the task by its label. This is the reliable way to run a different task without changing the default.

For another one-keystroke action, add a custom keybinding for workbench.action.tasks.runTask with the exact task label as its argument.

Change the default build task

Run Tasks: Configure Default Build Task again and pick a different task. Then inspect tasks.json and make sure only the intended task has isDefault: true.

You can also move the group object manually. Save the file and use the build shortcut to confirm that the new task runs.

Troubleshooting

Ctrl+Shift+B shows a picker instead of running

Either no task is marked as default or more than one build task has isDefault: true. Run Tasks: Configure Default Build Task, then inspect tasks.json and keep isDefault: true on the one task the shortcut should run.

The task runs but says "command not found"

The task command is not on the task environment's PATH or depends on an interactive shell startup file. Try the same command in the integrated terminal first. Prefer a project script or add the executable to the normal PATH, then open a new VS Code window and rerun the task.

Two tasks show the build group in tasks.json

Keep isDefault: true on the task you want the shortcut to run directly. Other tasks can remain in the build group without isDefault and can be started with Tasks: Run Task.

Once your build task runs reliably, learn how problem matchers turn compiler and linter output into clickable errors in the Problems panel.

Rune AI

Rune AI

Key Insights

  • Run Tasks: Configure Default Build Task from the Command Palette to choose an available build task.
  • In tasks.json, add group: { kind: "build", isDefault: true } to make a task the default build task.
  • Press Ctrl+Shift+B on Windows or Linux, or Shift+Cmd+B on macOS, to run it.
  • If multiple build tasks are marked as default, VS Code opens a picker instead of choosing one.
  • Run a non-default task with Tasks: Run Task or bind it to a custom shortcut.
RunePowered by Rune AI

Frequently Asked Questions

Can I have more than one default build task?

VS Code can store more than one task with isDefault set to true, but Run Build Task then opens a picker instead of running one task directly. Keep one default for a one-keystroke build. Bind other frequent tasks to custom shortcuts with workbench.action.tasks.runTask and the task label as the argument.

What is the difference between a build task and a test task?

The group kind determines which task command uses it. Build tasks use kind: build and Tasks: Run Build Task. Test tasks use kind: test and Tasks: Run Test Task. A task can belong to either group without being the default.

Can I set a default build task without editing tasks.json?

Yes. Run Tasks: Configure Default Build Task from the Command Palette. Choose an available build task and VS Code generates or updates tasks.json with the build group and isDefault flag.

Conclusion

A VS Code default build task turns the Run Build Task shortcut into a direct action. Set group.kind to build and isDefault to true, keep one task as the default, and verify that its expected build output appears when you use the shortcut.