> ## 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.

# How a setup file works

> What is inside a Bach setup file, what happens step by step during install, update and removal, and why an interrupted update can be undone safely.

You don't need this page to use Bach. It's for when you want to know what happens on your users' computers, for example to answer a security question or to debug an unusual problem.

## What's in a setup file

A setup file is Bach's install window program (`bach-setup.exe`) with your app attached to the end of it. `bach build` copies the program, sets your icon and file details on the copy, and appends:

```text theme={"theme":{"light":"github-light","dark":"github-dark"}}
[ install window ] [ your files, compressed ] [ logo, fonts, pictures ] [ manifest ] [ trailer ]
```

The **manifest** is a list of everything setup needs to know: the app's name and version, every file with its size and checksum, the options, texts, license and look. The **trailer** at the very end says where each part starts.

Because Windows ignores extra data after a program, the file runs like any `.exe`. When it starts, it reads its own manifest and shows the window. On its own, `bach-setup.exe` has nothing attached and installs nothing.

## Installing and updating

1. **Check.** Requirements are present, no other setup for this app is running, the app isn't open, and there's enough disk space.
2. **Remove a previous installer's version**, on a first install only, if [`[[migrate]]`](/docs/reference/config/migrate) names it.
3. **Unpack** every chosen file next to where it belongs, as `<name>.bach-new`. The archive is checked against its recorded checksum as it's read.
4. **Swap.** Only when everything unpacked correctly, the new files are moved into place. Each replaced file is first renamed to `<name>.bach-old`.
5. **Finish.** Run steps, services, shortcuts, `PATH`, links and file types are set up, `uninstall.exe` is written and the app is listed under Settings › Apps.
6. **Clean up.** Old copies are deleted, along with files the previous version installed that this one doesn't have.

If anything in steps 3 to 5 fails, the earlier version is put back. While files are being unpacked the window has a **Cancel** button; while they're moved it can't be closed.

### If the power goes out

Before moving any file, setup writes a small journal, `.bach-update`, into the install folder. If a crash or power cut stops the move halfway, the next install, update or removal (or background update check) reads the journal and puts the old files back. The journal is only deleted once that has worked. If a program holds one of the files, setup says which, and you can try again after closing it.

## The uninstaller

`uninstall.exe` is the same install window program with the manifest of what was installed and the user's choices, without your files. Settings › Apps runs it. A program can't delete itself, so it copies itself to the temporary folder, runs from there and removes itself last. (For apps installed for every user it runs in place, with administrator rights.)

It deletes the files in its list, then empty folders. Files that were changed after install, and files it never installed, stay.

## Updates

With `[updates]`, `uninstall.exe` also checks the update feed and downloads newer setup files into `%LOCALAPPDATA%\Bach\updates\<app id>`, using Windows' own `curl.exe` over `https` only. Before running a downloaded file, it checks it again: checksum, app id and version, plus your signature if you [require one](/docs/guides/update-security.md). The background task is a per-user scheduled task called `Bach\<app id>`.

The [online installer](/docs/guides/other-builds.md#online-installer) works the same way: it downloads the newest setup file and installs from it.

## Run programs

[`[[run]]`](/docs/reference/config/run) steps start programs from your own files, without a command shell. They run as the current user unless the step says `elevated = true`.

## Languages

The window reads the user's Windows display languages, most preferred first, and picks the first one your app offers. If none match, it uses your first language. Your `[text]` entries replace the built-in texts.

## The same input gives the same file

Building the same files with the same `bach.toml` and the same Bach version produces the same setup file, byte for byte, on any computer. So anyone can rebuild a release and compare checksums:

```powershell theme={"theme":{"light":"github-light","dark":"github-dark"}}
bach build --out check\Setup.exe
(Get-FileHash check\Setup.exe).Hash
```

Three things change the result on purpose: an access key (it uses random values), signing, and a different Bach or `bach-setup.exe` version.

## Keeping old files working

Setup files already on people's computers have to keep working. The format only changes with a new format version, and an older setup reports a clear error instead of guessing. A damaged or edited setup file shows a message instead of installing.

## On macOS

With a [`[macos]`](/docs/reference/config/macos) section, `bach build` also makes a Setup app, `Install <app>.app`, inside a `.dmg`. It has the same install window and the same install code, with these differences:

* Your files aren't attached to the program. They're a separate file inside the app bundle, because adding data to a Mac program breaks its code signature.
* The uninstaller is an app kept out of sight in your Library folder. Users remove your app by moving it to the Trash, and Bach then cleans up what it added.
* File permissions and symbolic links are kept, so frameworks keep working.
* Updates download the `.dmg`, check it and run its Setup app without a window.

[Files and locations](/docs/reference/setup/files-and-locations.md#on-a-mac) lists where everything goes.

## ARM64

The default `bach-setup.exe` is built for x64, which Windows 11 on ARM runs through emulation. For a native ARM64 installer, see [Other builds](/docs/guides/other-builds.md#arm64). The `vcredist` requirement checks for the x64 runtime on x64 computers, and accepts the x64 or ARM64 runtime on ARM.

## Large file lists

The manifest takes about 120 bytes per file, and is stored in the setup file and again in `uninstall.exe`. It isn't compressed so that older installed copies can still read newer setup files. `bach check` warns when it passes about 2 MB; fewer, larger files (for Electron, an `asar` archive) keep both smaller.


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