# Update

> Keep bay current with `bay update`, an hourly background check, and version pins.

Source: https://getbay.io/docs/update (HTML).

`bay update` installs a newer bay release. It verifies the signed `SHA256SUMS`, the signed `VERSION`, and the sha256 before it replaces the program. It runs the new program once, then renames it over `~/.local/bin/bay` (`bay.exe` on Windows), whichever copy ran the update. Then it runs `bay install --machine`. That copies the matching skill into every Claude config directory, and changes no repository.

It refuses a downgrade unless a pin names the older version. Update settings belong to the machine, not to a repository.

```sh
bay update                     # the newest release with a build for this machine
bay update --version <x.y.z>   # one exact version, newer than this one
bay update --check             # report only; changes nothing
```

> Its result names the installed version and the new one.
> `detail.changes` lists each newer release's notes, newest first, `bay update --check` too.

> The update installs the new guide itself.
> When that install fails, the result is `failed`, but the new program stays.
> Run `bay install`.
> After a background update, the `bay` row of `bay doctor` then shows `install_error`.
> Its sentence names what is left: `bay doctor` in each repository.
> Doctor names any hook a repository's settings now lack.

## Update while a runner runs

`bay update` and the hourly check never wait for a runner to stop. bay keeps each version it installs, and each version a runner runs, at `$XDG_DATA_HOME/bay/versions/<version>/bay`. Without `XDG_DATA_HOME`, that folder is under `~/.local/share`. An update keeps the newest three versions there, its own version, and each live runner's version. A runner's operation starts each child `bay` from its own version, so it ends on the version it started with. Between operations, `bay runner run` runs the new version in the same process, and names the move in `detail.reexec`.

> `bay host serve` moves to the new version between passes in the same way.
> With `--once`, or on Windows, a runner keeps its version until it starts again.
> A runner never moves to a new bay that does not take its own command, such as `bay runner run`.
> A runner with a pin moves to its pin or a newer release, never to an unreleased build.
> Either way, it keeps running its version, and says why once on stderr.
> It asks again each pass, so a pin that moves later moves the runner then.

## Automatic updates

At most once an hour, `bay status` or `bay doctor` starts `bay update` in the background. A looping `bay runner run` starts it too. A newer release installs on its own, never during a merge. The check downloads from GitHub only, and sends no repository data.

Set `bay.updateAuto` to `false` in your global Git config to turn it off. `BAY_DISABLE_AUTOUPDATE=1` turns it off too, and it wins over every setting. A pinned machine still follows every newer release.

```sh
git config --global bay.updateAuto false
```

## Which release

`bay update` takes the newest release that has a build for this machine. When the newest release has no build for it, bay skips back to the newest one that has. It reads GitHub's release list with `GH_TOKEN` or `GITHUB_TOKEN` when one is set. When GitHub turns that read away, bay reads the newest version from the release page. Version numbers are 0.x, so a minor release can still change a command. The changelog names each change.

## Release keys

`bay update` trusts a list of release keys, so a key can roll over. It trusts two: the release key, held in hardware, and the 0.x build key. While bay is 0.x, the build key signs each release on the machine that builds it. The build key goes before 1.0. The install script trusts the same two keys.

## After a key rollover

`bay update` steps through a release-key rollover on its own. When it cannot verify the newest release's signature, it tries older releases, newest first. It installs the newest one it can verify that is newer than the installed bay. `detail.stepped` is then `true`, and `detail.next` says to run `bay update` again. `--version` never steps, and neither does a pin newer than every release. bay refuses a release whose sha256 does not match.

## Pins

A pin is the oldest version a machine runs. A pin is `bay.updateVersion` in global Git config, or `BAY_UPDATE_VERSION` for one process. With the variable, one agent on a shared login can choose its own version. A pinned machine follows every newer release, so a pin left behind never holds it back. A build that was never released never moves a pinned machine. A repository cannot pin the machine, so a cloned repository never moves or downgrades bay.

```sh
git config --global bay.updateVersion <x.y.z>
```

> On a pinned machine, `bay install` refuses with `UPDATE_PINNED` unless that bay is the pinned version or the newest release.
> So a test or another agent never moves a shared runner back.
> A pin below the installed bay is never the target.
> `--version` moves a machine back only to the exact version its pin names.
> bay refuses any other older version.
> To go back, pin the older version, run `bay update --version` with it, and turn off automatic updates.

## Refusals

| Code | Meaning | What to do next |
|---|---|---|
| `UPDATE_UNVERIFIED` | The signature, sha256 or `VERSION` did not verify, or the new program did not run. Nothing changed. | Keep the installed bay and tell the user; run `bay update` again once the release is republished. |
| `UPDATE_PINNED` | The target is older than the pin of this machine, or older than the installed version. | Keep this version: `bay update` moves only after this machine's pin moves. |
| `UPDATE_UNAVAILABLE` | No release could be read: the network is down, GitHub turned the read away, or no release matches this platform or version. | Run `bay update` again later, once a release is reachable. |
