spwn.toml reference
The file is the product's contract: the CLI, the MCP server, the host hooks and a future team server all read it and behave the same way. It is shaped like Docker Compose: a key that means what a Compose key means has the Compose name, and anything a service uses is declared on that service. Every key has a default unless marked required. This page follows spec v1; keys the current build does not run yet are marked.
Migrating from the earlier shape? Files written before 2026-11-12 used [ports.*], [data.*], stage, ready, in and one [secrets] table. They no longer load: spwn check reports one error per old key, at its line, naming the replacement. The table at the end lists them all.
Files, layering and templates
spwn looks for spwn.toml at the git root of the current worktree. Files merge in order, later wins: the .toml bases named in include, then spwn.toml, then a gitignored spwn.local.toml, which plays the role of compose.override.yml. Tables merge key by key; arrays of tables (hooks, ports, post_start) append; a service set to false is disabled, as in services.worker = false. Every diagnostic names the file and line of the layer that set the value.
| Key | Type | Default | Meaning |
|---|---|---|---|
version | int | required | Spec version. This page is 1. |
name | string | repo directory name | Project name, used in env slugs and URLs, and as the Compose project name ({{ name }}-{{ env.slug }}). |
include | array of paths | [] | Files merged before this one. A .toml is a shared spwn base, for example a monorepo root spwn.base.toml; includes may nest. A Compose file is read exactly as Docker reads it and its services appear by name (below). Compose includes arrive with PRD 010. |
shell | string | "sh -c" | How run strings are executed. |
Top-level tables: services, volumes, secrets, hooks, env_file, snapshots, proxy, fork, agent, limits, integrations, remote. Everything else lives on a service.
Templates
Any string value may contain {{ expr }}. Braces were picked so templates survive inside shell strings. Unknown names fail at spwn check, never at runtime. Templates render from the consumer's point of view: inside a container, {{ ports.pg }} is the container port and {{ services.postgres.host }} the service's network alias; on the host they are the allocated host port and 127.0.0.1.
| Namespace | Example | Value |
|---|---|---|
env | {{ env.id }}, {{ env.slug }}, {{ env.parent }} | Env id (ULID), URL-safe slug, parent id if forked |
worktree | {{ worktree.path }} | Absolute worktree path |
git | {{ git.branch }}, {{ git.sha }} | Branch and commit at up time |
ports | {{ ports.api }} | Port allocated to a named port |
services | {{ services.redis.host }} | Host a service is reachable on |
volumes | {{ volumes.pgdata.url }}, {{ volumes.pgdata.path }} | Connection URL or host path of a volume |
proxy | {{ proxy.api.url }} | Preview URL for a route (browsers only) |
secrets | {{ secrets.STRIPE_KEY }} | Resolved secret, only in a service, hook or [env_file] whose secrets list names it |
state | {{ state.dir }} | Per-env scratch dir, .spwn/ in the worktree |
[services.<name>]
A service is anything long-running in the env. The driver is inferred from the keys: run is a host process, image a container, url an external shared dependency spwn does not start, and a service that exists only in an included Compose file is a Compose service. Reading one [services.postgres] table tells you its image, port, data, health check and seeding.
| Key | Type | Default | Meaning |
|---|---|---|---|
depends_on | array | [] | Services, or provision hooks by name, that must be healthy or finished first. See start order. |
healthcheck | inline table | none | Readiness checks; see below. |
environment | table | {} | Env vars; templates allowed. |
ports | array | [] | Named ports this service listens on; see below. |
volumes | array | [] | Mounts in Compose syntax: "pgdata:/var/lib/postgresql/data" for a named volume, "./fixtures:/fixtures:ro" for a bind mount. A host process lists a named volume with no target and reads {{ volumes.<name>.path }}. The service that mounts a named volume owns it; two owners is an error. |
secrets | array | [] | Names of declared secrets injected into this service's environment. |
profiles | array | [] | Start this service only when one of these profiles is selected with spwn up --profile. Empty means always. |
restart | "no" | "on-failure" | "on-failure" | Up to 3 restarts, then the env is degraded. |
post_start | array of tables | [] | Commands run inside the service after it is healthy; see below. |
pre_stop | array of tables | [] | Commands run inside the service before it stops on down. |
cpus / memory | number / string | none | Caps for container services. |
| Driver | Keys |
|---|---|
| process | run (required), working_dir, stop_signal (default SIGTERM), stop_grace_period (default "10s"). Its ports have no target; its named volumes have no container path. |
| container | image (required), command, cpus, memory. Its ports carry a target (the container port) and its volumes a container path. |
| compose | None in spwn.toml: the service is defined in the included Compose file, and [services.<name>] may add any common key. Arrives with PRD 010. |
| external | url (required). Shared, not isolated: spwn only templates its URL. No ports, volumes or hooks. |
Environment of a service
A container receives its own environment, its listed secrets, the automatic SPWN_* variables and one variable per port it declares, and nothing else, as in Compose. A host process (run) also receives the [env_file] variables, because it runs in the worktree like the shell does. Precedence, later wins: automatic variables, env file (host processes only), the service's own environment, its secrets. A container that needs another service's port writes it into environment with a template.
ports
Every env gets one contiguous block of host ports from the machine-wide range in user config (default 41000-49999). Block size defaults to the number of named ports rounded up to 10. Re-running up in the same worktree reuses the block if it is still free; forks always get a new one. A port belongs to the service that listens on it. The short form mirrors Compose's HOST:CONTAINER, with the port name standing in for the host port spwn allocates:
[services.postgres]
ports = ["pg:5432/tcp"] # name:target[/protocol]
[services.web]
ports = ["web"] # a host process: no container port; it reads $WEB_PORT
The long form is a table with the keys below, either inline (ports = [{ name = "web", env = "PORT" }]) or as [[services.<name>.ports]] headers.
| Key | Type | Default | Meaning |
|---|---|---|---|
name | string | required | Port name, unique across the file. {{ ports.<name> }}, SPWN_PORT_<NAME> and tcp = "<name>" health checks use it. |
target | int | none | Container port. Required on a container service, an error on a host process. |
protocol | "http" | "tcp" | "http" | Only http ports get a proxy route. |
env | string | <NAME>_PORT | Env var the port is exported as. |
proxy | string | false | port name | Route name for the preview URL; false hides it. |
offset | int | declaration order | Fixed position in the block, for stable debugging. |
healthcheck = { … }
All keys given must pass. Defaults: timeout = "60s", interval = "500ms". For a container service, cmd runs inside the container, so no client tools are needed on the host.
| Key | Example | Passes when |
|---|---|---|
http | "/healthz" or a full URL | A 2xx or 3xx comes back. A path uses the service's first http port. |
tcp | "pg" | The named port accepts a connection. |
cmd | "pg_isready -p {{ ports.pg }}" | The command exits 0. test is accepted as an alias, as in Compose. |
log | "listening on" | A regex matches a line on stdout or stderr. |
[[services.<name>.post_start]] and pre_stop
A command that must run inside a container is a post_start or pre_stop entry on that service. post_start entries run in file order after the health check passes; anything that depends_on the service waits for them. pre_stop entries run before the service stops on down. Host processes have none: use a provision hook that depends_on the service.
[[services.postgres.post_start]]
name = "create bench db"
command = "createdb -U postgres bench"
inputs = ["spwn.toml"]
| Key | Type | Default | Meaning |
|---|---|---|---|
command | string | required | Command run inside the container through the driver's exec. |
name | string | derived from command | Shown in logs and status. |
environment | table | {} | Extra env vars; templates render from inside the container. |
inputs | array of globs | none | Skip when unchanged since the last success. The hash travels with the service's volumes, so a fork or a clone of a golden snapshot skips it too. |
timeout | duration | "10m" | Kill and fail after this long. |
on_fail | "abort" | "warn" | "abort" | Whether failure fails the env. |
secrets | array | [] | Names of secrets injected. |
Including Compose files
include = ["docker-compose.yml"]
A Compose file in include is loaded with the same library docker compose uses, under the project name {{ name }}-{{ env.slug }}, which namespaces containers, networks and volumes per env. Its services appear by their Compose names and start with the env; [services.<name>] in spwn.toml may add any common key to one of them (a healthcheck spwn can read, profiles, post_start), and [volumes.<name>] adds fork settings to a Compose named volume. Published host ports are remapped into the env's block and named after the service. spwn writes .spwn/compose.override.yml and never edits the original file.
Compose includes are the Compose driver, PRD 010 (R4), which is in the P0 scope but not built yet. Today a .yml entry in include fails spwn check with a message saying so.
[volumes.<name>]
Every stateful thing is a named volume: declared once here and mounted by the one service that owns it, exactly as in Compose. A named volume used in a service's volumes with no [volumes.<name>] table gets every default, so volumes = ["cache:/data"] alone is valid. A volume without an explicit path lives in the env's data root under the user-config data_root; .spwn/data/<name> is a symlink to it. All volumes of an env must be on one filesystem.
[services.postgres]
volumes = ["pgdata:/var/lib/postgresql/data"]
[volumes.pgdata]
source = "snapshot:seeded"
url = "postgres://postgres:dev@127.0.0.1:{{ ports.pg }}/orders?sslmode=disable"
| Key | Type | Default | Meaning |
|---|---|---|---|
kind | "dir" | "sqlite" | "dir" | A data directory, or a single SQLite file. sqlite arrives with R18. |
path | template | data root | Host path. |
source | string | "empty" | Where a fresh env's data comes from: "empty" or "snapshot:<name>". |
fork | strategy | "auto" | How a fork copies it: snapshot, clone, copy, empty or shared. See the world fork. |
quiesce | "auto" | "checkpoint" | "pause" | "stop" | "none" | "auto" | How the owning service is made consistent before the copy. auto is checkpoint on atomic backends and pause on per-file ones. |
url | template | none | Connection string, exposed as {{ volumes.<name>.url }}. |
[snapshots.<name>]
A golden snapshot is a seeded starting point every new env forks from, built in a throwaway env, keyed by the hash of its inputs, rebuilt only when those files change. Ids look like seeded@3f9a1c. The id also covers the post_start entries of the captured volumes' owners and the provision hooks with their depends_on.
| Key | Type | Default | Meaning |
|---|---|---|---|
from | string | "empty" | Base: "empty" or another snapshot, so layers stack. |
volumes | array | all [volumes.*] | Which volumes it captures. |
services | array | the owners of those volumes and what they depend on | Services started while building. |
steps | array of strings | [] | Commands run after provision hooks, before the snapshot is taken. |
inputs | array of globs | required | Cache key, for example db/migrations/**. |
keep | int | 3 | Old versions retained. |
stale | "rebuild" | "use" | "rebuild" | What up does when inputs changed: rebuild first, or start from the old one with a warning. |
[[hooks.<point>]]
Host-side hooks live at the top level, one array of tables per point, run in file order subject to depends_on. A command that must run inside a container is a post_start or pre_stop entry on that service instead. Hooks receive SPWN_ENV_ID, SPWN_ENV_SLUG, SPWN_PARENT_ID, SPWN_PHASE, SPWN_WORKTREE, one SPWN_PORT_<NAME> per named port, one SPWN_URL_<ROUTE> per preview URL, every variable from [env_file], and SPWN_CONTEXT, the path to a JSON file with the full resolved context.
| Point | Runs | Typical use |
|---|---|---|
create | After allocation, before volumes | npm ci, go mod download, link shared caches |
provision | After the services it depends_on are healthy | Migrations, idempotent seed |
ready | After all services are ready | Warm caches, print URLs |
pre_fork | In the parent, before state is cloned | Flush queues, pause workers |
post_fork | In the child, after the clone, before services start | Rename buckets, rotate per-env ids |
pre_snapshot | Before a snapshot is taken; in a golden build, after steps and before services stop | VACUUM, truncate logs |
post_reset | After volumes are restored to the base snapshot | Re-run fast fixtures |
teardown | Before services stop on down | Export logs or test artifacts |
| Key | Type | Default | Meaning |
|---|---|---|---|
run | string | required | Command, run on the host with shell in working_dir. |
name | string | derived from run | Shown in logs and status; the name a service's depends_on refers to. |
depends_on | array | [] | Services that must be healthy, with their post_start entries run, first. Honoured on provision hooks; an error on other points, which run when every service is up or down anyway. |
working_dir | string | {{ worktree.path }} | Working directory. |
environment | table | {} | Extra env vars; templates allowed. |
inputs | array of globs | none | Skip the hook when these files hash the same as at the last success. The hash also covers the command as written. |
timeout | duration | "10m" | Kill and fail after this long. |
on_fail | "abort" | "warn" | "abort" | Whether failure fails the env. |
secrets | array | [] | Names of secrets injected into this hook's environment. |
There is no stage key. A migration declares depends_on = ["postgres"], which makes Postgres start before provisioning and holds every other service until the migration is done. A service that nothing in provisioning needs still waits for it, which is the safe default; to start a service alongside infra, list it in a provision hook's depends_on. spwn check warns about a provision hook with no depends_on in a file that has services.
[proxy]
One shared reverse proxy per machine. Each http port gets http://<route>.<env.slug>.<domain>:<listen>. Browsers resolve *.localhost to 127.0.0.1 without DNS setup; the macOS system resolver does not, so code calls http://127.0.0.1:{{ ports.<name> }}.
| Key | Type | Default | Meaning |
|---|---|---|---|
enabled | bool | true | Turn routes off entirely. |
domain | string | "localhost" | Base domain. A team server sets a wildcard such as spwn.corp.internal. |
host | template | "{{ route }}.{{ env.slug }}.{{ domain }}" | Override the host pattern. |
listen | int | 8642 | Proxy listen port. Binding 80 with spwn proxy install is planned. |
[fork]
| Key | Type | Default | Meaning |
|---|---|---|---|
worktree | "clone" | "branch" | "shared" | "clone" | clone: copy-on-write the worktree including untracked and ignored files, as a sibling directory, registered as a git worktree on branch spwn/<child-slug>. shared: same worktree, only runtime state forks. branch: a fresh git worktree add from the parent's HEAD with uncommitted changes applied as a patch; arrives with R19. |
branch | template | "spwn/{{ env.slug }}" | Child branch name. |
rerun_create | bool | false with clone, else true | Re-run create hooks in the child. A cloned worktree already has its dependencies. |
[secrets.<NAME>]
One table per secret, as in Compose. Secrets are resolved at up, held in memory, and injected only into the services, hooks and post_start entries whose secrets list names them. They never reach the agent: the MCP server reports names and whether they resolved, never values. The source is one of the keys below; an empty table means "from the invoking shell, same name". Today environment and generate secrets run; file and ref parse but are refused by up until R20.
[secrets.STRIPE_KEY]
ref = "op://dev/stripe/test-key"
[secrets.SESSION_SECRET]
generate = true
[secrets.GITHUB_TOKEN] # $GITHUB_TOKEN from the invoking shell
| Key | Type | Default | Meaning |
|---|---|---|---|
environment | string | the secret's name | Read this variable from the invoking shell. |
file | string | none | Read the key of the same name from this dotenv file. |
ref | string | none | Provider reference; the scheme picks the provider: op://, doppler://, infisical://, vault://, or cmd:<command that prints the value>. |
generate | bool | false | A fresh random value per env, such as SESSION_SECRET. |
required | bool | true | Fail up when the secret does not resolve. An optional secret that is missing is absent from every target. |
[env_file]
The environment of the worktree: host hooks, run services, the shell, tests and the agent see the same values. Containers do not, as in Compose (above). The file at .spwn/env (or path) is written at ready and always includes SPWN_ENV_ID, SPWN_ENV_SLUG, SPWN_PARENT_ID, SPWN_WORKTREE, both names of every port and one SPWN_URL_<ROUTE> per preview URL; environment entries follow and may override them. spwn never replaces a file it did not write, and with secrets listed the path must be gitignored.
| Key | Type | Default | Meaning |
|---|---|---|---|
path | string | ".spwn/env" | Where it is written. Point it at .env.local for frameworks that auto-load it. |
format | "dotenv" | "json" | "dotenv" | File format. |
environment | table | {} | Name to template, as in DATABASE_URL = "{{ volumes.pgdata.url }}". |
secrets | array | [] | Secrets written into the file. Empty by default because agents read files. |
[agent]
Which MCP tools the agent gets and what its context file says. The keys are documented with the tools on Agent tools and AGENT.md.
[limits]
| Key | Type | Default | Meaning |
|---|---|---|---|
max_envs | int | 8 | Live envs for this repo on this machine. up fails past it. |
active | int | 0 | Envs of this repo that may run at once. 0 means no cap. With n ≥ 1 the rest are parked or waiting, and env_lock / spwn lock hands the slot over. A fork made by a lock holder shares its slot. |
lock_idle | duration | "30m" | How long a lock holder may be silent (no verb, MCP call, hook run or proxy request) before its lock is released and its env parked. |
idle | duration | "4h" | With no proxy traffic, MCP calls or hook runs: stop services, keep volumes. The next up resumes. Reaper arrives with R21. |
ttl | duration | "7d" | Destroy an env idle this long. Reaper arrives with R21. |
cpus / memory | number / string | none | Per-env caps for container services. |
Profiles
Profiles follow Compose. A service with profiles = ["full"] starts only with spwn up --profile full (repeatable) or SPWN_PROFILE=full,debug; a service without profiles always starts. An unselected service is absent from status, its volumes are not materialized, and an always-on service that depends_on it fails spwn check. The selection is recorded in the env and reused by re-up, fork and resume; a live env refuses an up with a different selection. There is no profile overlay table: machine-specific changes go in spwn.local.toml, where services.<name> = false disables a service.
[integrations]
| Key | What spwn install does |
|---|---|
claude_code = true | Registers the session and worktree hooks in .claude/settings.json and spwn mcp in .mcp.json. |
herdr = true | Registers the spwn Herdr plugin: an env per pane, env health in the sidebar. |
cursor = true | Adds setup and teardown commands to Cursor's worktree config. |
[remote]
Reserved for the team server. The open-source CLI parses this table and ignores it unless a server is configured, so v1 files stay forward-compatible. Keys: server (team server URL), placement ("local", "remote" or "auto"), pool (warm, pre-seeded envs kept ready) and registry (pull golden snapshots from a shared registry instead of building locally).
Full example
A Go API and worker with Postgres and Redis. New envs fork a seeded golden Postgres, Redis starts cold, the worker starts only under a profile, the agent gets a context file and fork tools, and the repo caps itself at one running env per machine.
version = 1
name = "orders"
# ── Host-side lifecycle ──
[[hooks.create]]
name = "go deps"
run = "go mod download"
inputs = ["go.sum"] # skipped when go.sum is unchanged
[[hooks.provision]]
name = "migrate"
run = "go run ./cmd/migrate up" # DATABASE_URL comes from [env_file]
depends_on = ["postgres"] # postgres starts first; api and worker wait for this hook
inputs = ["db/migrations/**"]
[[hooks.post_fork]]
name = "rekey tenants"
run = "go run ./cmd/devtools rekey --env {{ env.slug }}"
[[hooks.teardown]]
name = "keep test artifacts"
run = "mkdir -p artifacts && cp -r .spwn/logs artifacts/{{ env.slug }}"
on_fail = "warn"
# ── Services ──
[services.postgres]
image = "postgres:17"
ports = ["pg:5432/tcp"]
environment = { POSTGRES_PASSWORD = "dev", POSTGRES_DB = "orders" }
volumes = ["pgdata:/var/lib/postgresql/data"]
healthcheck = { cmd = "pg_isready -h 127.0.0.1 -p {{ ports.pg }}" } # runs inside the container
[services.redis]
image = "redis:7"
ports = ["redis:6379/tcp"]
volumes = ["redisdata:/data"]
healthcheck = { tcp = "redis" }
[services.api]
run = "go run ./cmd/api"
depends_on = ["redis"]
secrets = ["STRIPE_KEY", "SENDGRID_KEY", "SESSION_SECRET"]
healthcheck = { http = "/healthz", timeout = "90s" }
[[services.api.ports]]
name = "api"
env = "PORT" # api listens on $PORT
[[services.api.ports]]
name = "metrics"
proxy = false # http, but no preview URL
[services.worker]
run = "go run ./cmd/worker"
depends_on = ["api"]
secrets = ["STRIPE_KEY", "SENDGRID_KEY"]
healthcheck = { log = "worker started" }
profiles = ["full"] # only with `spwn up --profile full`
# ── Volumes ──
[volumes.pgdata]
source = "snapshot:seeded" # new envs fork the golden snapshot
fork = "auto" # zfs/btrfs snapshot, else APFS/reflink clone
url = "postgres://postgres:dev@127.0.0.1:{{ ports.pg }}/orders?sslmode=disable"
[volumes.redisdata]
fork = "empty" # cache: children start cold
[snapshots.seeded]
volumes = ["pgdata"]
steps = ["go run ./cmd/seed --fixtures db/seeds/dev.yaml"]
inputs = ["db/migrations/**", "db/seeds/**", "cmd/seed/**"]
[fork]
worktree = "clone" # CoW copy incl. build cache, new branch spwn/<slug>
# ── Secrets and env file ──
[secrets.STRIPE_KEY]
ref = "op://dev/stripe/test-key" # parsed now, resolved with R20
[secrets.SENDGRID_KEY]
ref = "op://dev/sendgrid/sandbox"
[secrets.SESSION_SECRET]
generate = true
[env_file]
environment = { DATABASE_URL = "{{ volumes.pgdata.url }}", REDIS_URL = "redis://127.0.0.1:{{ ports.redis }}/0", API_URL = "http://127.0.0.1:{{ ports.api }}" }
# ── Agent, limits, integrations ──
[agent]
include_in = ["CLAUDE.md"]
notes = """
Integration tests run against this env: `make test-int` reads .spwn/env.
Before a risky migration, call env_fork with worktree = "shared" and try it on the copy.
"""
[limits]
max_envs = 6
active = 1 # one running env per machine; others park
[integrations]
claude_code = true
On spwn up, spwn downloads Go modules unless go.sum changed, forks pgdata from seeded@<hash> (built once), and starts Postgres and Redis. Postgres is infra because migrate depends on it; the migration runs (a no-op on a fresh golden snapshot), then the API starts, and spwn writes .spwn/AGENT.md. The worker starts only under --profile full.
From the earlier shape
Each row is one spwn check error at the old key's position. All of them are reported in one pass, so a file migrates in one edit.
| Old key | Now |
|---|---|
[ports.<n>] | ports = ["<n>"] (or [[services.<svc>.ports]] with name) on the service that listens on it |
services.<svc>.ports = { 5432 = "<n>" } | An array: ports = ["<n>:5432"] |
[data.<d>], services.<svc>.data | [volumes.<d>], mounted by its service with volumes = ["<d>:<mount>"] (or ["<d>"] for a host process); service and mount move to that entry |
stage | Removed. A service a provision hook depends_on starts before provisioning, every other service after it |
ready | healthcheck |
env (service or hook) | environment |
cwd | working_dir |
stop_timeout | stop_grace_period |
secrets = true | A list of secret names: secrets = ["NAME"] |
hooks.<point>[i].in = "<svc>" | Removed. A command inside a container is [[services.<svc>.post_start]], or pre_stop for teardown |
[compose], services.<svc>.compose | include = ["docker-compose.yml"] (PRD 010) |
extends | include |
[profiles.<n>] | Removed. Put profiles = ["<n>"] on each service of the profile, or use spwn.local.toml |
[secrets] provider, refs, generate, file, run, required | One table per secret: [secrets.NAME] with environment, file, ref or generate |
[env_file] vars, include_secrets | environment; secrets = ["NAME"] |
[snapshots.<n>] data | volumes |
{{ data.<d>.path }}, {{ data.<d>.url }} | {{ volumes.<d>.path }}, {{ volumes.<d>.url }} |