exenv
Interactive .env generator from example template files with comment guidance, type inference, shell inheritance, and merge safety.
Installation
Via Go
go install github.com/kryft-dev/exenv@latest
Pre-built Binaries
Pre-compiled standalone binaries and archives are available on GitHub Releases:
- Linux (x86_64, ARM64)
- macOS (Apple Silicon, Intel)
- Windows (x86_64, ARM64)
Agent Skill
Install the official skill for AI coding agents:
npx skills@latest add kryft-dev/exenv
Usage
Interactive Mode
Run in any directory containing a template file (.env.example, .env.sample, .env.template):
exenv
If multiple template candidates exist in subdirectories, an interactive menu will prompt you to choose.
Explicit Source and Output Files
# Positional syntax
exenv .env.example .env.local
# Flag syntax
exenv --source config/.env.template --out config/.env
Non-Interactive & CI/CD
# Accept all defaults; fails if required variables lack defaults
exenv --defaults
# Dry run (renders output to stdout without modifying disk)
exenv --defaults --dry-run
CLI Flags
| Flag | Short | Description | Default |
|---|---|---|---|
--source |
-s |
Path to source template file | Auto-discovered |
--out |
-o |
Path to target output file | .env |
--defaults |
-d |
Non-interactive mode using default values | false |
--force |
-f |
Overwrite existing .env without pre-filling |
false |
--yes |
-y |
Skip review summary confirmation prompt | false |
--dry-run |
Output generated file to stdout | false |
|
--no-env |
Do not inherit shell environment variables | false |
|
--no-ignore |
Do not respect .gitignore during discovery |
false |
|
--no-backup |
Do not create .env.bak on overwrite |
false |
|
--show-secrets |
Display secret values in plain text | false |
|
--max-depth |
Maximum directory search depth | 5 |
|
--version |
-v |
Display version information |
Template Annotations
Annotate comments directly above variables in .env.example to customize field behaviors:
# Application environment
# @options dev,staging,prod
# @required
APP_ENV=dev
# Stripe secret key
# @secret
STRIPE_API_KEY=
# Public encryption key
# @public
PUBLIC_KEY=""
# Enable experimental background workers
# @bool
ENABLE_WORKERS=false
@secret: Forces password input masking in prompts and review summary cards.@public: Overrides secret heuristics for sensitive key names.@required: Enforces non-empty input before allowing progression.@options val1,val2,val3: Renders an interactive select dropdown.@boolor@type bool: Renders a boolean selector (true/false).
Key Features
Breadth-First Template Discovery
Searches shallowest directories first, respecting .gitignore rules and automatically skipping standard dependency folders (node_modules, vendor, .venv, dist, build).
Merge Safety & Orphan Preservation
If a target .env exists, current values are pre-filled so existing secrets are not lost. Local custom variables absent from the template are automatically preserved under a dedicated comment section at the bottom.
Shell Environment Inheritance
Matching environment variables already exported in your terminal session are auto-detected and pre-filled with an indicator.
Atomic File Writing
New .env files are created with restricted 0600 permissions (owner read/write only). Overwriting an existing file automatically creates a .env.bak backup copy.
License
Released under the MIT License. Maintained by Kryft.