Repository navigation
Inside Environments
Which database a feature works against is the machine's answer, not the
script's. It used to be the literal dev, written into force_dev three
times over, and that was right while everybody shared one database. It stopped
being right when a product could offer a Supabase stack running locally: a
developer applying migrations wants a database nobody else is reading, and a
developer working on the interface has no reason to install Docker for one.
So environment.sh asks, in order: $SCLAUDE_ENV, then the answer this machine
gave before (~/.claude/sclaude/environment), and only then the human — once,
with the project's own environment names as the choices. There is deliberately
no default: a guess would put somebody on a shared database believing they
were isolated, or on an empty local one believing they were looking at real
data, and both mistakes are quiet ones. A project that declares no environments
simply does not get asked, and keeps whatever its worktree had.
An environment is a .env file. The product names each one in
.sclaude/config.json — "dev": {"env": ".env.dev"}, "prod": {"env": ".env.prod", "protected": true, "siteUrl": "https://…"} — and that is all
sclaude needs to know (sclaude/lib/core/envs.py). A tree is on the environment
whose file its .env.local points at. sclaude switches it itself: .env.local
to the file, and on Supabase the CLI linked to the project that file's URL
names, or unlinked for a local stack, since supabase db push obeys the link
and not .env.local. A build made on the old file is removed with it,
because NEXT_PUBLIC_* is inlined. The credentials stay in those files: a
rollback reads production's database URL from production's file, and
whatever sclaude needs and no file holds it asks for at the terminal, every
time, saying that naming the file once spares the question.
Not every environment is a choice. A protected one is production. A
deployed one names deployments rather than a machine — a preview, perfectly
safe to write to, but not somewhere a local dev server and a local browser
suite belong; offered as a choice, it sent the cycle into a regression whose
e2e stage refuses to start. Nor is one whose siteUrl is not a loopback
address.
Two things survive from the old behaviour unchanged. A feature is still never
left pointed at production — that is why the function acts rather than reporting,
and protected environments are excluded from the choices, refused from
$SCLAUDE_ENV, and refused from a saved answer somebody edited by hand. And an
environment we cannot identify is still treated as protected: the hook that
governs supabase db push allows it only on an environment the project does
not protect, and only when .env.local and the CLI's link agree — silence is
not permission. A push that names its own target is judged by it instead:
a database URL (--db-url, or CLI 3's --remote <url>, with or without =)
passes only when it is local — written out, since a variable or a
substitution cannot be read: that refusal says to write a local address out
and carry on rather than stop, and that a remote one is refused either way,
so a variable holding one is not to be expanded — a project named by ref or branch (--remote <ref>) is refused, and
--local passes; migration up, migration down and db reset that name a target are held
to the same rules, and without one they work on the local stack. A push that names nothing is read as CLI 2 reads it, aimed
at the link: CLI 3 would aim it at the local stack, but the command does not
say which CLI runs. A session may not point .env.local at production's file
either; a product's own switch script is banned in its policy.
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