env-config
Skill0 starsChanged 33 days agoMITView on GitHub
Designing a typed, validated configuration system: centralises all env var reads into one config module, validates and fails fast at startup with a clear error, distinguishes secrets from plain config, maintains a .env.example with every key documented, and prevents os.environ / process.env scattered across the codebase. Use when you want to set up config properly, validate environment variables at startup, add a config module, manage secrets vs config, structure .env files, fail fast on missing config, or stop using os.environ everywhere.
- Reads credentials
- Installs packages
4 other projects use a version of this.
Adopted by
Most recently taken up by
- AnyOrgName/php-skillstheir own version, first seen Nov 8, 2026
- mrhlaingbwardev/agentic-hacking-skillstheir own version, first seen Nov 8, 2026
- roborracle/agent-workflow-kittheir own version, first seen Aug 11, 2026
- AutumnsGrove/ClaudeSkillstheir own version, first seen Oct 26, 2025
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- mrhlaingbwardev/agentic-hacking-skills★ 347same name
- AutumnsGrove/ClaudeSkills★ 30same name
- AnyOrgName/php-skills★ 4same name
- roborracle/agent-workflow-kit★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository68 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .claude/CLAUDE.mdCLAUDE.md
- accessibilitySkill
- api-designSkill
- api-versioningSkill
- authSkill
- background-jobsSkill
- cachingSkill
- capacity-planningSkill
- changelogSkill
- chaos-engineeringSkill
- ci-cdSkill
- circuit-breakerSkill
- claude-best-practicesSkill
- code-commentsSkill
- code-hygieneSkill
- code-reviewSkill
- code-structureSkill
- commit-styleSkill
- concurrency-and-lockingSkill
- database-transactionsSkill
- data-consistencySkill
- debug-infra-startupSkill
- debug-sessionSkill
- demo-video-creatorSkill
- demo-video-script-creatorSkill
- dependency-injectionSkill
- dependency-updateSkill
- disk-cleanupSkill
- distributed-tracingSkill
- dockerSkill
- env-setupSkill
- error-handlingSkill
- event-driven-architectureSkill
- feature-flagsSkill
- file-storageSkill
- graceful-shutdownSkill
- idempotencySkill
- input-validationSkill
- jars-engineering-blogsmithSkill
- jars-workshop-builderSkill
- licensingSkill
- loggingSkill
- memory-and-allocationsSkill
- migrate-dbSkill
- monitoringSkill
- multi-tenancySkill
- notificationsSkill
- openapiSkill
- paginationSkill
- perf-profileSkill
- pr-descriptionSkill
- query-optimizationSkill
- rate-limitingSkill
- refactorSkill
- releaseSkill
- runbook-writerSkill
- searchSkill
- secrets-auditSkill
- simplifySkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
9 rules. 0 are common, 2 are distinctive, and 7 are very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
7
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Very specific: line 21
If any module outside config/ calls os.environ.get, process.env.X, or os.getenv directly — move it into the config module.
- Distinctive: line 34
Never put a secret in a config file that is committed.
- Distinctive: line 208
Every key the app reads must appear here — no undocumented env vars.
- Very specific: line 212
Commit .env.example. Never commit .env.
- Very specific: line 243
Never write a .env.production file.
- Very specific: line 273
Read env vars in exactly one file.
- Very specific: line 277
Document every key in .env.example.
- Very specific: line 279
Never log the config object at startup — it contains secrets.
- Very specific: line 281
Never use os.environ.get("KEY", "") as a fallback for a required value.
“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
env-config
Design the config system once, in one place. Every other module reads from it — never from the environment directly.
1. The core rule
os.environ / process.env / ENV[]
↓ read exactly once
config/settings.py (or config.ts / config.go)
↓ imported by
everything elseIf any module outside config/ calls os.environ.get, process.env.X, or os.getenv
directly — move it into the config module. One place to look, one place to fix.
2. Distinguish secrets from plain config
| Type | Examples | Where it lives |
| Secret | DB password, API keys, JWT secret | Secrets manager (AWS SSM, Vault, Doppler) or .env — never committed |
| Plain config | Port, log level, feature flags, timeout values | .env or environment — safe to commit as defaults in .env.example |
| Build-time constant | App name, version | Hardcoded or read from package.json / pyproject.toml |
Never put a secret in a config file that is committed. Never put plain config in a secrets manager — it creates operational overhead for no security gain.
3. Python — typed config with Pydantic Settings
# config/settings.py
"""
config/settings.py
------------------
Single source of truth for all application configuration.
Reads from environment variables (and .env file in development).
Fails fast at import time if any required variable is missing or invalid.
Depends on: pydantic-settings
Used by: every module that needs config — import settings, never os.environ
"""
from pydantic import AnyHttpUrl, Field, PostgresDsn
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
case_sensitive=False,
)
# ── Server ────────────────────────────────────────────────────────────
app_env: str = Field("development", pattern="^(development|staging|production)$")
port: int = Field(8000, ge=1, le=65535)
log_level: str = Field("INFO", pattern="^(DEBUG|INFO|WARNING|ERROR|CRITICAL)$")
# ── Database ──────────────────────────────────────────────────────────
database_url: PostgresDsn # required — no default, startup fails if missing
# ── Auth ──────────────────────────────────────────────────────────────
jwt_secret: str = Field(min_length=32) # required, enforced minimum length
jwt_expiry_seconds: int = Field(3600, ge=60)
# ── External services ─────────────────────────────────────────────────
email_provider_api_key: str # required
email_from_address: str
# ── Optional / feature flags ──────────────────────────────────────────
rate_limit_enabled: bool = True
max_requests_per_minute: int = Field(60, ge=1)
# Module-level singleton — validated once at startup, shared everywhere.
# If any required field is missing or invalid, this raises immediately with
# a clear error message naming the exact variable that failed.
settings = Settings()# Usage anywhere in the app — never os.environ
from config.settings import settings
def connect_database():
return create_engine(str(settings.database_url))
def build_jwt(user_id: int) -> str:
return jwt.encode({"sub": user_id}, settings.jwt_secret, algorithm="HS256")Install:
uv add pydantic-settings # or: pip install pydantic-settings4. Node.js / TypeScript — typed config with zod
// config/settings.ts
/**
* config/settings.ts
* ------------------
* Single source of truth for all application configuration.
* Parses and validates process.env at startup — throws on first missing or
* invalid variable so the app never starts with bad config.
*
* Depends on: zod, dotenv
* Used by: every module that needs config — import { settings }, never process.env
*/
import { z } from 'zod';
import 'dotenv/config'; // loads .env into process.env before validation
const schema = z.object({
// Server
NODE_ENV: z.enum(['development', 'staging', 'production']).default('development'),
PORT: z.coerce.number().int().min(1).max(65535).default(3000),
LOG_LEVEL: z.enum(['debug', 'info', 'warn', 'error']).default('info'),
// Database
DATABASE_URL: z.string().url(), // required — no default
// Auth
JWT_SECRET: z.string().min(32),
JWT_EXPIRY_SECONDS: z.coerce.number().int().min(60).default(3600),
// External services
EMAIL_API_KEY: z.string().min(1),
EMAIL_FROM_ADDRESS: z.string().email(),
// Feature flags
RATE_LIMIT_ENABLED: z.coerce.boolean().default(true),
MAX_REQUESTS_PER_MINUTE: z.coerce.number().int().min(1).default(60),
});
const parsed = schema.safeParse(process.env);
if (!parsed.success) {
console.error('❌ Invalid configuration — fix these before starting:\n');
parsed.error.issues.forEach((issue) => {
console.error(` ${issue.path.join('.')}: ${issue.message}`);
});
process.exit(1); // fail fast — never start with bad config
}
export const settings = parsed.data;// Usage anywhere in the app
import { settings } from '../config/settings';
const db = new Pool({ connectionString: settings.DATABASE_URL });Install:
npm install zod dotenv5. .env files — one template, never committed secrets
# .env.example ← committed to git, no real values
# Copy to .env and fill in the required values before running locally.
# ── Server ────────────────────────────────
APP_ENV=development
PORT=8000
LOG_LEVEL=INFO
# ── Database (required) ───────────────────
# Format: postgresql://user:password@host:5432/dbname
DATABASE_URL=
# ── Auth (required) ───────────────────────
# Must be at least 32 characters. Generate with: openssl rand -hex 32
JWT_SECRET=
JWT_EXPIRY_SECONDS=3600
# ── Email provider (required) ─────────────
# Get from: https://app.youremailprovider.com/api-keys
EMAIL_PROVIDER_API_KEY=
EMAIL_FROM_ADDRESS=noreply@example.com
# ── Feature flags ─────────────────────────
RATE_LIMIT_ENABLED=true
MAX_REQUESTS_PER_MINUTE=60Rules for .env.example:
- Every key the app reads must appear here — no undocumented env vars.
- Required keys have an empty value and a comment explaining where to get it.
- Optional keys have their default value filled in.
- Include a generation command for secrets (
openssl rand -hex 32). - Commit
.env.example. Never commit.env.
.gitignore:
.env
.env.local
.env.staging
.env.production6. Multi-environment strategy
.env.example ← committed template (no values)
.env ← local dev (gitignored, filled in by developer)
.env.test ← test overrides (can be committed if no secrets)For staging and production — do not use .env files on servers. Inject variables
directly through the deployment platform:
| Platform | How to inject |
| Docker / Compose | environment: block or --env-file flag |
| Kubernetes | ConfigMap (plain) + Secret (sensitive) → envFrom |
| AWS ECS | Task definition environment / SSM parameter store |
| Heroku / Render / Railway | Dashboard config vars |
| GitHub Actions | Repository secrets → env: in workflow |
Never write a .env.production file. If it exists, it will eventually be committed.
7. Fail fast — what good startup output looks like
# ✅ Good — missing config caught immediately, clear message
$ python main.py
ValidationError: 1 validation error for Settings
database_url
Field required [type=missing, input_value={'APP_ENV': 'development'...}]
Hint: set DATABASE_URL in your .env file
Format: postgresql://user:password@host:5432/dbname
# ❌ Bad — missing config causes a cryptic crash deep in the app
$ python main.py
Traceback (most recent call last):
File "repositories/user_repository.py", line 47, in connect
engine = create_engine(os.environ["DATABASE_URL"])
KeyError: 'DATABASE_URL'The difference: config validated at the module boundary catches the problem at startup.
os.environ scattered through the code crashes wherever it's first called.
Rules
- Read env vars in exactly one file. Grep for
os.environ,process.env,ENV[— any hit outside the config module is a bug to fix. - Validate type and constraints at startup — port is an integer in range, URL is a valid URL, secret meets minimum length. A bad value caught at startup is better than a crash at 2am.
- Document every key in
.env.example. If a key is missing from the template, the next developer will spend an hour finding it. - Never log the config object at startup — it contains secrets. Log only non-sensitive fields
(
app_env,port,log_level) to confirm the app started with the right profile. - Never use
os.environ.get("KEY", "")as a fallback for a required value. An empty string is not the same as "not set" — it will pass validation silently and fail mysteriously later.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

