# Run a dev stack

Write your project's dev servers into one desk.yml, start the whole stack in one click, and let an agent restart a server when it needs to.

Most projects need more than one process running while you work: a web front end, an API, perhaps a
worker. Write them into the project's `desk.yml` once, commit it, and everyone who opens the project in
Rundesk gets the same commands, each one click to start, stop or restart.

This page builds a two-process stack, a web server and an API, and runs it.

## Write the project's desk.yml

Create `desk.yml` in the project's folder. Each entry under `processes:` is one command; its name is
what the sidebar shows.

```yaml
processes:
  web:
    command: pnpm dev
    working_dir: web
    env:
      PORT: 3000
      API_URL: http://localhost:4000
  api:
    command: pnpm start
    working_dir: api
    env:
      PORT: 4000
      LOG_LEVEL: debug
```

| Key | Meaning |
|---|---|
| `command` | the line to run, through your login shell; required |
| `working_dir` | the folder it runs in, relative to the project folder; left out, the project folder |
| `env` | variables set on top of your login environment; a number or `true` becomes its text |

Use your own command lines, folders and ports. On macOS every command starts with your login
environment, the `PATH` and variables your own terminal has; on Windows it starts with Rundesk's own
environment. Either way its own `env` comes after, so `env` wins.

You can also add a command without opening an editor: click **+** beside **Commands** and choose
**Add to project file**. Rundesk adds the entry at the end of `processes:` and leaves your other lines
as they were. It also puts a one-line `# Learn more about this at https://rundesk.app` comment at the top of the
file, unless the file already has it. **Add for me** stores a command in Rundesk for you alone, without touching the project's
files.

> [!NOTE]
> If a `desk.yml` you copied has `auto_start: true`, Rundesk reads it and ignores it. **Nothing starts
> on its own**: a command runs only when you, or an
> agent you allow, start it. Opening the project, or launching Rundesk, starts nothing.

## See the commands in the sidebar

Within two seconds of saving the file, the project's **Commands** section lists `web` and `api`:
Rundesk reads the file every two seconds and whenever the window comes back, so you never reload.
**Refresh commands**, on the section's header, reads it straight away. Hover a command's row to see its
command line.

If the file has a mistake, the project shows the error in place of its commands, such as `desk.yml:
api: env PORT is not a scalar` for a list where a value belongs. Fix the file and the commands come
back.

## Start, stop and restart the commands

1. Click the play button on the **Commands** header, **Start all**, to start every command not
   already running. Or start just one from its row.
2. Click a command to see its terminal: its output, live.
3. After changing a setting that needs a fresh process, **Restart** the command. It stops the command,
   then starts it again in a new terminal. Start and Restart read the command line from the file at that
   moment, so an edited line runs as edited.
4. When you are done, the square button, **Stop all**, stops every command started in the project at
   once. It shows only while something is running.

Each command's row shows its state:

| Row mark | State |
|---|---|
| spinner | running |
| amber ring | stopping |
| red dot, `exited 1` | it ended on its own with an error |
| gray dot, `exited 0` | it finished on its own without an error |
| gray dot, `stopped` | you stopped it |

A stop ends everything the command started, its child processes included, so the port is free again.
A command you stopped reads `stopped` in its row and `Stopped` in its footer, not a failure. A command that fails on its own raises an alert,
such as `Failed with exit code 1`, and its output stays on screen to read.

> [!TIP]
> Drag commands into the order you want. The order is stored in Rundesk, never written to `desk.yml`,
> so your arrangement never shows up in someone else's checkout.

## Read a command's footer for its state, CPU and memory

The bar under a command's terminal shows what it is doing and what it costs:

- **State**: `Not started`, `Running`, `Stopping`, `Stopped`, or how it ended, such as `Exited 1`.
- **CPU and memory** for the command and everything under it together, read every second. CPU is the
  share of one core, so it can pass 100%.
- **Processes**: the `+N` count shows the processes running under the command. Open it to see each by name and process
  number, and **Kill** one runaway process without stopping the rest.

## Let an agent run the stack

An agent working in the project can start, stop and restart the same commands through Rundesk's tools,
and you see every change in the sidebar. With these tools an agent can restart the API after changing
its configuration, or read a server's output to find out why a request failed.

| Tool | Switch in Settings › MCP | Description |
|---|---|---|
| `command_list` | **Commands: View** | lists the commands with their command line and state |
| `command_start` | **Commands: Start and stop** | starts a command; does nothing if it is running |
| `command_restart` | **Commands: Start and stop** | stops a command if it is running, then starts it again |
| `command_stop` | **Commands: Start and stop** | stops a command and everything it started |
| `command_start_all`, `command_stop_all` | **Commands: Start and stop** | the whole project's commands |
| `command_output` | **Commands: View** | reads the last lines of a command's terminal |

Switch off **Commands: Start and stop** and the agent's calls are refused with the switch's name, so it
tells you instead. An agent adds or edits a command only when you ask, which needs **Commands: Add and
edit**.

A prompt to paste into an agent working on the API:

```text
The project's dev stack is in Rundesk's Commands. After each change to the API, restart it with
command_restart (name "api"), then read its last lines with command_output to check it started
cleanly. If "web" is not running, start it with command_start. Do not start the stack in a terminal
of your own.
```

## Related pages

- [desk.yml](/docs/desk-yml.md): every key, its default, and when Rundesk edits the file.
- [Terminals and commands](/docs/terminals.md): shells, saved terminals and commands in full.
- [MCP tools and permissions](/docs/mcp.md): every permission agents can be given.
