Getting started
spwn turns any git worktree into its own running environment: allocated ports, services, forked volumes and a browser URL, all described by one committed spwn.toml. This page takes a repo from nothing to a forkable world.
spwn is pre-release. The validation release (the P0 scope) is being built in the open; parts of the spec that are not implemented yet are marked as such throughout these docs, and Status and roadmap lists them in one place.
What you need on the machine
spwn follows one rule for itself and for you: nothing on the host that doesn't need to be. Databases, caches and their client tools come from container images.
- macOS (APFS) or Linux (ext4, XFS, btrfs or ZFS). Windows only through WSL.
- git. Worktrees are git's; spwn only drives them.
- A container runtime such as Docker Desktop, OrbStack or Podman, if any service uses
image. spwn talks to it through thedockerCLI. - Your app's own toolchain for services you run as host processes (
go run,npm run dev). - zfs or btrfs tools, only where those filesystems hold the data. spwn never uses
sudo;spwn doctorprints the one-time delegation setup for you to run.
Install
spwn is one static Go binary with no runtime dependencies.
go install github.com/spwn-gg/envs/cmd/spwn@latest
spwn doctor
spwn doctor checks the container runtime, the filesystem under your data root (and which fork strategy it will get), *.localhost resolution and the port range, and repairs spwn's own state when asked with --fix.
A first spwn.toml
spwn looks for spwn.toml at the git root of the current worktree. It is shaped like Docker Compose: services, ports, volumes, environment, healthcheck and depends_on mean what they mean there, and everything a service uses is declared on the service. If you already have a Compose file, keep it. A web app with one dev server needs one service and one hook: spwn allocates a free port, exports it as PORT, installs dependencies once, starts the server and waits for it to answer.
version = 1
[[hooks.create]]
run = "npm ci"
inputs = ["package-lock.json"]
[services.web]
run = "npm run dev"
ports = [{ name = "web", env = "PORT" }]
healthcheck = { http = "/" }
Validate it, then bring the env up:
$ spwn check
$ spwn up
$ spwn status
spwn check reports every mistake with file and line, including template names that don't resolve and, for a file written in the earlier [ports.*]/[data.*] shape, what each old key became. spwn up prints the env id and http://web.<slug>.localhost:8642. Browsers resolve *.localhost to 127.0.0.1 on their own; code that calls the service uses 127.0.0.1:$PORT instead, because the system resolver does not.
Add a database and seed it once
A stateful service mounts a named volume, as in Compose: a directory spwn materializes, mounts into the container and forks copy-on-write with the rest of the env. Everything the service uses sits on the service; the [volumes.*] table only says where a fresh env's data comes from. A golden snapshot seeds it once; every later env clones the snapshot instead of seeding again.
[services.postgres]
image = "postgres:17"
ports = ["pg:5432/tcp"] # name:container-port/protocol
environment = { POSTGRES_HOST_AUTH_METHOD = "trust" }
volumes = ["pgdata:/var/lib/postgresql/data"]
healthcheck = { cmd = "pg_isready -h 127.0.0.1 -p {{ ports.pg }}" }
[volumes.pgdata]
source = "snapshot:seeded"
url = "postgres://postgres@127.0.0.1:{{ ports.pg }}/app?sslmode=disable"
[[hooks.provision]]
name = "migrate"
run = "npm run migrate" # DATABASE_URL comes from [env_file]
depends_on = ["postgres"] # postgres starts first; web waits for this hook
inputs = ["db/migrations/**"]
[snapshots.seeded]
volumes = ["pgdata"]
steps = ["npm run seed"]
inputs = ["db/migrations/**", "db/seeds/**"]
[env_file]
environment = { DATABASE_URL = "{{ volumes.pgdata.url }}" }
There is no stage key: because migrate depends on postgres, Postgres starts before provisioning and web waits until the migration is done. Templates render from the consumer's point of view. Inside the Postgres container {{ ports.pg }} is the container port, so the health check runs inside the container with no Postgres tools on the host. The first spwn up builds seeded@<hash> in a throwaway env; it is rebuilt only when a file matching inputs changes.
[env_file] environment is the environment of the worktree: host processes and hooks receive it, together with SPWN_ENV_ID, SPWN_ENV_SLUG, one SPWN_PORT_<NAME> per named port and one SPWN_URL_<ROUTE> per preview URL. Containers get only what their own service declares, as in Compose. The same values are written to .spwn/env at ready for your shell and test runner (source .spwn/env, or point [env_file] path at .env.local); secrets reach it only when [env_file] secrets lists them, and never at a path git would commit.
Wire up Claude Code
$ spwn install --host claude-code --dry-run # shows the diff
$ spwn install --host claude-code
This registers hooks in the project's .claude/settings.json and the spwn MCP server in .mcp.json, touching nothing else in either file. From then on each Claude Code worktree gets its own env on creation, a resumed session brings an idle env back, and the agent reads .spwn/AGENT.md, which tells it where its services are and when to fork or reset. Details are on the integrations page.
Fork, reset, tear down
$ spwn fork --name try-migration # a child env with its own ports, URL and cloned volumes
$ spwn fork --worktree shared # same worktree, only runtime state forks
$ spwn reset # volumes back to the snapshot the env started from
$ spwn reset --to seeded@3f9a1c # or to a specific one
$ spwn down # stop services, free the port block, remove volumes and children
A fork copies every volume and, by default, the worktree (including untracked and ignored files, so build caches come along) as one operation while the parent keeps running. The agent can do the same over MCP with env_fork and env_reset. How it works explains what happens underneath.
Where to go next
- How it works: ports, start order, volumes, golden snapshots, the fork algorithm and the env lock.
- spwn.toml reference: every table and key, with defaults.
- Agent tools and AGENT.md: what the agent can do to its own env.