Repository navigation
Inside A dev server and a database per feature
The orchestrator runs the dev server, not the session. A next dev started
from a claude session stays in its process group and will not let it exit — and
exiting is what a step ends with. setsid takes the server into a session of its
own, where it outlives both claude and sclaude itself; it is shut down by
sclaude done or by hand through sclaude dev --stop <feature>. Chrome, by comparison,
detaches itself — chrome-debug leaves it with PPID=1, and it holds no
session.
Every feature has a dev server of its own, and opens at
http://<feature>.localhost:3000. The first start claims a port from
3100–3199 and records it in .sclaude/local/feature/state.json, so a feature keeps its port
and its address between runs; a lock keeps two features started together from
claiming the same one. Nobody needs to know the ports: sclaude-proxy holds
:3000 and hands each request to the server its host names (see
bin/sclaude-proxy). The host rather than only the port is
what keeps two features apart in one browser — cookies ignore the port, so on
bare ports a sign-in on one feature would sign the other one out.
The server is started with PORT (where to listen) and SCLAUDE_DEV_URL (where
it is reached from). The second is for the app: it cannot see the proxy's name
from where it stands, and an app that builds its sign-in redirects and email
links from its own address would otherwise send them to localhost:3000, the
list of features. What the project does with it is its own business — a Next.js
app might turn it into NEXT_PUBLIC_SITE_URL in its dev script.
It listens on this machine alone. The proxy answers loopback and the
tailnet, and reaches a feature on 127.0.0.1:<port>; a feature's own port
open on every interface would let anybody on the same network past that
filter. next dev and next start take every interface when nothing names
an address, and which command a product runs is its own business, so sclaude
sets the address under it: dev_net_env (worktree.sh) puts
--require=sclaude/lib/tree/dev_loopback.cjs into NODE_OPTIONS for the dev
server and for the build the regression serves, and that file moves every
listen on a wildcard address — none, 0.0.0.0, :: — to 127.0.0.1. An
address the product names on purpose, a unix socket or a handle is left
alone, and a NODE_OPTIONS already in the environment is kept after it. A
step's session is told to start the server with sclaude dev, which goes the
same way. The regression's parts and a session's own test runs are left
without it: a test listening on :: and connecting over ::1, or a
container calling back through host.docker.internal on a Linux Docker,
would go red for no fault of the feature, and a suite's webServer reuses
the server already running. A product script that sets NODE_OPTIONS itself
(NODE_OPTIONS=… next dev) replaces sclaude's, and another runtime never
reads it: dev_exposed reads the port's listeners when ensure_dev sees
the server listening, at its start or on a later call that finds it up, and
says so once per process, in the terminal and the feature's topic. By
SCLAUDE_DEV_LOOPBACK in the environment of the process or its parents it
tells how it got there: one started without the shim — before it existed,
or by hand — is to be started again through sclaude dev <feature>; for one
that lost it on the way, the product's command names the address, gives the
server an environment of its own or drops $NODE_OPTIONS, or runs no Node. Next.js still prints a Network: line with the
machine's address; nothing answers there.
The local regression hands the suite the same address in E2E_LOCAL_URL,
with PORT and SCLAUDE_DEV_URL in case the suite has to start the server
itself, and the feature's name in SCLAUDE_FEATURE. One thing to know when a
project's suite talks to that address from Node rather than from the browser:
Chrome resolves *.localhost by itself, but Node asks the system resolver,
and a stock WSL Ubuntu answers ENOTFOUND. The suite then has to answer those
names itself, in a test fixture.
Every step starts by printing the address under the step's banner, once
a step in a run of sclaude (STEP_ANNOUNCED, read by run_step): the
review's next round in the same conversation (REVIEW_KEPT_SAID), a fresh
session for its next findings and its polish round leave the banner and the
lines under it out. A step gone back to (step_rewind_to, a QA hand-back
among them), the next part (parts_built) and the next review block are
announced again. The
database's line and Chrome's "already up" are said once a process, on any
round, unless something was started. Where
the proxy's page can list the feature's users — through the proxy, with
devLogin in the project's config and a local database of the feature's own
(dev_users_address) — it is that page, each user a sign-in without a
password (Sign in as any user: http://<feature>.localhost:3000/__sclaude/users);
otherwise Open it at the feature's address (http://<feature>.localhost:3000
through the proxy, http://localhost:<port> without it). The feature's menu
shows it beside the dev server's state.
A port found held by a process from another directory is not ours to take back: the feature moves to another port and says so, rather than offering to kill somebody else's server.
Every feature on the local database has a Supabase of its own. Two features
on one local stack see each other's schema — a migration written in one lands
under the other — and a db reset in one wipes the other's data. So when a
feature's environment is the project's local one, ensure_dev first starts a
stack for it alone: its own project_id (Docker names containers and volumes
after it — the project's id and the feature's label, kept to the 40
characters the Supabase CLI keeps, a longer one cut short and ending in a hash,
and recorded in the state as db.project_id), its own block of ten ports from 55000, only the containers the
project needs. On WSL a block is also clear of the ranges Windows keeps
(netsh int ipv4 show excludedportrange protocol=tcp): Docker Desktop cannot
publish a port there, though nothing listens on it, and WinNAT can reserve most
of 55000-55990 at boot. A recorded block that Windows has come to keep since is
given up for another — a stack still running on the old block is stopped, its
data kept, and started on the new one, or the feature would be pointed at ports
nobody listens on; one the stop cannot move falls back to the shared database
with a warning — and a start Docker refuses for its ports says so, rather
than failing the same way at every step. For a typical web app that is a handful of containers and a
few hundred MB, up in under a minute the first time. It is filled once: with a copy of the main local
database's data when the project sets copyFromMain and the main stack is up —
the same rows under the same ids, so whatever the project keeps outside the
database under those ids is already there — and with the project's seed
otherwise (a reset of it goes through sclaude dev --rebuild-db, which fills it
again the same way).
The copy goes into main's schema, not the feature's. A migration that inserts
reference rows with generated ids gives them different ids in every stack, so
main's rows that point at them, loaded over the feature's own, pointed at
nothing — and a later migration that put a foreign key back failed on them.
So the feature's stack is set back to the main database's last migration
(db reset --version), public's tables are emptied, main's rows go in, and
the feature's own migrations then apply over them, as they will over
production's. Where the two cannot be made one schema — the main database has
a migration the tree lacks — the copy goes over the feature's schema as
before (db_copy_main).
The main local database is the source, so it is kept on main's migrations:
db_main_up applies the ones on origin/main that it lacks, from a workdir of
main's own (whatever the main checkout has checked out), at the end of every
cycle and before every copy. It is quiet when nothing is pending, leaves a
stopped stack stopped, and only warns when the migrations do not apply — the
main stack is the developer's, and sclaude does not rebuild it. Its log is
.sclaude/local/db-main.log in the main checkout.
The stack runs from .sclaude/local/feature/supabase/: a rewritten copy of the tree's
supabase/config.toml — the tracked one is never touched, or the ports would
ride into a commit — and symlinks for everything else, so the migrations the
feature writes are the ones its stack applies. Pending migrations, the
feature's and main's after a sync, are applied on every start. One applied
already and changed since — edited in a review's fix, or gone, folded into
another — is one migration up never runs again, so before applying them
sclaude compares the SQL the stack keeps for each applied migration
(supabase_migrations.schema_migrations, spacing and semicolons aside) with
its file (db_stale). A stack that differs is reset and filled again, as by
sclaude dev --rebuild-db, and the line says which migrations it was for.
.sclaude/local/feature/db.env points the feature at it, and every process sclaude starts
there sources it — the dev server, the local regression, the claude session
of a step, and the friction review and the retrospective, which may fix the
product on its branch and check the fix.
It carries SUPABASE_WORKDIR, so the database CLI typed in the session
reaches this feature's database and no other. A plain db reset of it is
refused (supabase-own-reset): it would empty the database for good, since
the fill runs once, and the refusal sends the session to sclaude dev --rebuild-db, the same reset followed by the same fill. A hook refuses
--workdir pointing anywhere else — in a call, or a heredoc a shell may run,
not in one that cat or tee only writes to a file. The project decides the rest in
.sclaude/config.json under database.local (see sclaude/config.example.json), and
its own dotenv loading must let an exported value win over its environment
link (envLink, .env.local unless named).
Nothing runs that nobody uses. sclaude-proxy starts a stopped feature on
the first request for it — a page says it is starting and reloads until the
feature answers, under a minute with its database — and stops one nobody has
opened for half an hour (SCLAUDE_DEV_IDLE), its database with it, data
kept. It never stops a feature while anything is working in its tree: a claude
session, a regression, a shell. The start goes through sclaude dev --no-browser and the stop through sclaude dev --stop, so the proxy decides
only when; the PATH they need — nvm's node among it, which systemd does not
have — is the one sclaude last ran with, left in the registry; with a plain
dev command (one program, no shell syntax), only a PATH that command is found
on is left there, so a start from a process without it keeps the last good
one. A start that
fails shows its log and waits for "Try again" rather than looping. The local
regression brings the feature up itself before its parts run.
The stack is removed with its data when the feature is merged or abandoned,
after the project's teardown — for example, deleting from object storage
what the feature's people uploaded and the main database does not reference; it is told
when the stack was filled (SCLAUDE_DB_FILLED), and asks the main database
itself which of the stack's rows are its own — sclaude knows nothing of what a
row is. What a teardown cannot tell is the feature's own — anything older than
the stack's last fill — is left for the project's sweep, which sclaude runs
in the main checkout when it starts with no feature in progress, and when
sclaude done has just removed the last one: the main
database is then the only one left, so what it does not use is nobody's. A
removal that could not take a feature's stack away (Docker down, a stop that
failed) writes its project_id down in .sclaude/local/stacks-left, and the
sweep holds off while a line is there, naming it, until the person removes
the stack and the line. It runs five minutes at most. Its last line is shown,
everything goes to .sclaude/local/sweep.log, and one that refuses leaves
things as they were.
The main repository keeps its own stack, and a feature on the shared cloud
project has none. With Docker down sclaude starts it — Docker Desktop from WSL,
or docker.service where sudo needs no password — and waits up to
SCLAUDE_DOCKER_WAIT seconds (120); SCLAUDE_DOCKER_DESKTOP names the
launcher when it is somewhere unusual. A start that fails is not retried for
ten minutes. A stack whose start exits with an error — as it does when started
again while its containers are still coming up — is given up to
SCLAUDE_DB_WAIT seconds (120) to answer status before it counts as down:
the shared database it would fall back to lacks the feature's own migrations.
Only when Docker or the stack stays down does the feature fall back to the
shared local database, and it says so. SCLAUDE_DOCKER_START=off starts
nothing.
Generated from docs/sclaude.md; edit it there, then rebuild with wiki/build.py.
SClaude is open source under MIT · Repository · Landing page · Contact
Why
How it works
- The cycle
- Big features in parts
- Limits in code
- Fewer tokens
- Feedback loops
- Metrics and the replay
- For a team
- Working from the phone
- Stack and costs
- Privacy
Guide
- Getting started
- Setting up
- Using sclaude
- The config, key by key
- When something goes wrong
- Glossary
- Gates and rules
- Team setup
- Privacy in full
- The tools
- Decks and the map
- Contributing
Inside
Links