# Koshi 0.5.0 — Update and versions (/docs/v0.5/cli/update)



```bash
koshi update
```

`koshi update` installs the newer release the way koshi was installed:

| Install                   | What `koshi update` does                                                                                                                                                                                                         |
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Homebrew                  | Runs `brew upgrade gohyuhan/koshi/koshi`. `brew` decides whether a newer version exists. A formula pinned to one version, such as `koshi@0.5.0`, is not upgraded; the command names `brew install gohyuhan/koshi/koshi` instead. |
| Scoop                     | Downloads the newest release archive, checks its SHA-256 checksum, and replaces `koshi.exe` in place. Scoop still lists the version it installed.                                                                                |
| Release script or archive | Downloads the newest release archive for this OS and architecture, checks its SHA-256 checksum, and replaces the program file in place. A symbolic link stays and the file it names is replaced.                                 |
| Built from source         | Downloads nothing.                                                                                                                                                                                                               |

If the installed version is the latest, it says so and exits successfully.
Network, platform, archive, checksum, permission, and install failures return
an update error.

On Linux and macOS, the new file replaces the old one in one rename. A program
file in a root-owned directory, such as `/usr/local/bin`, is installed with
`sudo install -m 755`. On Windows, the running `koshi.exe` is renamed to
`koshi.old` and the new one takes its path; `koshi.old` is removed on a later
launch.

## The running sessions move too [#the-running-sessions-move-too]

After every update, whether or not it installed a release, `koshi update`
restarts each running session into the installed koshi, and then the router,
the background process that tracks sessions. A release install skips a session
that already runs the installed version. A build from source restarts every
session.

A session keeps its panes, the programs running in them, and their scrollback.
An attached client reconnects to its session on its own. Saved sessions,
config files, remote access records, saved servers, certificates, and runtime
files are converted to the new build's formats as it opens them.

Sessions started by koshi 0.3.0, 0.4.0, or 0.5.0 restart this way. A session
started by koshi 0.1.0 or 0.2.0 keeps running its old build; end it and start a
new one to use the installed build.

<Callout type="warn">
  A session that refuses the restart is named on standard error and keeps the old
  build until you end it and start it again.
</Callout>

A session refuses the restart when:

* a pane's program stopped reading its input;
* a pane has no terminal to carry;
* this machine cannot run the new binary;
* the new binary does not read the resume file this build writes.

A session running a koshi with no restart at all, one that still reports the
old version after the restart, and one that answers nothing within ten seconds
are all reported the same way.

## `restart-servers` [#restart-servers]

```bash
koshi restart-servers
```

Restarts every running session, then the router, into the koshi program on
disk, and installs nothing. Use it after koshi is installed another way, such
as by a package manager. Every pane keeps running. The command prints one line
per server, and exits 1 if any server does not come back on the version of the
koshi that ran the command.

A running session or router also restarts by itself when the koshi program it
started from now holds another version: the next koshi command that connects
to it starts the restart.

## Which build is running where [#which-build-is-running-where]

```bash
koshi version                  # the koshi program you just ran
koshi server-version           # every running koshi server
koshi server-version --session <NAME_OR_ID>
koshi server-version --format json
```

`koshi version` prints the same line as `koshi --version`:

```text
koshi version
koshi 0.5.0
```

The two answers differ while an update rolls out — the program your shell runs
is a newer build than the process answering it until every restart lands:

```text
koshi server-version
kind     session                                       version
router   -                                             0.5.0
session  session-3f2a1c94-8e7b-4d15-9a02-6c5138ef7b40  0.5.0
session  session-91c4de07-2b53-41a8-bf6e-70d9a2c81f35  0.4.0
```

| Cell                  | Meaning                                                                                                                     |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| a build, like `0.5.0` | The server answered and named it                                                                                            |
| `unknown`             | The server answered and is too old to name its build                                                                        |
| `not running`         | Nothing is listening there                                                                                                  |
| `unreachable`         | The server could not be asked, the session is restarting, or it did not answer in time; the reason prints on standard error |

A server that could not be asked does not stop the rest of the answer: the
other rows still print, and the command exits 4. Everything answering exits 0,
including a machine running nothing at all.

`--session` reports that one session and leaves out the router. It takes the
session id or its exact generated name, and a name must match exactly one
running session.

## Startup checks [#startup-checks]

Interactive launches can check on an interval and ask before installing:

```kdl title="koshi.kdl"
version 2

update {
    auto-check #true
    check-interval-days 14
    allow-prerelease #false
}
```

Startup check failures never block or crash a normal launch. koshi stores only
the last-check time in `update.json` in its state directory; it never rewrites
`koshi.kdl`. A build from source checks nothing.

`allow-prerelease #true` lets the startup check and `koshi update` choose
pre-releases too. A Homebrew install is offered stable releases only.
