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

# Run in production

> Run hatchmark serve in Docker inside your network: it rebuilds the dashboards on a schedule, serves the last good build, flags stale data and reports failures.

Run Hatchmark next to your data. One container rebuilds the dashboards on a schedule and serves
the last good build to your colleagues. It runs inside your own network, beside the database, so the
database never has to be reachable from the internet.

```sh theme={null}
docker run -d --name hatchmark --restart unless-stopped \
  -p 8080:8080 \
  -v "$PWD/analytics:/project:ro" \
  -v hatchmark-data:/data \
  --env-file hatchmark.env \
  ghcr.io/hatchmark-dev/hatchmark:<version> \
  serve --host 0.0.0.0 --port 8080 --at 06:00 --tz America/New_York
```

That is the whole setup: `hatchmark serve` builds at once, then every day at 6 AM New York time,
and serves the dashboards at `http://<host>:8080/`. Pin the image to a version tag rather than
`latest`, so a rebuild never changes Hatchmark under you.

## The image

Every Hatchmark release publishes `ghcr.io/hatchmark-dev/hatchmark` for `linux/amd64` and
`linux/arm64`, so one tag runs on x86 servers and on ARM hosts such as AWS Graviton or Apple silicon.

```sh theme={null}
docker pull ghcr.io/hatchmark-dev/hatchmark:<version>
```

| Tag | Points to |
| - | - |
| `<version>`, such as `1.4.2` | That release. |
| `<major>.<minor>`, such as `1.4` | The highest stable release of that minor version. |
| `latest` | The highest stable release. |

A prerelease such as `1.5.0-rc.1` gets only its own version tag, and a patch to an older line, such
as `1.3.9` after `1.4.0`, never moves `latest`. Each image carries its SBOM and build provenance:

```sh theme={null}
docker buildx imagetools inspect ghcr.io/hatchmark-dev/hatchmark:<version> --format '{{ json .SBOM }}'
docker buildx imagetools inspect ghcr.io/hatchmark-dev/hatchmark:<version> --format '{{ json .Provenance }}'
```

## Why it runs inside your network

Production databases usually sit in a private network, and a build has to read them. A build on a
hosted CI runner or a laptop can't reach them, so the build runs on a machine that can: a VM, a
Kubernetes cluster or any container host in the same network as the database. The pages it serves
hold only aggregated results, never a connection to the database.

## The project

Mount the project directory (the one with `hatchmark.yaml`) at `/project`, read-only. Before each
build, serve copies it into its state directory, so a build always sees one consistent version of
the project even while it changes. To ship an edit, update the directory with `git pull` on the
host, a deploy job, or a git-sync sidecar in Kubernetes. The next build picks it up.

## Secrets

`hatchmark.yaml` names environment variables and never holds a connection string (see
[database sources](/docs/reference/sources.md#credentials)). Give the container those variables, for example with an env file that
only the deploy user can read:

```sh theme={null}
# hatchmark.env
SHOP_DATABASE_URL=postgresql://hatchmark_reader:...@db.internal:5432/shop
```

In Kubernetes, put them in a Secret and pass it with `envFrom`. Use a database user that can only
read.

The image includes the database and cloud storage extensions Hatchmark uses (PostgreSQL, MySQL,
SQLite, S3, GCS and Azure, and SQL Server where available), so builds need no internet access to
fetch them.

## Schedules

| Option | Builds |
| - | - |
| `--every 1h` (default) | Every hour, counted from the start of each build (`30m`, `1d`). |
| `--at 06:00` | Every day at 6:00. Several times: `--at 06:00,18:00`. |
| `--tz America/Chicago` | The time zone of `--at`, any IANA name. Default UTC. |
| `--timeout 30m` | Stops a build that runs longer and records it as failed. Default: see below. |

serve always builds once at start. It never runs two builds at once: a build that overruns its
interval is followed by the next one straight away. A query that hangs is stopped at the timeout,
so it can't hold up the builds after it.

The default timeout follows your builds: twice the slowest of the last 20 good builds, and at least
the interval up to one hour. Until a build has succeeded it is one hour, since the first build fills
the cache and is the slowest. A project whose data grows gets a longer timeout as its builds slow
down, without a setting.

Frequent builds stay cheap. Each one reuses the results of queries whose inputs didn't change (the
[build cache](/docs/reference/build.md#build-cache)), and a database source reuses its local copy while it is younger
than its `max_age`. Match `max_age` to how often the table really changes: a table loaded once a
night needs `max_age: { hours: 12 }` even when the dashboards build every hour. The cache lives in
the state directory, so it survives restarts.

## When a build fails

The last good build keeps being served. A failed build never replaces it.

Every page footer shows when its data was updated. A page calls its data late, and shows a banner
saying it may be out of date and since when, only when a build has started and neither it nor any
later build has succeeded by its start plus its timeout plus a grace period. The grace period is a
tenth of the interval between scheduled builds, at least 15 minutes: 15 minutes for hourly builds,
2 hours 24 minutes for a daily one. So a build that is still running is never late, a slow build
that finishes inside its window raises nothing, and a failed build that the next one fixes in time
raises nothing either. A page that stays open while a newer build replaces it says newer data is
available and offers a reload, rather than claiming the new update time for the numbers it shows.

* Each build logs one JSON line to stdout (`docker logs hatchmark`) with its result, duration,
  cache reuse and, for a failure, the full diagnostics.
* `/status` shows the last 20 builds with their error codes, and `stale` turns true at the same
  moment the banner appears.
* A webhook can tell you, see below.

Until the first build succeeds, viewers see a "not ready yet" page with status 503. The reason is
only in the logs, because diagnostics can name tables and columns.

### Webhook

Set `HATCHMARK_WEBHOOK_URL` to an http or https URL and serve POSTs JSON to it when the data turns
late, by the same rule as the banner, and again when a build succeeds after that. A database that
stays down for a night sends one message, not twelve, and a single failed build that the next one
fixes sends none. The late time and whether the alert went out are kept in the state directory,
so a restart during an outage neither moves the deadline nor sends the alert again.

```json theme={null}
{
  "event": "data.late",
  "text": "Hatchmark: no build has succeeded since 2026-11-29T11:00:00.000Z, and one was expected by 2026-11-30T14:24:00.000Z. The last build, at 2026-11-30T11:00:00.000Z, failed (HM2041). The dashboards still show data updated 2026-11-29T11:00:00.000Z.",
  "at": "2026-11-30T14:24:30.000Z",
  "schedule": "daily at 06:00 America/New_York",
  "updated_at": "2026-11-29T11:00:00.000Z",
  "expected_by": "2026-11-30T14:24:00.000Z",
  "last_run": {
    "at": "2026-11-30T11:00:00.000Z",
    "ok": false,
    "timed_out": false,
    "codes": ["HM2041"]
  }
}
```

`event` is `data.late` or `data.recovered`. `last_run.codes` are the diagnostic codes
(`hatchmark explain HM2041` explains one), and the payload never includes diagnostic messages,
which can name tables and columns, or any secret. Anything that accepts a JSON POST can receive it.
Tools that read a `text` field, such as a Slack incoming webhook, show the sentence as is; for
others, forward the payload with your own automation. serve tries three times over about half a
minute and logs the result, never the URL.

## Health checks

| Path | Answers |
| - | - |
| `/healthz` | 200 while the process runs. Use it for liveness. |
| `/readyz` | 200 once a good build exists, else 503. Use it for readiness. |
| `/status` | JSON: `ready`, `stale`, `updated_at`, `stale_at`, `next_run_at`, `timeout_ms`, `grace_ms`, and `runs` with error codes. |
| `/_hatchmark/status.json` | What the pages read: update time, late time, the last build's result and the build the pages belong to. |

Neither JSON route holds diagnostic messages; they are only in the logs. The image's Docker health
check calls `/healthz` on port 8080. Failed builds never make `/healthz` fail: restarting the
container can't fix a database that is down, and the last good build should keep being served
meanwhile. Alert on `stale` in `/status` or on the webhook instead.

Pages that were served before a new build replaced the old one keep loading their scripts and
fonts: serve keeps the content-hashed files of earlier builds for seven days.

## Who can see the dashboards

serve has no login of its own, and every page holds the numbers it shows. Keep it on your private
network, or put it behind the access control you already use: a VPN such as Tailscale, or a sign-in
proxy such as Cloudflare Access or oauth2-proxy in front of it. If you'd rather not run that
yourself, use the hosted version of Hatchmark.

The [API](/docs/reference/api.md) at `/api/v1` shows what the pages show, so the same access control
covers it, and your apps call it with the viewer's sign-in. `/embed/v1` is for servers outside that
access control: it answers only requests with a token, like `/mcp`, so exempt `/embed/v1` and the
paths under it the same way, and nothing else under `/embed/` (see
[behind a sign-in proxy](#agents-over-mcp)).

## Agents over MCP

serve can also answer AI agents, such as Claude Code or Codex, on the same port at `/mcp`: the same
four read-only tools as `hatchmark mcp` (see [CLI](/docs/reference/cli.md#mcp)), over MCP's Streamable HTTP
transport. It stays off until you give it tokens. Put one named token per person or agent in
`HATCHMARK_TOKENS`, comma separated:

```sh theme={null}
HATCHMARK_TOKENS=alice=<64 hex characters>,ci=<64 hex characters>
```

The same tokens open the API at `/embed/v1`. serve still reads `HATCHMARK_MCP_TOKENS` when
`HATCHMARK_TOKENS` isn't set.

Generate each token with `openssl rand -hex 32`; serve refuses a token shorter than 32 characters
or with characters a bearer token can't carry (only letters, digits and `- . _ ~ + /`, with `=` at
the end), a name used twice, and a token shared by two names. A request needs `Authorization: Bearer <token>`;
any other gets 401. serve logs one `mcp` line per request with the token's name, never the token,
so the log shows who asked. Browser requests from any origin but localhost get 403.

Hatchmark MCP only reads and never changes data: each tool is marked read-only and non-destructive
for the client. Queries run in the container, against the sources, read-only and one at a time,
with the same result limits as `hatchmark mcp`. To connect Claude Code:

```sh theme={null}
claude mcp add --transport http hatchmark https://bi.example.com/mcp \
  --header "Authorization: Bearer $HATCHMARK_TOKEN"
```

**Rotating a token.** Tokens are read at start. Add the new one under a new name, such as
`alice2=<new>`, restart, move the client to it, then remove `alice=<old>` and restart again. Removing a
name revokes its token at the next restart; nothing else changes.

**Behind a sign-in proxy.** A sign-in proxy such as Cloudflare Access or oauth2-proxy can't sign in
an agent, so exempt `/mcp` from it and let the token protect that path. With oauth2-proxy, that's
`--skip-auth-route=^/mcp$`. In Cloudflare Access, add a Bypass policy for the `/mcp` path, and keep
`/mcp` on HTTPS. Exempt `/embed/v1` and the paths under it the same way
(`--skip-auth-route=^/embed/v1(/|$)`) when servers outside call the API; other paths under `/embed/`
are ordinary pages and stay behind the proxy.

## Docker Compose

`hatchmark init` writes this `compose.yaml` into the project, with the image pinned to the version that
wrote it and `--tz` set to the project's `timezone`, and a starting `hatchmark.env.example`. Copy
the example to `hatchmark.env`, add a line for each variable your sources name, and start it from
the project directory:

```sh theme={null}
cp hatchmark.env.example hatchmark.env
docker compose up -d
```

`init` adds `hatchmark.env` to `.gitignore`, and serve leaves it out of the copy it builds from.

```yaml theme={null}
services:
  hatchmark:
    image: ghcr.io/hatchmark-dev/hatchmark:<version>
    command: [serve, --host, 0.0.0.0, --port, "8080", --at, "06:00", --tz, America/New_York]
    restart: unless-stopped
    ports: ["8080:8080"]
    env_file: hatchmark.env
    volumes:
      - .:/project:ro
      - hatchmark-data:/data
volumes:
  hatchmark-data:
```

For agents over MCP, add the tokens to `hatchmark.env`:

```sh theme={null}
HATCHMARK_TOKENS=alice=<token>,ci=<token>
```

## Kubernetes

```yaml theme={null}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hatchmark
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels: { app: hatchmark }
  template:
    metadata:
      labels: { app: hatchmark }
    spec:
      containers:
        - name: hatchmark
          image: ghcr.io/hatchmark-dev/hatchmark:<version>
          args: [serve, --host, 0.0.0.0, --port, "8080", --every, 1h]
          ports: [{ containerPort: 8080 }]
          envFrom: [{ secretRef: { name: hatchmark-sources } }]
          livenessProbe: { httpGet: { path: /healthz, port: 8080 } }
          readinessProbe: { httpGet: { path: /readyz, port: 8080 } }
          volumeMounts:
            - { name: project, mountPath: /project, readOnly: true }
            - { name: data, mountPath: /data }
      volumes:
        - name: project
          persistentVolumeClaim: { claimName: hatchmark-project }
        - name: data
          persistentVolumeClaim: { claimName: hatchmark-data }
```

Run one replica: each instance builds on its own schedule. Any way of getting the project into
`/project` works, such as a volume a deploy job writes or a git-sync sidecar.

## Serving the files yourself

To publish with a web server you already run, or to sync to object storage behind a CDN, add
`--out <dir>`: serve also writes each good build there with its `_hatchmark/status.json`, and
updates that file after a failed build, so the footer and the banner work there too. Files there
are replaced in place, as with `hatchmark build --out`: if a write fails partway, serve logs it,
the directory can mix two builds until the next good one is written, and serve itself keeps
serving and building from its own complete copy. Plain `hatchmark build` writes static pages
with neither an update time nor a banner.

## Without Docker

`hatchmark serve` runs the same way wherever Hatchmark is installed. Its state directory defaults
to `.hatchmark/serve` in the project; `--state-dir` or `HATCHMARK_STATE_DIR` moves it outside.
`HATCHMARK_STATE_DIR` also holds the build cache and database copies of every other command.
Run it under a process manager such as systemd, and stop it with SIGTERM: it stops the build in
progress and exits.


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