Files
prompts/docs/skills/vscode-configuration/references/tasks-json-configuration.md
T
John Lancaster 75b0c8d192 vscode skill
2026-06-19 16:56:45 -05:00

93 lines
2.2 KiB
Markdown

# Configure Project Tasks in tasks.json
Use `.vscode/tasks.json` to define repeatable project commands and optional hooks for debugging.
## Minimal File
```json
{
"version": "2.0.0",
"tasks": []
}
```
## Task Fields You Will Use Most
- `label`: Task name shown in VS Code.
- `type`: Usually `shell`.
- `command`: Executable to run.
- `args`: Command arguments.
- `options.cwd`: Working directory.
- `group`: Mark default build or test tasks.
- `problemMatcher`: Parse errors into the Problems panel.
- `isBackground`: `true` for long-running tasks (for example dev server watch).
## Python Project Example
```json
{
"version": "2.0.0",
"tasks": [
{
"label": "App: Run",
"type": "shell",
"command": "uv",
"args": ["run", "uvicorn", "personal_mcp.main:app", "--host", "127.0.0.1", "--port", "8000", "--reload"],
"options": {
"cwd": "${workspaceFolder}"
},
"isBackground": true,
"problemMatcher": []
},
{
"label": "Tests: Pytest",
"type": "shell",
"command": "uv",
"args": ["run", "pytest"],
"options": {
"cwd": "${workspaceFolder}"
},
"group": "test",
"problemMatcher": []
}
]
}
```
## Connect Tasks to Debug Profiles
In `launch.json`, you can run a task first:
```json
{
"name": "FastAPI: Attach",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "127.0.0.1",
"port": 5678
},
"preLaunchTask": "App: Run"
}
```
Use this only when startup sequencing is needed.
## Task Design Guidelines
1. Keep labels stable and descriptive.
2. Prefer one task per intent instead of monolithic shell commands.
3. Keep shell portability in mind if teammates use multiple OSes.
4. Avoid embedding secrets directly in task definitions.
5. Mark long-running tasks with `isBackground` and keep matchers explicit.
## Troubleshooting
If a task fails unexpectedly:
1. Run the underlying command directly in terminal.
2. Confirm `options.cwd` points to expected workspace root.
3. Confirm tool availability in environment path.
4. Confirm quoting and argument boundaries in `args`.
5. Confirm the task is not blocked by an outdated background process.