Environment setup is a configuration-boundary job. Keep the main skill focused on env ownership, precedence, validation, and safe secret handoff instead of turning it into generic machine setup or deployment automation.
Read references/env-precedence-and-visibility.md when env-file layering,
public/private split, or framework visibility rules are the main risk. Read
references/validation-and-secret-handoff.md when the problem is required
variable validation, .env.example discipline, CI/prod secret injection, or
rotation handoff.
When to use this skill
- Structure
.env,.env.local,.env.example, CI, and production config - Separate public, private, secret, and runtime-only environment values
- Add typed env validation and fail-fast startup checks
- Clean up config drift between local, staging, preview, CI, and production
- Decide what should live in env vars versus checked-in config files
When not to use this skill
- The main task is machine bootstrap, runtime versions, Docker Compose, or devcontainers: use
system-environment-setup - The main task is authentication architecture rather than env distribution: use
authentication-setup - The main task is provider-neutral deployment rollout or promotion rules: use
deployment-automation - The main task is broader secret governance, hardening, or abuse controls: use
security-best-practices
Instructions
Step 1: Map the env surface before choosing files
Capture the minimum boundary first:
- runtime surface: browser, server, worker, CLI, edge, or mixed
- environments: local, preview, CI, staging, production
- config classes: public, private, secret, runtime-only, or optional
- current failure: missing var, drift, secret leak risk, broken preview, or env-file sprawl
- framework/runtime rules: Next.js, Vite, Docker, Rails, FastAPI, or generic app
If the user is really blocked on local toolchains, containers, or machine
bootstrap, route to system-environment-setup before designing .env policy.
Step 2: Define precedence and visibility explicitly
Choose the smallest clear layering model:
- checked-in defaults:
.env.example, typed config docs, or non-secret constants - developer-local overrides:
.env.local, direnv, or shell exports - CI/preview values: pipeline or provider-managed secrets
- production values: runtime or platform secret store
For each variable, decide:
- who can read it
- where it is injected
- whether it may ship to the client
- whether it must exist at boot time
Read references/env-precedence-and-visibility.md if the public/private split
or file precedence is unclear.
Step 3: Validate required config early
Prefer one typed validation boundary at startup:
- parse env once
- coerce types once
- fail fast on missing or malformed required values
- keep derived config in code, not duplicated across many env files
Read references/validation-and-secret-handoff.md when deciding how to pair
.env.example, schema validation, CI checks, and production secret handoff.
Step 4: Keep the boundary clean
- Route machine setup, Docker Compose, devcontainers, and runtime installs to
system-environment-setup - Route auth/session architecture to
authentication-setupwhen env vars are not the real decision - Route deployment promotion and release rollout to
deployment-automation - Route secret hardening or broad app security review to
security-best-practices
Do not turn this skill into a generic infrastructure, auth, or deployment lane.
Step 5: End with the smallest safe next check
Before finishing, state:
- the env ownership model
- precedence order and file/platform split
- required validation gate
- which values are public vs private vs secret
- the next smallest verification step, such as startup validation, CI check, or preview smoke test
Output format
Expected response shape:
Env surface: runtimes, environments, and current painOwnership model: what lives in repo, local overrides, CI, and productionVisibility rules: public vs private vs secret valuesValidation gate: how required config is checked and where it fails fastDrift risks: what commonly diverges across local, CI, and productionNext check: the smallest verification or handoff stepRoute-outs: sibling skills that should own any broader follow-up
Examples
Example 1: Env-file sprawl cleanup
Input:
We have `.env`, `.env.local`, `.env.staging`, provider secrets, and random
shell exports. Help me clean up the config model without breaking local or CI.
Expected shape:
- keeps the request on
environment-setup - defines precedence and ownership before suggesting files
- ends with validation and drift checks
Example 2: Public vs private split
Input:
Which values should stay server-only, which can go in `NEXT_PUBLIC_*`, and how
should I document them for the team?
Expected shape:
- keeps the request on
environment-setup - distinguishes visibility rules clearly
- names the documentation and validation boundary
Example 3: Route machine setup outward
Input:
My repo fails because Docker, Node, and Postgres versions are inconsistent
across laptops. Fix the developer setup.
Expected shape:
- recognizes the primary problem as machine or runtime setup
- routes to
system-environment-setup - keeps env-file policy as secondary
Example 4: Route rollout outward
Input:
I need a staging-to-production release process with preview deploys, health
checks, and rollback steps.
Expected shape:
- recognizes rollout automation as the main task
- routes to
deployment-automation - does not keep
environment-setupas the primary owner
Best practices
- Document every required variable in one place.
- Keep secrets out of checked-in env files.
- Validate env once at startup rather than reading raw
process.enveverywhere. - Minimize the number of env layers and make precedence explicit.
- Keep public and server-only variables clearly separated.
- Add references and evals before any
skill-autoresearchloop on this skill.
References
- Local:
references/env-precedence-and-visibility.md - Local:
references/validation-and-secret-handoff.md - Twelve-Factor config: https://12factor.net/config