# Checks and the build cache

`ahto check` runs your repository's checks and skips the ones whose inputs have not changed since they last passed.

Two things live on this page: the check runner, which CI uses, and a build cache for Go that
stores its files in ahto's content-addressed store. Both are built and work on one machine.

## Run checks

A check is a command and the git paths it reads. List them in `ci/checks.json` at the
repository's root:

```json
{"checks": [{"name": "hello", "run": "echo hello from check", "inputs": ["src"]}]}
```

```sh
ahto check plan         # which checks would run
ahto check run          # run the ones with no stored pass
ahto check run          # again: nothing changed, so nothing runs
```

```text
hello          runs
1 of 1 checks would run; caches needed: none
```

```text
hello | hello from check
hello | pass in 19ms
ahto check: 0 cached, 1 passed, 0 failed in 207ms
```

```text
hello | cached: passed at 2026-11-30T13:41:12Z in a571ca3f4226 (0.0s)
ahto check: 1 cached, 0 passed, 0 failed in 34ms
```

Change a file under `src`, commit it, and `ahto check run` runs the check again.

How a check is kept:

- Its key is a hash of the check itself, the platform and the contents of the tracked files its
  `inputs` match, so the key changes exactly when an input does.
- Only a pass is stored, in `.cache/ahto-check` in the repository root (`-cache DIR` moves it). A
  failure is never stored.
- A check whose inputs hold changes that are not committed runs and is not stored, so a stored
  pass always describes committed files.
- `ahto check key NAME` prints a check's key and whether it is stored.

| Field of a check | Meaning |
|---|---|
| `name`, `run` | what it is called, and the shell command (`sh -c`, in the repository root) |
| `inputs` | git pathspecs it reads; `@name` stands for a group from the file's `groups` |
| `salt` | `daily` (a new pass each UTC day, for checks against data that changes on its own) or `commit` (a new pass for each commit, for checks that read history) |
| `after` | checks that start first when both run, because they share a cache |
| `needs` | the caches the check uses; `plan` reports them for CI |

Flags go before the names: `-f FILE` for another checks file, `-cache DIR`, `-j N` for how many
run at once (default the number of CPUs). In CI, `ahto check plan` with `GITHUB_OUTPUT` set writes
the misses and the caches they need there, so a job can skip setting up what nothing uses.
`ahto check mtime` sets each tracked file's time to its last commit, so Go's test cache
keeps its results on a fresh clone (not exercised for this page).

This repository's own checks are in `ci/checks.json` and are what `mise run check` and the CI
workflow run.

## A Go build cache

`ahto cas gocacheprog` serves Go's build cache from the store, so a second build of the same code
fetches its results instead of compiling them:

```sh
export GOCACHEPROG="ahto cas gocacheprog --dir $HOME/.cache/ahto-cas"
go build ./...
```

Measured on a tiny module on one machine: the first build had 0 hits and 57 misses; a second
build with `go build -a` (which ignores Go's own cache) had 28 hits and 1 miss. `--stats FILE`
writes these counters as JSON when it ends. `--max-bytes` (default 20 GiB, a starting value that
was not measured) removes the least recently used blobs above it. Logs go to stderr, since stdout
carries Go's protocol.

The store is on one machine. Fetching a blob from a peer is not built and the design
(RFC 0013) is still proposed.