# Tasks

> Make a project start itself when it opens, using VS Code-style tasks.json, and run npm scripts from the menu.

Last updated: October 17, 2026
Source: https://codevre.com/docs/ide/tasks

Tasks let a project set itself up when it opens: install dependencies, start a dev server, open the preview. Codevre uses the same `tasks.json` format as VS Code, so existing projects work.

## Where tasks live

1. `.vscode/tasks.json`
2. `.codevre/tasks.json` (used when `.vscode/tasks.json` doesn't exist)

Both are JSONC (comments allowed). To create one, right-click the `.codevre` folder and choose **Create tasks.json**:

```json
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Start project",
      "type": "shell",
      "command": "vre run",
      "runOptions": { "runOn": "folderOpen" }
    }
  ]
}
```

## Supported fields

| Field | Meaning |
|---|---|
| `label` | The task's name (`taskName` also works) |
| `type` | `"shell"`, or leave it out |
| `command` | A shell command line. `npm install && npm run dev` works |
| `args` | Extra arguments. Each is quoted and appended to `command` |
| `options.cwd` | Folder to run in. Relative paths are relative to the project |
| `options.env` | Environment variables, e.g. `{ "PORT": "4000" }` |
| `dependsOn` | A label or list of labels to run first |
| `dependsOrder` | `"sequence"` |
| `runOptions.runOn` | `"folderOpen"` runs the task when the project opens |
| `presentation.reveal` | `"always"` opens the Terminal; `"silent"` (default) and `"never"` don't |

Variables:

- `${workspaceFolder}` is the project folder in the runtime.
- `${workspaceFolderBasename}` is the project name.

Codevre ignores other fields, such as `problemMatcher`, `group` and `isBackground`.

## Startup tasks

A task runs automatically when it has `"runOptions": { "runOn": "folderOpen" }`, is a shell task, and has a command. This happens:

- when a saved project finishes opening
- when a template or uploaded workspace loads
- after you clone a repository into the project root

Each independent startup task gets its own terminal tab. Run them again any time with **Terminal ▸ Run Startup Tasks**.

`dependsOn` chains are combined into one command (`a && b && c`). A cycle or a missing dependency stops the tasks with an error such as `Task "dev" depends on missing task "install".`

### Example: a Node project

```jsonc
{
  "version": "2.0.0",
  "tasks": [
    { "label": "install", "command": "npm install" },
    {
      "label": "dev",
      "command": "npm run dev",
      "dependsOn": "install",
      "runOptions": { "runOn": "folderOpen" },
      "presentation": { "reveal": "always" }
    }
  ]
}
```

## Trust and safety

A project from someone else could run anything on open, so Codevre asks first:

> **Allow automatic workspace tasks?** `.vscode/tasks.json` wants to run when this project opens … Only allow this if you trust the project.

- **Allow and Run** remembers your approval for that exact file and those commands, for your account in this browser. If the file changes, you're asked again.
- **Not Now** skips them. You can review the file and run the tasks yourself.
- Signed out, you're asked every time.
- Startup tasks that only use `cd <path>` and `vre run [file.html]`, joined by `&&`, run without asking. Anything with other commands, pipes, redirects, `;`, `$` or backquotes needs approval.
- **Terminal ▸ Run Startup Tasks** is your own explicit action, so it doesn't ask.

Tasks run in Nodepod like anything else you type in the terminal. They never receive your GitHub token. See [Tokens and secrets](tokens-and-secrets.md).

## Running things by hand

The **Terminal** menu has quick ways to run code without a tasks file:

| Command | What it does |
|---|---|
| **Run Active File** | An `.html` file opens in localhost:codevre; a `.js`, `.mjs` or `.cjs` file runs with `node` |
| **Run Selected Text** | Runs the selection, or the current line, in the terminal |
| **Run npm Script ▸** | One item per script in `package.json` (`npm run <name>`), plus `npm install` |
| **Run Preview (VRE)** | Starts or reruns localhost:codevre |
| **Run Startup Tasks** | Runs the `folderOpen` tasks now |

## Recipes

**A build step plus the preview.** Make `npm start` build, then open VRE:

```json
// package.json
{ "scripts": { "build": "node build.js", "start": "npm run build && vre run index.html" } }
```

```jsonc
// .codevre/tasks.json
{ "version": "2.0.0", "tasks": [
  { "label": "start", "command": "npm install && npm start", "runOptions": { "runOn": "folderOpen" } }
] }
```

Also set `"vre.preview.autoRun": false` in `.codevre/settings.json`, so the preview doesn't rerun on every source save before the build finishes. Your build calls `vre run` (or `vre reload`) when output is ready.
