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

> ## Agent Instructions
> To set up Hatchmark for a user, follow https://hatchmark.dev/docs/get-started/agent-setup.md. Inside a Hatchmark project, prefer `hatchmark docs`: it prints the docs of the installed version.

# hatchmark build

> Turn a Hatchmark project into static HTML with hatchmark build: what it checks and runs, the files it writes, its JSON result, the build cache and exit codes.

`hatchmark build` turns a project into static HTML: one page per dashboard and per
[report](/docs/guides/reports.md), ready for any static host. It never asks questions and prints one line of
JSON when an agent runs it.

```sh theme={null}
hatchmark build            # writes outDir from hatchmark.yaml (dist by default)
hatchmark build --out site # writes site/ instead, relative to --cwd
hatchmark build --json     # one line of JSON on stdout
hatchmark build --no-cache # run every query instead of reusing .hatchmark/cache/
```

To rebuild on a schedule and serve the pages from inside your network, see
[Production](/docs/guides/production.md).

While you edit, `hatchmark dev` serves the same pages locally and updates them on every save; see
[CLI](/docs/reference/cli.md#dev).

## What it does

1. Loads the project and checks it, like `hatchmark check`. Any error stops the build before a
   query runs (exit 1, the same diagnostics as check).
2. Plans every dashboard, runs its queries in DuckDB over the project's sources (data files, and
   local copies of cloud storage and database sources; see [Data sources](/docs/reference/sources.md)), and resolves
   `asOf: "latest_data"` or `"latest_common_data"` once per dashboard from the source horizons.
   The build machine's clock is read only to warn about future-dated rows (`HM4012`).
3. Renders each dashboard with the theme, the project's `palette`, `brand.logo` and icon files,
   and writes the output directory.

## Output

```text theme={null}
dist/
  sales/index.html          one page per dashboard, named after dashboards/<name>.yaml
  2026-10/index.html        one page per report, named after reports/<name>.md
  index.html                opens the first page of the navigation
  _hatchmark/
    hatchmark.<hash>.js     the browser runtime (tooltips, crosshair, keyboard)
    IBMPlexSans-*.<hash>.woff2
    OFL.txt                 the font licence
    favicon.<hash>.svg      the project's icon files, when it has any (favicon.svg, favicon.png,
                            favicon.ico, apple-touch-icon.png)
    manifest.json           every file this build wrote
```

* Every URL in the output is relative, so `dist/` works on any static host, under any sub-path
  (`https://example.com/reports/`), and opened straight from disk.
* With more than one page, every page links to the others in a sidebar, or a Pages menu on narrow
  screens. `nav` in hatchmark.yaml sets their order, groups and names
  ([Project file](/docs/reference/project.md#navigation)).
* Asset names carry a content hash, so they can be cached forever.
* Icon files next to hatchmark.yaml are copied into `_hatchmark/` and linked from every page as its
  browser icon ([Theme](/docs/guides/theme.md#favicon)).
* With more than one dashboard, a link from one page to another (the navigation, or a relative
  link in a `text` block such as `[Markets](../../markets/)`) keeps the reader's choice for each
  filter the target page also has, with the same `type` and `id` (and, for `select`, the same
  `column`). A period and region picked on one page open the next page on the same view; filters
  the target lacks are left behind, and a value written into the link itself
  (`../markets/?region=EMEA`) wins. Pointing at or focusing a link prefetches the page, and
  Chromium browsers render it ahead. Once a page is idle, Chromium browsers also fetch up to ten
  navigation links in view (on a phone, once the Pages menu opens), unless the reader saves data or
  is on a 2G connection. A tab left open across a rebuild or redeploy can show a page it fetched
  ahead from the previous build until the reader reloads, or, on pages that `hatchmark serve`
  rebuilds, until the page's next build check (every five minutes) drops what it fetched ahead. In browsers with cross-document View
  Transitions the change fades instead of flashing, unless the reader's system asks for reduced
  motion. Both need the pages to be served over HTTP(S); opened from disk, the links still work as
  plain links.
* The output is byte-identical for identical input: the page shows what the data runs through
  ("Data through Oct 31, 2026", with the time when the data ends partway through that day, such as
  "6:54 PM EDT"), never the build time. Pin `period.asOf` to a date if the
  data itself keeps growing and you want reproducible builds.
* Build never deletes a file it did not write. Each build lists its files in
  `_hatchmark/manifest.json`. The next build first writes all of its files under temporary names
  next to their targets; if one can't be written, it removes them, changes nothing and exits 3
  (`HM0004`). Then it moves each file into place and removes the ones the previous build wrote
  that it no longer needs, so a web server serving the directory meanwhile never shows a page
  with missing files. Moving the files into place is not atomic: if a move fails partway (exit 3,
  `HM0004`), the directory mixes the new build and the previous one until a build succeeds, so run
  it again once the cause is fixed; that build takes over every file either one wrote. `hatchmark serve` only ever serves complete builds. Anything
  else in the directory stays. Build refuses (`HM0004`, exit 2) a directory that is not empty
  and has no manifest, a file it would write that the manifest does not list, and an output
  directory that contains the project. Build never follows a symbolic link: it also refuses an
  output directory that is a link (or sits under one inside the project), and any link where it
  would read, remove or write under the output directory. Each file is written fresh and renamed
  into place.

## Who can see the pages

The pages hold the data they show. Besides the numbers on screen, a page embeds what its controls
need: day-level totals for a `period` filter's custom ranges, the numbers for every combination of
a `segment` filter's segments, and each table's full-precision rows for its CSV download (see
[Dashboards](/docs/reference/dashboards.md#filters)). Anyone who can open a page, or a copy of `dist/`, can read
all of it, and nothing in the page asks who they are.

So publish `dist/` where your existing access control already decides who sees the data: an
internal web server or intranet behind your company's sign-in, a private bucket served through
your cloud's signed or authenticated access, or a static host with its own access policy. A public
static host suits only data you would publish anyway. `hatchmark dev` is a preview for the author,
not a way to share pages ([CLI](/docs/reference/cli.md#dev)).

## Network access

Sources other than local CSV, Parquet, JSON and DuckDB files need DuckDB extensions, which DuckDB
downloads the first time a command reads such a source and keeps in
`~/.duckdb/extensions/<DuckDB version>/<platform>/` (under the home directory of the user that runs
Hatchmark):

| Source | Extension | Downloaded from |
| - | - | - |
| `sqlite` | `sqlite` | `extensions.duckdb.org` |
| `postgres` | `postgres` | `extensions.duckdb.org` |
| `mysql` | `mysql` | `extensions.duckdb.org` |
| `sqlserver` | `mssql` | `community-extensions.duckdb.org` |
| `bigquery` | `bigquery` | `community-extensions.duckdb.org` |
| `s3://`, `gs://` or `gcs://` | `httpfs` | `extensions.duckdb.org` |
| `az://` or `azure://` | `azure` | `extensions.duckdb.org` |

When the download fails, the command stops with `HM2044`. Behind a corporate proxy, set
`http_proxy` and Hatchmark downloads them through it
([Proxy and certificates](/docs/reference/sources.md#proxy-and-certificates)). A host without internet access needs the files in place before the first build: run the
same Hatchmark version once on a connected machine with the same operating system and processor,
read every such source there (`hatchmark build` does), and copy its `~/.duckdb/extensions`
directory to the same place on the offline host. A new Hatchmark version can bring a new DuckDB
version, which needs its own copy. The Docker image has these extensions installed already
([Production](/docs/guides/production.md)). The Docker image does not include the BigQuery extension; it
downloads it on first use.

Apart from reading its sources, `hatchmark build` downloads nothing else: fonts, the browser runtime
and the map boundaries ship in the package. `hatchmark render` also needs a Chromium-based browser
and uses an installed Chrome or Edge when there is one; it downloads the Chromium headless shell only with `--install-browser`. On
an offline host, install Chrome or Chromium from your own package source and set
`HATCHMARK_BROWSER`, or copy Playwright's browser cache ([Render to PNG or PDF](/docs/reference/render.md#the-browser)).

## The page

* Header with the project name, dashboard title, the period ("Nov 2025 – Oct 2026 compared with
  Nov 2024 – Oct 2025 · USD"), the description, and the data date. Footer with the source files.
  The period caption lists each currency once, in the order its amounts first appear. No currency
  amounts means no currency list. A `.change_pct` reference alone doesn't add a currency.
* Consecutive `kpi` blocks form one KPI strip. Other blocks are cards in a 12-column grid, as
  wide as their `span`. Line, area and bar charts are at least 3 columns wide (HM2024 warns when
  `span` is smaller); a card that no longer fits beside the cards before it starts the next row.
* Light and dark follow the reader's system setting. `?theme=dark` or `?theme=light` in the URL,
  or `data-theme="dark"` on the `<html>` element, overrides it.
* Layout: charts are drawn at the exact width of each layout (1392, 1232, 976, 720, 552, 358 and
  328 px of content) and the page shows the one that fits, so chart text is never scaled. Below
  1024 px every block takes the full width; on phones KPIs sit two per row.
* Charts carry a text description and a hidden data table for screen readers, and can be stepped
  through with the arrow keys after focusing them (Tab).

See [KPI](/docs/components/kpi.md) for each block type.

## JSON result

```json theme={null}
{
  "format_version": "1",
  "ok": true,
  "error_count": 0,
  "warning_count": 0,
  "diagnostics": [],
  "out_dir": "dist",
  "pages": [
    {
      "dashboard": "sales",
      "path": "dist/sales/index.html",
      "blocks": [{ "id": "revenue", "type": "kpi", "digest": "76a8e355f22f951d" }]
    }
  ],
  "files": 10,
  "cache": { "enabled": true, "dir": ".hatchmark/cache", "hits": 24, "misses": 0, "written": 0 }
}
```

`index` is the page at the site root, which opens the first page of the navigation. Each page
lists its `blocks` in page order with a `digest` of the block's card as `hatchmark render --block`
draws it in the page's default state: its markup laid out with its row, and the theme. The page
title, filter labels and navigation don't enter it. Two builds draw a card the same when its
digest matches; a KPI's digest also covers the strip it sits in, which is how the
[GitHub Action](/docs/guides/github-action.md) finds the charts a pull request changed. `cache` counts the queries reused from the build
cache (`hits`), the ones that ran (`misses`) and the entries written; it is absent with
`--no-cache`. On errors the result is the diagnostic report
described in [Diagnostics](/docs/reference/diagnostics.md) and nothing is written.

## Build cache

Build keeps every query result, and the latest date of every time column it measured, in
`.hatchmark/cache/` as Parquet files, so the next build runs only the queries whose inputs
changed. `hatchmark init` adds `.hatchmark/` to `.gitignore`.

When `HATCHMARK_STATE_DIR` is set, every command keeps what it would write under `.hatchmark/`
there instead: the build cache, `tmp/`, database copies and `copy-key`. Set it to build a
read-only checkout, such as in CI or a container; the project itself is then never written.

* A result is reused only when everything that decides it is unchanged: the query (its metric,
  filters, grouping, window and the source's reader options in `hatchmark.yaml`), the as-of date,
  time zone, week and year anchors and filter defaults, the contents of the data files it reads,
  and the engine (the Hatchmark version, its query and executor code, and the DuckDB version).
* Data files are compared by the SHA-256 of their contents, never by size or modification time,
  so any changed byte runs the query again. Build first copies each data file it reads into
  `.hatchmark/tmp/` (a copy-on-write clone where the file system supports it), hashes the copy and
  runs the queries on the copy, so a file edited while a build runs can never be stored under the
  wrong fingerprint. The copy is removed when the build ends.
* Queries of raw SQL metrics (`type: sql`) always run and are never cached: their SQL can
  read the clock or other files, which no cache key can see.
* A cached build writes the same bytes as `hatchmark build --no-cache`. A damaged or unreadable
  entry is ignored and rewritten.
* Each build removes the entries it did not use, so the cache holds the last build's results.
  Deleting `.hatchmark/cache/` is always safe.
* The cache is best effort: it never fails a build or changes its output. When `.hatchmark` or
  a directory under it that the cache uses is a symbolic link, unreadable or unwritable, or when
  copying a data file, writing an entry or removing an unused one fails, the cache turns off for
  the rest of the command. The build continues as with `--no-cache`, prints one warning, and
  reports `enabled: false` with the reason in `cache.reason`; `explain` shows such queries as
  `off`.

`hatchmark explain --dashboard <name> --block <id>` lists each query's cache status after its SQL:
`hit` with the time the entry was stored, `stale` with what changed since (`data` with the file,
`context` such as the as-of date, or `engine`), `miss`, or `off` for raw SQL metrics. Editing a
query itself (a metric's filters, a block's grain) gives it a new id, so it shows as a `miss`.

## Exit codes

| Code | Meaning |
| - | - |
| 0 | Built. Warnings are allowed. |
| 1 | Errors in the project's files; nothing was built. |
| 2 | Usage or configuration error, or the output directory was refused (`HM0004`). |
| 3 | Environment problem, such as a data file that does not exist. |
| 4 | Internal bug in Hatchmark. Please report it. |

## Try it

```sh theme={null}
hatchmark init shop && cd shop
hatchmark build
open dist/sales/index.html
```


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