> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Bach builds Windows installers from one bach.toml with the bach command: bach init, bach check, bach preview, bach build. Installs are per user and need no administrator rights by default. installer.scope = "machine" installs for every user after one Windows prompt. On Windows, run setup files with Start-Process -Wait -PassThru in PowerShell, and give signtool arguments that start with the word sign.

# Set up automatic updates

> Let your installed app find, download and install new versions on its own, and let your app check for updates or update when the user quits.

With automatic updates, people who installed your app get new versions without downloading anything. This page shows how to turn them on, what they do on the user's computer, and how your app can check for updates itself.

Turn this on before your first public release if you can. A copy installed without `[updates]` can't update itself later; its user has to run a newer setup file once.

## 1. Say where updates come from

If your code is on GitHub and the repository is public:

```toml bach.toml theme={"theme":{"light":"github-light","dark":"github-dark"}}
[updates]
github = "your-name/hello-notes"
```

For any other `https` host:

```toml bach.toml theme={"theme":{"light":"github-light","dark":"github-dark"}}
[updates]
feed = "https://example.com/hello-notes/latest.json"
download_url = "https://example.com/hello-notes/{file}"
```

`feed` is the address of the update feed. `download_url` is where the setup file will be, with `{file}` replaced by its name. [Where to host updates](/docs/guides/update-hosting.md) walks through both.

Your version must be numbers with dots, such as `1.2.0`, so Bach can compare versions.

## 2. Build and publish

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
bach build
```

Next to the setup file you now get `latest.json`:

```json latest.json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "version": "1.1.0",
  "url": "https://example.com/hello-notes/Hello%20Notes-Setup-1.1.0.exe",
  "sha256": "<checksum of the setup file>",
  "size": 10187776
}
```

Upload both files. For every new version, upload the new setup file and replace `latest.json`. If you [sign](/docs/guides/signing.md) the setup file after building, write the feed again with [`bach feed`](/docs/reference/cli/feed), because signing changes the file.

## What the user sees

The install window has an extra box, **Automatic updates**, ticked. If the user leaves it ticked, setup creates a Windows scheduled task for their account that checks for updates every four hours, and soon after the computer is turned on again if a check was missed. It runs hidden and needs no administrator rights.

Each check:

1. reads the feed
2. downloads a newer version, if there is one
3. installs it, but only if your app isn't running; otherwise it waits for a later check

Your app is never closed while someone is using it.

Unticking the box during a later update removes the task. So does uninstalling.

### Change the default

```toml bach.toml theme={"theme":{"light":"github-light","dark":"github-dark"}}
[updates]
github = "your-name/hello-notes"
auto = false
```

| `auto` | Meaning |
| - | - |
| `true` | Offered, ticked (the default) |
| `false` | Offered, unticked |
| `"always"` | Always on, not asked |
| `"never"` | No background updates; your app can still check |

Apps that [install for every user](/docs/guides/machine-wide-installs.md) can't update in the background, because a normal user can't write to Program Files. Leave `auto` out for them.

## Check for updates from your app

The installed `uninstall.exe` also handles updates. Your app can run it:

| Command | What it does | Exit code |
| - | - | - |
| `uninstall.exe --check-update` | Says whether there's a newer version | 10 if yes, 0 if not |
| `uninstall.exe --check-update --json` | The same, as JSON | same |
| `uninstall.exe --download-update` | Downloads it and keeps it ready | 10 if ready |
| `uninstall.exe --apply-update` | Installs the downloaded update | 0 if done or nothing to do |
| `uninstall.exe --update` | Downloads and opens the setup window | setup's result |

`--json` prints one line with `app`, `current`, `latest`, `available`, `downloaded`, `notes` and `size`.

`uninstall.exe` is in your app's install folder, next to your program.

### Update when the user quits

A common pattern:

1. When your app starts, run `uninstall.exe --download-update` in the background.
2. When the user quits, or clicks "Restart to update", start this and exit:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
uninstall.exe --apply-update --wait-for <your process id> --launch
```

`--wait-for` waits for your app to close, and `--launch` starts it again after updating. The download already happened while the app was open, so the update itself takes a moment.

To try the commands in PowerShell, use `Start-Process`, which waits and gives you the exit code:

```powershell theme={"theme":{"light":"github-light","dark":"github-dark"}}
$p = Start-Process "$env:LOCALAPPDATA\Programs\Hello Notes\uninstall.exe" -ArgumentList '--check-update' -Wait -PassThru
$p.ExitCode
```

## Interrupted updates

* If the download stops, it continues where it left off next time.
* If a file is held for a moment, for example by a virus scanner right after your app closes, `--apply-update` tries three times, then keeps the download for later.
* If the computer shuts down during an update, the next check or setup puts the old files back first.

## When something goes wrong

Every update run writes `%TEMP%\<app id>-update.log`. [Why aren't automatic updates working?](/docs/troubleshooting/updates.md) goes through the usual causes.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.