π‘οΈ EnvGuard
Smart .env file manager β scan, validate, diff, and sync environment variables
Ever deployed to production only to crash because DATABASE_URL was missing?
EnvGuard scans your code, validates your .env files, detects leaked secrets, and keeps environments in sync β all from one CLI.
β¨ Features
- π Code Scanner β Finds every env var your code actually uses (JS/TS, Python, Go, Rust, Docker)
- β
Validator β Validates
.env against a schema with type checking (int, bool, url, port, email, enum)
- π Cross-Validation β Detects vars used in code but missing from
.env, and vars in .env but unused
- π Diff β Compare
.env files across environments with color-coded output
- π Secret Detection β Finds AWS keys, private keys, JWTs, and tokens in your codebase
- π Encrypted Sync β Share
.env files via git safely with AES-256-GCM encryption
- πͺ Pre-commit Hook β Validate before every commit automatically
- π Schema Generator β Auto-generate
.env.schema from existing .env with type inference
- π CI-Ready β Clean exit codes (0=ok, 1=warnings, 2=errors) for pipeline integration
π¦ Installation
Go Install
go install github.com/AbdullahTarakji/envguard/cmd/envguard@latest
From Source
git clone https://github.com/AbdullahTarakji/envguard.git
cd envguard
make build
sudo mv envguard /usr/local/bin/
Binary Releases
Download pre-built binaries from Releases.
π¬ Demo
π Quick Start
# Scan your code for env var usage
envguard scan
# Validate your .env file
envguard validate
# Run all checks (validate + security scan)
envguard check
# Compare dev vs prod env files
envguard diff .env .env.production
π Usage
envguard scan β Find Environment Variables in Code
Scans your source code to discover which environment variables are actually used:
$ envguard scan
Found 8 unique environment variables in 12 references:
DATABASE_URL src/db.ts:5 (js)
PORT src/index.ts:3 (js)
API_KEY src/api.ts:10 (js)
DEBUG src/config.py:8 (python)
REDIS_URL src/cache.go:15 (go)
...
Supported languages:
| Language |
Patterns Detected |
| JavaScript/TypeScript |
process.env.VAR, process.env['VAR'], import.meta.env.VITE_* |
| Python |
os.environ['VAR'], os.getenv('VAR'), os.environ.get('VAR') |
| Go |
os.Getenv("VAR"), os.LookupEnv("VAR") |
| Rust |
std::env::var("VAR"), env::var("VAR"), env!("VAR") |
| Docker |
ENV VAR=val, ARG VAR, ${VAR} in compose |
# Filter by language
envguard scan --lang js
# JSON output
envguard scan --json
# Scan specific directory
envguard scan ./src
envguard validate β Validate Your .env File
Against Code (default)
Checks that every env var your code uses is defined in .env, and warns about unused vars:
$ envguard validate
β MISSING_VAR: variable used in code but missing from .env
β OLD_CONFIG: variable defined in .env but not used in code
β 12 variables validated successfully
Against a Schema
Create a .env.schema to enforce types and requirements:
# type: string, required
DATABASE_URL=
# type: port, required
PORT=
# type: bool, optional, default: false
DEBUG=
# type: enum(development,staging,production), required
NODE_ENV=
# type: url, required
API_ENDPOINT=
# type: email, optional
ADMIN_EMAIL=
$ envguard validate --schema .env.schema
β PORT: expected type "port", got "abc" (not a valid port number)
β NODE_ENV: expected one of [development, staging, production], got "test"
β 8/10 variables passed validation
Supported types: string, int, bool, url, email, port, enum(val1,val2,...)
# Strict mode (warnings become errors)
envguard validate --strict
# JSON output for CI
envguard validate --json
# Explicit paths
envguard validate --env .env.staging --schema .env.schema
envguard diff β Compare Environment Files
$ envguard diff .env .env.production
~ DATABASE_URL: localhost:5432/dev β prod-db:5432/app (line 1 β 1)
~ PORT: 3000 β 8080 (line 2 β 2)
- DEBUG=true (line 3)
+ SENTRY_DSN=https://... (line 8)
~ NODE_ENV: development β production (line 5 β 4)
# Mask sensitive values (for sharing/logging)
envguard diff .env .env.prod --mask
~ DATABASE_URL: ***** β ***** (line 1 β 1)
~ API_KEY: ***** β ***** (line 4 β 3)
# JSON output
envguard diff .env .env.prod --json
envguard init β Generate Schema from .env
Auto-generates a .env.schema with inferred types:
$ envguard init
Generated .env.schema with 10 entries
$ cat .env.schema
# type: string, required
DATABASE_URL=
# type: port, required
PORT=
# type: bool, required
DEBUG=
# type: url, required
API_ENDPOINT=
Type inference:
- Numbers β
int (or port if 1-65535)
true/false/yes/no β bool
http:///https:// β url
- Contains
@ and . β email
- Everything else β
string
envguard check β Run All Checks
Combined validation + security scan, perfect for CI:
$ envguard check
β .env is not in .gitignore
β MISSING_VAR: used in code but not in .env
β Found potential AWS key pattern in src/config.js:15
β Encryption check passed
$ echo $?
2 # exit code 2 = errors found
Exit codes: 0 = clean, 1 = warnings only, 2 = errors
envguard encrypt / decrypt β Secure .env Sharing
Share .env files through git safely with AES-256-GCM encryption:
# Encrypt .env β .env.enc (from project directory)
envguard encrypt --password "team-secret"
# Or specify the file path directly
envguard encrypt .env.staging --password "team-secret"
# Decrypt .env.enc β .env
envguard decrypt --password "team-secret"
# Decrypt a specific file
envguard decrypt .env.staging.enc --password "team-secret"
# Password from environment variable
export ENVGUARD_PASSWORD="team-secret"
envguard encrypt
envguard decrypt
Add .env.enc to git, add .env to .gitignore. Team members decrypt with the shared password.
envguard hook install β Pre-commit Hook
$ envguard hook install
Installed pre-commit hook at .git/hooks/pre-commit
This runs envguard check before every commit. Failed checks block the commit.
βοΈ Configuration
Create .envguard.yaml in your project root:
# Paths
env_file: .env
schema_file: .env.schema
# Scanning
scan_paths:
- src/
- lib/
- cmd/
ignore_patterns:
- node_modules/
- vendor/
- dist/
- build/
- .git/
# Custom secret patterns
secret_patterns:
- name: internal_token
pattern: "MYAPP_[A-Z]+_TOKEN"
# Variables to ignore in validation
ignore_vars:
- PATH
- HOME
- USER
- SHELL
ποΈ Tech Stack
- Language: Go β Fast, single binary, cross-platform
- CLI Framework: Cobra β Industry-standard Go CLI
- Encryption: AES-256-GCM with scrypt key derivation
- Color Output: fatih/color β Cross-platform terminal colors
π Project Structure
envguard/
βββ cmd/envguard/
β βββ main.go # Entry point, Cobra commands
βββ internal/
β βββ envfile/
β β βββ parser.go # .env file parser
β β βββ parser_test.go
β βββ scanner/
β β βββ scanner.go # Directory walker + interface
β β βββ javascript.go # JS/TS patterns
β β βββ python.go # Python patterns
β β βββ golang.go # Go patterns
β β βββ rust.go # Rust patterns
β β βββ docker.go # Dockerfile/compose patterns
β β βββ scanner_test.go
β βββ validator/
β β βββ validator.go # Validation engine
β β βββ schema.go # Schema parsing
β β βββ types.go # Type validators
β β βββ validator_test.go
β βββ differ/
β β βββ differ.go # Env file diffing
β β βββ differ_test.go
β βββ gitguard/
β β βββ gitguard.go # Security checks
β β βββ patterns.go # Secret detection patterns
β β βββ gitguard_test.go
β βββ sync/
β β βββ crypto.go # AES-256-GCM encrypt/decrypt
β β βββ crypto_test.go
β βββ config/
β βββ config.go # .envguard.yaml parsing
β βββ config_test.go
βββ .github/workflows/ # CI + Release
βββ .goreleaser.yaml
βββ Makefile
βββ BACKLOG.md
βββ CHANGELOG.md
βββ CONTRIBUTING.md
βββ README.md
π€ Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
π License
MIT β use it however you want.