# Local daemon

The local daemon is a background process on your machine. It runs:

- the **Dryv Engine**, which validates, plans and generates;
- the **agent runtime** behind [`dryv code`](/docs/guides/agent) and the VS Code chat;
- **task registry and sync** for [tasks](/docs/guides/tasks).

It listens only on your own machine (`127.0.0.1`). It needs no Dryv account and no key.

## How clients use it

You rarely start the daemon yourself.

- **CLI.** Commands that need the Engine, such as `dryv validate`, `plan` and `generate`, start the daemon when it is not running and use its Engine. `dryv code` and `dryv task sync` also start it.
- **VS Code.** The extension runs `dryv local connect --json` to start or find the daemon.

If you pass `--api <url>` or set `DRYV_API_URL`, the CLI uses that Engine instead and does not start the daemon.

## Ports

The daemon picks free ports when it starts. It serves two addresses:

- the agent API, for example `http://127.0.0.1:41000/v1`;
- the Engine, on its own port.

Each start creates a new random access token for the agent API. Clients read the addresses and token from the daemon's connection file. You never need to copy them.

To choose the agent API port, pass `--port` to `connect`, `start` or `restart`. The Engine port is always picked automatically.

## Commands

```bash
dryv local connect     # start the daemon if needed and print how to reach it
dryv local status      # is it running?
dryv local logs        # print the log (last 200 lines)
dryv local restart     # stop it and start a fresh one
dryv local stop        # stop it
```

| Action | What it does | Options |
| --- | --- | --- |
| `connect` | Starts the daemon if it is not running, then prints its connection details. | `--host`, `--port`, `--runtime-home`, `--json` |
| `start` | Same as `connect`. | Same as `connect` |
| `status` | Reports whether the daemon is running. Exits with status 1 when it is not. | `--runtime-home`, `--json` |
| `restart` | Stops the daemon and starts a new one. Refuses while agent runs are active. | `--force`, `--host`, `--port`, `--runtime-home`, `--json` |
| `stop` | Stops the daemon gracefully. | `--runtime-home`, `--json` |
| `logs` | Prints the daemon log. | `--tail <n>` (default 200), `--runtime-home`, `--json` |
| `link status\|connect\|disconnect` | Shows or changes whether the daemon holds your Platform sign-in. | `--platform <url>`, `--json` |

`restart` will not interrupt work. If runs are active it stops and tells you how many. Use `dryv local restart --force` to restart anyway.

## Where it keeps its files

The daemon home is `~/.dryv/local`. Set `DRYV_LOCAL_HOME` to use another folder.

| Path | Contents |
| --- | --- |
| `daemon.json` | How clients reach the running daemon. Removed when it stops. |
| `credentials.yaml` | Optional model provider keys. See [Dryv agent](/docs/guides/agent#set-your-provider-key). |
| `data/logs/api/api.log` | The log that `dryv local logs` prints. |
| `task-sync.json` | Projects with task sync turned on, so sync resumes after a restart. |

## Signing in and the daemon

`dryv login` stores your Platform session in your operating system's keychain. Each time the CLI reaches the daemon, it hands the session to the daemon, which keeps it in memory only. The daemon uses it for [task sync](/docs/guides/sync).

- `dryv local link status` shows whether the daemon holds a session.
- `dryv local link connect` hands it over now. It fails if you are not signed in.
- `dryv local link disconnect` makes the daemon forget it.

A daemon restarted without the CLI has no session until the next CLI command. Remote control of your machine from the web or mobile app is not available yet.

## Troubleshooting

**"dryv-local was not found."** The CLI looks for the daemon in this order: the `DRYV_LOCAL_COMMAND` variable, the copy packaged with the CLI, `dryv-local` on your `PATH`. Reinstall the CLI, or set `DRYV_LOCAL_COMMAND` to the command that runs `dryv-local`.

**A command hangs, then fails to connect.** Run `dryv local logs` to see why the daemon did not start, then `dryv local restart`.

**The agent does not see a new provider key.** Keys are read when the daemon starts. Run `dryv local restart`.

**You want to use another Engine.** Pass `--api <url>` or set `DRYV_API_URL`. The daemon is then not used for Engine commands.
