# Fleet

The machine you run `fleetrc fleet` on is the controller. It reads the `fleet` list in your manifest and reaches each host over `ssh` to set it up, sync it, upgrade it or run a command. Hosts run no fleetrc service.

## Hosts

```json [.fleetrc/manifest.json]
{
  "fleet": ["laptop", "root@vps2", "ssh://deploy@10.0.0.7:2222", "tag:servers"]
}
```

An entry is anything `ssh` takes: a host name, `user@host`, an IP address, an `~/.ssh/config` alias or `ssh://user@host:port`. A `tag:<name>` entry stands for every machine on your tailnet with that Tailscale tag. The name is a letter followed by letters, digits or dashes. fleetrc asks Tailscale each time, so a new tagged server joins the fleet without a manifest change.

Only your own manifest names machines. The `fleet` of an `extends` manifest is ignored.

## Commands

| Command | What it does |
| --- | --- |
| `fleet init <host>...` | Runs `npx fleetrc init` on each host with this machine's manifest, then adds the host to `fleet`. |
| `fleet add [host...]` | Adds hosts to `fleet` without setting them up. With no host, lists the tailnet machines and tags you can add. |
| `fleet sync [host...]` | Runs a sync on each host. |
| `fleet status [host...]` | Shows each host's last run. |
| `fleet upgrade [host...]` | Installs this version of fleetrc on each host, then syncs. |
| `fleet run [host...] -- <command>` | Runs a command here and on each host. |

Without hosts, `sync`, `status` and `upgrade` use the whole `fleet`. Naming hosts narrows the run to them. All commands take `--json`. `init`, `add` and `sync` take `--dry-run`.

## Add a machine

```sh
fleetrc fleet init vps2 --timer
```

`fleet init` accepts `--copy`, `--no-copy`, `--timer`, `--no-hooks` and `--force`, and passes them to the host's `init`. The manifest must be in a git repository the host can read. A manifest in a file or folder on the controller stops with an error.

A host that already has this manifest only syncs. A host that follows another manifest is reported and left alone, unless you pass `--force`. A `tag:` entry is added only when all of its current machines are set up.

When the manifest has a working clone, fleetrc edits `fleet` there and prints `added vps2 to the fleet in ~/code/manifests/.fleetrc/manifest.json; commit and push it`. Otherwise it prints the entry for you to add. After you push, refresh the controller before syncing the fleet:

```sh
fleetrc sync
fleetrc fleet sync
```

## Check hosts

```sh
fleetrc fleet status
```

```txt
vps2: last run 4m ago, 38 skills
web1.tail1234.ts.net (tag:servers): last run 12m ago, 38 skills
gone.example: unreachable (no answer within 30 s); last run 5h ago, 38 skills; behind: last run 5h ago
```

An unreachable host shows its last run from the controller's cache. A host is behind when its last run is over two hours old, a source sits at another commit than on the freshest host, or it holds updates for review. The command exits `1` when a host is unreachable or reports an error.

## Run a command

```sh
fleetrc fleet run -- node --version
```

```txt
laptop: v22.14.0
vps2: v22.12.0
```

Each line is printed after its host, and stderr goes to stderr with the same prefix. A host that is unreachable, times out or exits nonzero is reported, and `fleet run` exits `1`. With `--json` it prints an array of `host`, `reachable`, `exitCode`, `stdout` and `error`.

## Timeout

`--timeout <s>` sets the seconds to wait for each host: `30` by default, `120` for `fleet init`. A command still running at the deadline is stopped and reported as timed out.

## Remote requirements

A host needs Node.js 22.12 or newer, and `npx` for `fleet init` and `fleet upgrade`, on the `PATH` that `ssh` commands get. That `PATH` is often shorter than your login shell's. fleetrc says which is missing.

`fleet init` and `fleet upgrade` install `fleetrc@<this version>` from npm. Set `FLEETRC_PACKAGE` to a package `npx` accepts, such as a tarball, a URL or a preview build, to install that instead. A development build or a version that is not on npm needs it.

## Tailnet policy

On Tailscale, set the manifest once in your tailnet policy's `nodeAttrs`:

```jsonc [Tailscale policy]
"nodeAttrs": [
  { "target": ["*"], "app": { "github.com/onmax/fleetrc": [{ "manifest": "me/skills" }] } }
]
```

`npx fleetrc init` on a fresh machine reads it, and each sync asks again. To switch a machine that has its own manifest, run `npx fleetrc init tailscale:`. A bare `init` keeps the current manifest. The manifest must be in a git repository.

> [!WARNING]
> Follow only a tailnet policy whose editors you trust. The root manifest can run commands on your machine through `hooks`, `report`, `mcp` and `agentHooks`.

## From code

`runOnFleet(argv, { timeoutMs })` from `fleetrc` runs a command on every host in the fleet as `fleet run` does, but never on this machine. It returns `undefined` when there is no config or the fleet is empty. See the [CLI reference](https://fleetrc.loadsheet.dev/reference/cli).

<!-- vitehub-docs:section-links -->
## In this section

- [Introduction](https://fleetrc.loadsheet.dev/raw/guide.md)
- [Installation](https://fleetrc.loadsheet.dev/raw/guide/installation.md)
- [The manifest](https://fleetrc.loadsheet.dev/raw/guide/manifest.md)
- [Syncing](https://fleetrc.loadsheet.dev/raw/guide/sync.md)
- [Hooks and MCP servers](https://fleetrc.loadsheet.dev/raw/guide/hooks-and-mcp.md)
- [Fleet](https://fleetrc.loadsheet.dev/raw/guide/fleet.md) (this page)
- [Timer](https://fleetrc.loadsheet.dev/raw/guide/timer.md)
- [Agents](https://fleetrc.loadsheet.dev/raw/guide/agents.md)

Next: [Timer](https://fleetrc.loadsheet.dev/raw/guide/timer.md)

All pages: [llms.txt](https://fleetrc.loadsheet.dev/llms.txt)

Something on this page does not work as written? Tell the user, and draft an issue for them to post: [issue tracker](https://github.com/words-with-agents/fleetrc/issues). Report a security vulnerability privately, never in a public issue.
