zorath-env
Package: zorath-env | Binary: zenv
Built by Zorath -- infrastructure for builders.
A fast, single-binary CLI that validates .env files against typed schemas, detects secrets, scans your code, generates docs, exports to 7 deployment formats, and auto-fixes issues. No runtime dependencies. Works with any stack.
14 types -- 7 export formats -- 9 language scan -- 15 secret patterns -- 6 framework presets -- 686 tests
Why zenv
.env files drift. Teams copy/paste secrets. CI fails at 3am. Docs go stale. Nobody catches the typo until production.
zenv catches config bugs at build time, not runtime. Your schema is the single source of truth -- docs, examples, and validation are all generated from it.
What makes zenv different:
- Validate with real types -- 14 validators (url, email, port, semver, uuid, ipv4, ipv6, date, hostname, and more), not just "is it a string?"
- Scan your code -- find env vars used in source code across 9 languages that aren't in your schema yet
- Export anywhere -- shell, Docker, Kubernetes, systemd, GitHub Secrets, JSON, dotenv
- Detect secrets -- 15 patterns (AWS, Stripe, GitHub, Slack, JWT, PGP keys) plus entropy analysis
- Auto-fix -- add missing vars, remove unknown keys, preview changes safely with
--dry-run - One binary, any stack -- Rust binary with no runtime deps. Node, Python, Go, Ruby, Java, PHP, Kotlin -- doesn't matter
See how zenv compares to dotenv-linter, envalid, dotenvx, and others: docs/comparison.md
Privacy
zenv runs locally. No uploads, no telemetry, no phoning home.
Install
Via cargo (recommended)
From source
Run locally
Library usage
zenv can be embedded in other Rust tools:
use ;
use ;
// Load schema
let opts = default;
let schema = load_schema_with_options?;
// Validate files directly
let errors = validate_files?;
// Generate documentation
let markdown = generate?;
let json_docs = generate?;
// Generate .env.example content
let example_content = generate; // include defaults
// Export to deployment formats
use ExportFormat;
let docker_env = export_to_string?;
let k8s_config = export_to_string?;
Add to your Cargo.toml:
[]
= "0.3"
Quick start
1. Create a schema from your existing .env:
2. Validate your .env against the schema:
3. Find env vars in your code that aren't in your schema:
4. Export to deployment formats:
5. Generate docs and examples:
Commands
zenv check
Validates .env against env.schema.json.
Exit codes (CI-friendly):
0- Valid1- Validation failed (invalid values, missing required)2- Input/file error (file not found, failed to read)3- Schema error (invalid JSON, parse failure)
When fixable issues are found, check suggests running zenv fix.
JSON Output (--format json):
Machine-readable output for CI/CD pipelines:
Secret Detection (--detect-secrets):
Scans for potential secrets that shouldn't be committed:
- AWS Access Keys and Secret Keys
- Stripe, GitHub, GitLab, Slack tokens
- Google, Heroku, SendGrid, Twilio, Mailchimp API keys
- npm tokens
- Private key headers (RSA, SSH, PGP)
- JWT tokens
- URLs with embedded passwords
- High-entropy strings
Watch Mode (--watch):
Watches for file changes and re-validates automatically:
Features:
- Delta detection: shows exactly which variable changed
- Targeted validation: only validates changed keys
- Content-hash skip: ignores saves without changes
- Local timestamps
- Terminal bell on errors
zenv docs
Generates documentation for all env vars in the schema.
zenv init
Creates env.schema.json from .env.example (best-effort inference, you refine types after).
zenv version
Shows installed version and optionally checks for updates.
zenv completions
Generates shell completions for bash, zsh, fish, and PowerShell.
# Or evaluate directly
zenv example
Generates .env.example from schema (reverse of init).
zenv diff
Compares two .env files and shows differences.
Shows:
- Variables only in first file
- Variables only in second file
- Variables with different values
- Possible typos ("Did you mean?" suggestions)
- Optional schema compliance check for both files
zenv fix
Auto-fix common .env issues with backup.
What it fixes:
- Missing optional variables (adds with schema defaults)
- Unknown keys (with
--remove-unknown)
Security: --dry-run masks sensitive values (passwords, keys, tokens) as ***MASKED***.
What it reports but doesn't fix:
- Invalid types (needs human input)
- Missing required variables (needs human input)
zenv scan
Scan source code for environment variable usage.
Supported languages: JavaScript/TypeScript, Python, Go, Rust, PHP, Ruby, Java, C#, Kotlin
zenv cache
Manage remote schema cache.
zenv export
Export .env to various formats for deployment.
zenv doctor
Run health check and diagnostics.
Checks:
- Schema file exists and is valid
- .env file exists and parses correctly
- Config file (.zenvrc) is valid JSON
- Remote schema cache is accessible
- Validation passes (if schema and env exist)
Output shows [OK], [WARN], or [ERROR] with actionable suggestions.
zenv template
Generate CI/CD configuration templates for popular platforms.
Available templates:
github(aliases:gh,github-actions) - GitHub Actions workflowgitlab(aliases:gl,gitlab-ci) - GitLab CI configurationcircleci(aliases:circle) - CircleCI configuration
Files
By default, zenv looks for:
.env(optional).env.example(optional)env.schema.json(preferred)
Env file fallback
If .env doesn't exist, zenv check will automatically try:
.env.local.env.development.env.development.local
This is useful for Next.js and other frameworks that use .env.local for secrets.
You can override paths:
Schema format (v0.3)
Schemas can be written in JSON or YAML (auto-detected by file extension).
JSON schema
env.schema.json is a JSON object where each key is an env var name.
YAML schema
Use .yaml or .yml extension for YAML schemas:
# env.schema.yaml - more readable, supports comments
DATABASE_URL:
type: url
required: true
description: Primary database connection string
NODE_ENV:
type: enum
values:
- development
- staging
- production
default: development
description: Runtime environment
SERVER_PORT:
type: port
default: 3000
description: HTTP port
Supported types
| Type | Description | Example |
|---|---|---|
string |
Any string value | "hello" |
int |
Integer number | 42 |
float |
Floating point number | 3.14 |
bool |
Boolean (true/false/1/0/yes/no) | true |
url |
Valid URL | https://example.com |
enum |
One of specified values | "development" |
uuid |
UUID format | 550e8400-e29b-41d4-a716-446655440000 |
email |
Email address | user@example.com |
ipv4 |
IPv4 address | 192.168.1.1 |
ipv6 |
IPv6 address | 2001:0db8:85a3::8a2e:0370:7334 |
semver |
Semantic version | 1.2.3-beta.1 |
port |
Port number (1-65535) | 8080 |
date |
ISO 8601 date | 2024-06-15 |
hostname |
RFC 1123 hostname | api.example.com |
Validation rules
Add constraints with the validate field:
Severity levels
Mark non-critical validations as warnings (don't cause exit code 1):
Default severity is "error". Warnings are reported but don't fail validation.
Schema inheritance
Schemas can extend other schemas:
Inheritance supports up to 10 levels of depth. Circular references are detected and will cause an error.
Remote schemas
Fetch schemas from HTTPS URLs for shared team configurations:
# Validate against remote schema
# Generate docs from remote schema
# Force fresh fetch (skip cache)
Features:
- HTTPS only (HTTP rejected for security)
- Automatic caching with 1-hour TTL
--no-cacheflag to bypass cache- Remote schemas can extend other schemas (URLs resolved relative to parent)
Remote schema security
Hash verification - Verify schema integrity with SHA-256:
# Verify schema hasn't been tampered with
# Hash prefix matching supported (first 16+ chars)
Custom CA certificates - For enterprise internal servers:
Rate limiting - Prevents excessive fetching:
- Default: 60 seconds between fetches per URL
- Bypassed by
--no-cache - Configure in
.zenvrc:"rate_limit_seconds": 120
Configuration File (.zenvrc)
Create a .zenvrc file in your project root to set default options. CLI arguments always override .zenvrc settings.
All Configuration Keys
| Key | Type | Description |
|---|---|---|
schema |
string | Path to schema file (default: env.schema.json) |
env |
string | Path to .env file (default: .env) |
allow_missing_env |
boolean | Allow validation when .env file is missing |
detect_secrets |
boolean | Enable secret detection during validation |
no_cache |
boolean | Skip cache when fetching remote schemas |
no_color |
boolean | Disable colored terminal output |
verify_hash |
string | SHA-256 hash to verify remote schema integrity |
ca_cert |
string | Path to custom CA certificate (PEM format) |
rate_limit_seconds |
number | Seconds between remote schema fetches (default: 60) |
Example: Full Configuration
Note: Unknown keys in .zenvrc will trigger a warning but won't cause failures.
.env features
Comments and Blank Lines
Full-line comments, inline comments, and blank lines are supported:
# This is a full-line comment
DATABASE_URL=postgres://localhost/db # inline comment
# Blank lines are ignored
PORT=3000
Export prefix
Shell-style export prefix is supported for compatibility:
export DATABASE_URL=postgres://localhost/db
export NODE_ENV=development
Variable interpolation
Reference other variables with ${VAR} or $VAR:
BASE_URL=https://api.example.com
API_ENDPOINT=${BASE_URL}/v2
Multiline values
Use quoted strings for multiline:
SSH_KEY="-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA...
-----END RSA PRIVATE KEY-----"
Escape sequences
Double-quoted strings support \n, \t, \r, \\, \"
Example output
Success
Validation errors
)
When unknown variables are found in your .env that are not in the schema, zenv will show a helpful tip suggesting you update your schema.
Pre-commit hook
# .git/hooks/pre-commit (make executable)
#!/usr/bin/env bash
if [; then
if ; then
||
else
||
fi
fi
GitHub Action
Validate .env files in your CI/CD pipeline:
- name: Validate .env
uses: zorl-engine/zorath-env/.github/actions/zenv-action@main
with:
schema: env.schema.json
env-file: .env.example
Inputs:
schema- Path to schema file (default:env.schema.json)env-file- Path to .env file (default:.env)allow-missing-env- Allow missing .env (default:true)version- zenv version to use (default:latest)
Outputs:
valid-trueif validation passederrors- JSON array of error messages
Connect
- Official site: zorl.cloud
- Documentation: zorl.cloud/zenv/docs
- GitHub: github.com/zorl-engine/zorath-env
- crates.io: crates.io/crates/zorath-env
- All links: edgeurl.io/p/zorl-engine
License
MIT