# Remote hosts

> Run terminal sessions on a zidane server, open the whole window on one server, and lend this machine to a server.

The terminal app can run sessions on a [zidane server](https://zidane.si/docs/server.md). The [server clients](https://zidane.si/docs/server-clients.md) page covers hosts, machines and settings sync in every client.

| You want | Use |
| - | - |
| Some sessions on a server, others on this computer | [Remote hosts](#remote-hosts) |
| The whole window on one server | [`--host`](#open-the-app-on-one-server) |
| A server's sessions working in your folders | [Lend a machine](#lend-a-machine) |

## Remote hosts

Remote hosts are off by default. Turn on Settings › Agent › Remote hosts ([kill switches](https://zidane.si/docs/server-clients.md#turn-remote-hosts-on)). The Hosts tab then shows in Settings.

### Add a server

*Terminal: Settings, Hosts tab: this computer, and a row to add a server.*

```text
┌─ settings ───────────────────────────────────────────────────────────────────────────────┐
│                                                                                          │
│   Agent 44   UI 37  [Hosts]  Keybindings   Authentication   Instructions   Skills        │
│   MCP servers   Extensions & Plugins                                                     │
│                                                                                          │
│  ┌────────────────────────────────────────────────────────────────────────────────────┐  │
│  │ search hosts settings by name or description…                                      │  │
│  └────────────────────────────────────────────────────────────────────────────────────┘  │
│                                                                                          │
│  ▶ ● This computer                                           connected  in this window   │
│    + add a server                                                                        │
│                                                                                          │
│                                                                                          │
│                                                                                          │
│                                                                                          │
│                                                                                          │
│                                                                                          │
│                                                                                          │
│                                                                                          │
│                                                                                          │
│                                                                                          │
│                                                                                          │
│                                                                                          │
│                                                                                          │
│                                                                                          │
│                                                                                          │
│                                                                                          │
│  ↑↓ navigate  ←→ tabs                                                                    │
│                                                                                          │
└──────────────────────────────────────────────────────────────────────────────────────────┘
```

## 1. Get a token

On the server, run `zidane-server token create --name laptop`. The command prints the token once ([server tokens](https://zidane.si/docs/server-security.md#tokens)).

## 2. Add it

In Settings › Hosts, press `Enter` on `+ add a server`. Type the address (`wss://host:port`) and press `Enter`. Paste the token and press `Enter` to connect and save. zidane saves the server only if it answers.

## 3. Use it

When you start a new session, zidane asks where it runs. The sessions list groups sessions by host.

| Key on a server row | Does |
| - | - |
| `Enter` or `Ctrl`+`T` | Test the connection |
| `Ctrl`+`B` | Machines lent to the server |
| `Ctrl`+`S` | Send this computer's settings to the server ([settings sync](https://zidane.si/docs/server-clients.md#settings-sync)) |
| `Ctrl`+`E` | Rename |
| `Ctrl`+`U` | Change its URL (prefilled). Keeps the token, and saves once the same server answers there. |
| `Ctrl`+`X` | Remove. Press `Y` to confirm or `N` to keep it. |

zidane saves the servers in `hosts.json`, which the desktop app also reads. The tokens go in the credentials file ([files and folders](https://zidane.si/docs/files.md)). In a server session, [Settings](https://zidane.si/docs/tui-settings.md#tabs) edits the server's side. `!` commands run on the server, in the session's folder.

## Open the app on one server

`--host` points the whole window at one server. zidane does not save the server:

```bash
zidane --host wss://zidane.example.com --token-file ~/.config/zidane/box.token
```

| Flag or variable | Use |
| - | - |
| `--host <wss-url>` | The server |
| `--token-file <path>` | Read the token from a file. `-` reads stdin. |
| `--token <t>` | The token itself. It shows in `ps` and your shell history, and zidane prints a warning. `--token -` reads stdin. |
| `ZIDANE_HOST_URL` | `--host` from the environment |
| `ZIDANE_HOST_TOKEN` | The token from the environment |

`--no-remote` and `ZIDANE_NO_REMOTE=1` refuse `--host` and ignore `ZIDANE_HOST_URL` with a warning. `zidane run --json` and `--json-schema` runs stay local and refuse `--host`. What runs where: [server clients](https://zidane.si/docs/server-clients.md#tui).

## Lend a machine

To add a computer as a machine that starts at boot, run `zidane machine setup --join <url>#<code>` on that computer. The `<code>` part is a join code, a one-time code from the server ([servers and machines](https://zidane.si/docs/servers-and-machines.md)). On a server row in Settings › Hosts, `Ctrl`+`B` opens its machines. The `add a machine` row (`Enter`) shows that command with a new join code. `C` copies it and `Esc` closes it.

`zidane machine share` lends this computer's folders and a shell to a server's sessions:

```bash
zidane machine share --host wss://zidane.example.com --token-file machine.token --name studio --root ~/code
```

Repeat `--root` for several folders. File operations cannot reach outside these folders. Shell commands from the server run as your user, so share only with servers you trust.

Each flag can come from a `ZIDANE_MACHINE_*` variable instead (`ZIDANE_MACHINE_HOST`, `_NAME`, `_ROOTS`, `_TOKEN_FILE`, `_DATA_DIR`). Without a token file, `ZIDANE_MACHINE_TOKEN` holds the token itself. `--env-file <file>` reads them from a file of mode 600. A flag wins over the environment, and the environment wins over the file.

The token must have the `machine` scope. On the server, create it with `zidane-server token create --name studio --scope machine` ([machines](https://zidane.si/docs/server-clients.md#machines)).

## Local hosts

| Host | Does |
| - | - |
| `zidane server` | Runs a server on this computer for other windows ([install the server](https://zidane.si/docs/server-install.md)) |
| The [daemon](https://zidane.si/docs/daemon.md) | A background process that keeps runs going after you close the window and shares them with your other windows. Settings › Agent › Use daemon runtime turns it on. |

## Reference

- [Server clients](https://zidane.si/docs/server-clients.md) and [server protocol](https://zidane.si/docs/server-protocol.md)
- [`zidane/ipc`](https://zidane.si/docs/reference/ipc.md) and [`zidane/ipc/remote`](https://zidane.si/docs/reference/ipc-remote.md)
