From sdlc
Set up auto-generated .env.example with idempotent .env sync from typed settings. Works in both interactive (human-in-loop) and headless (automated workspace) contexts.
How this skill is triggered — by the user, by Claude, or both
Slash command
/sdlc:env-managementsonnetThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
**Three components. One rule: code is the source of truth.**
Three components. One rule: code is the source of truth.
Typed config class ← single source of truth
(with descriptions) field descriptions become docs
│
│ generate
▼
.env.example ← committed to git, always fresh
(documented, organized) no manual maintenance, no drift
│
│ idempotent sync
▼
.env ← gitignored, user secrets
├── existing values → never overwritten
├── new variables → added with defaults
└── unknown vars → preserved, flagged
│
│ startup validation
▼
fail fast ← crash immediately with a clear error
(required vars checked) not silently at call-time
One place defines every environment variable the application uses. Each field has a type, a default (or is explicitly required), and a description that says what the variable does and where to get the value.
No scattered os.environ.get("THING") calls. No undocumented vars.
No README section that goes stale. The code is the documentation.
Run one command (just gen-env) and .env.example is recreated from the config.
Removed fields disappear. New fields appear with their description.
Secrets are always emitted as KEY= (never leak defaults).
Required vars are marked [REQUIRED].
Fields that are discovered at runtime (not configured upfront) can be excluded
from the template entirely — they don't appear in .env.example, and users aren't
confused about whether they need to set them.
Fixed sections (security warnings, deployment notes) live in the generator code — they survive every regeneration.
At application boot, validate that all required vars are present and well-formed. Crash immediately with a clear message pointing to the missing var. Never let a missing secret surface as a cryptic error buried in a stack trace.
# What env vars does the codebase reference today?
grep -r "os\.environ\|os\.getenv\|process\.env\." --include="*.py" --include="*.ts" -h \
| grep -oP '(?<=environ\["|getenv\(")[^"]+' | sort -u
# Existing config structure?
find . -name "settings.py" -o -name "config.py" -o -name "env.ts" | head -10
# Generator already exists?
ls scripts/gen* scripts/generate* 2>/dev/null
See references/<language>/ for a full implementation.
Key decisions:
SecretStr in Python, z.string() with .min(1) in TS.envSee references/<language>/generate_env_example.py (or equivalent).
The generator must:
KEY=value lineKEY= always (never show the default)[REQUIRED]exclude={"field_name"} for dynamic/runtime-discovered values.env — preserving existing values, adding new ones,
keeping unknown vars in a clearly marked section# justfile
gen-env:
uv run python scripts/generate_env_example.py
Run it, commit .env.example. Never commit .env.
# At app entry point — not lazily, not on first use
settings = get_settings() # raises immediately if required vars are missing
git add .env.example scripts/generate_env_example.py
git commit -m "chore: add auto-generated env management"
echo ".env" >> .gitignore
| Pattern | How |
|---|---|
| Required secret | SecretStr with no default → emitted as KEY=, marked [REQUIRED] |
| Optional with default | str = "info" → emitted as KEY=info |
| Dynamic/runtime value | Use exclude={"field"} → hidden from template entirely |
| Feature-gated secret | SecretStr with empty default → marked [REQUIRED when using this feature] |
| Persistent header | Written in generator code → survives every regeneration |
## Env Management Setup
**Config class:** `<path/to/settings.py>`
**Generator:** `scripts/generate_env_example.py`
**Command:** `just gen-env`
**Sections:** <list sections and var counts>
**Excluded (dynamic):** <field names and why>
**Startup validation:** ✅ fails fast on missing required vars
**Next:** run `just gen-env`, commit `.env.example`, add `.env` to `.gitignore`
references/python/ — Full Python implementation (pydantic-settings)sdlc/agents/env-reviewer — Audits env config qualitysdlc/centralized-configuration — Broader cross-language patternsnpx claudepluginhub agentparadise/agentic-primitives --plugin sdlcAnalyzes environment variables in code, generates .env.example templates, validates configurations and types, documents variables with examples, and provides naming and security best practices.
Sets up Python configuration management with environment variables and pydantic-settings for typed validation, secrets handling, and environment-specific settings.
Scans project code for environment variables (Python os.getenv/os.environ, Node.js process.env, .env refs), generates documented .env.example templates, ensures .gitignore excludes .env files, outputs var list with acquisition instructions.