Skip to main content

Type-safe env generation + governance

Turn .env.example into typed contracts and production-ready checks

env-typegen generates TypeScript, Zod, t3-env, and declaration outputs, then validates real environment sources with contract checks, drift detection, and CI-friendly reports.

Single source of truth

Generate typed artifacts directly from .env.example so code, runtime validation, and documentation stay aligned.

Governance by default

Use check, diff, and doctor to enforce contracts and detect drift across local and cloud environments.

CI-ready outputs

Emit machine-readable JSON reports and integrate validation into pull requests, release workflows, and deployment gates.

From generation to drift detection

  1. 1. Generate typed outputs from .env.example.
  2. 2. Define a contract with expected types and requirements.
  3. 3. Validate environments with strict checks in CI.
  4. 4. Detect drift across targets and cloud snapshots.

$ npx env-typegen --input .env.example --output env.generated.ts

$ npx env-typegen check --env .env --contract env.contract.ts

$ npx env-typegen diff --targets .env,.env.production --contract env.contract.ts

$ npx env-typegen doctor --env .env --targets .env,.env.production --json

Built for teams that need reliable environment governance

env-typegen is designed for teams that have moved beyond ad-hoc.env handling and need repeatable, reviewable, and typed environment contracts. Instead of relying on tribal knowledge and manual checks, you can generate strongly typed artifacts, validate every environment source, and enforce rules in CI before changes reach production.

This approach reduces deployment risk, shortens onboarding for new contributors, and gives platform teams a clear governance path across local files, cloud snapshots, and release pipelines. It is especially effective for repositories where multiple services, environments, and contributors must stay aligned over time.

Frequently asked questions

How is env-typegen different from plain dotenv usage?

dotenv loads values at runtime, but it does not enforce typed contracts or drift checks. env-typegen generates typed artifacts and adds validation commands that can be enforced in CI.

Can I use env-typegen without Next.js?

Yes. The CLI and core generators work in any Node.js/TypeScript project. You can choose only the outputs you need, including TypeScript, Zod, declaration files, or t3-env configuration.

Can env-typegen validate cloud environment snapshots?

Yes. Validation commands support cloud snapshot files from Vercel, Cloudflare, and AWS so teams can detect drift before deployment.

Star