Tiny Go CLI that catches missing or empty .env keys before they break your deploy. Compares .env against .env.example, validates required values, scans source code (Go, JS/TS, Python, Ruby, Rust, PHP) for env vars referenced in code but missing from your template, and emits GitHub Actions annotations on failure. Drop it into CI or a pre-commit hook — one static binary, no dependencies.
With Go:
go install github.com/caglareker/envcheck@latest
Pre-built binary: download the archive for your platform from
Releases, extract, and put
the envcheck binary on your $PATH.
Check the version:
envcheck --version
envcheck --template .env.example --actual .env
| Flag | Default | Purpose |
|---|---|---|
--template |
.env.example |
Template file listing required keys |
--actual |
.env |
Env file to check |
--ci |
false |
Exit non-zero when any problem is detected |
--strict |
false |
Also report keys present in --actual but not in --template |
--require-values |
false |
Fail when a required key is present but empty in --actual (e.g. API_KEY=) |
--scan |
(off) | Scan a source directory for env-var usage and flag keys missing from template |
--ignore |
(none) | Skip keys matching these glob patterns in every check; comma-separated, repeatable |
--format |
text |
Output format: text (human readable) or github (Actions annotations) |
| Code | Meaning |
|---|---|
0 |
Success — or problems found but --ci is off |
1 |
--ci and at least one of: missing keys, empty required values, extra keys, undeclared scan hits |
2 |
Could not read one of the env files (e.g. file not found, permission denied) |
- Lines starting with
#are treated as comments and ignored. - Inline comments after a value (
PORT=5432 # the port) are stripped. export FOO=baris supported.- Quoted values (
KEY="value with spaces",KEY='single') are unwrapped. KEY=""is considered empty for--require-values.
Fail CI when keys are missing:
envcheck --ci
Also flag stale keys in .env that are no longer in the template:
envcheck --strict --ci
Fail when a required key was added but left blank (the classic "I forgot to set it in CI" bug):
envcheck --require-values --ci
Emit GitHub Actions annotations so missing keys show up inline on PRs:
envcheck --ci --format=github
Catch env vars used in code but forgotten in .env.example:
envcheck --scan ./src --ci
Skip keys you never want reported — system variables, vendor prefixes, stale local-only keys:
envcheck --scan ./src --ci --ignore 'PATH,HOME,NODE_ENV' --ignore 'AWS_*'
--scan <dir> walks the given directory and looks for env-var references in
source files. Anything used in code but not declared in the template is
reported as undeclared, with the file + line number of each call site.
Supported languages:
| Extension | Detected patterns |
|---|---|
.go |
os.Getenv("X"), os.LookupEnv("X") |
.js .jsx .ts .tsx .mjs .cjs |
process.env.X, process.env["X"], import.meta.env.X, Deno.env.get("X") |
.py |
os.environ["X"], os.environ.get("X"), os.getenv("X") |
.rb |
ENV["X"], ENV.fetch("X") |
.rs |
env::var("X"), env::var_os("X") |
.php |
getenv("X"), $_ENV["X"] |
Skipped directories: .git, node_modules, vendor, target, dist, build, .next, .nuxt, __pycache__, .venv, venv, .tox.
--ignore takes glob patterns and drops matching keys from every check —
missing, empty, extra and undeclared alike. It is comma-separated and
repeatable, so these two are equivalent:
envcheck --ignore PATH,HOME,NODE_ENV
envcheck --ignore PATH --ignore HOME --ignore NODE_ENV
Patterns use path.Match syntax — * matches
any run of characters, ? matches exactly one — and are case-sensitive:
| Pattern | Matches |
|---|---|
PATH |
exactly PATH |
AWS_* |
AWS_REGION, AWS_SECRET_ACCESS_KEY, … |
*_SECRET |
DB_SECRET, APP_SECRET, … |
VITE_? |
VITE_A, but not VITE_API |
Nothing is dropped silently: when a key is actually suppressed, the text output
says so (ignored 3 key(s) via --ignore). A malformed pattern exits 2 instead
of quietly matching nothing.
There is no built-in ignore list, on purpose. A validation tool that skips
keys you never asked it to skip is hard to trust, and "system variable" means
different things in different projects — NODE_ENV, PORT and CI are real
application config in plenty of them. Scan mode is where you will want this
most; a reasonable starting point to copy:
envcheck --scan ./src --ci \
--ignore 'PATH,HOME,USER,SHELL,LANG,PWD,TMPDIR,CI,NODE_ENV'
envcheck ships a pre-commit hook definition. Add it
to your .pre-commit-config.yaml:
repos:
- repo: https://github.com/caglareker/envcheck
rev: v0.1.0
hooks:
- id: envcheckThe hook runs envcheck --ci whenever a .env* file changes, so commits that
introduce or break env declarations fail locally instead of in CI.
Enable additional checks via args:
- id: envcheck
args: [--ci, --strict, --require-values]Scan source code for undeclared env vars:
- id: envcheck
args: [--ci, --scan, ./src]Silence keys that are not yours to declare:
- id: envcheck
args: [--ci, --scan, ./src, --ignore, 'PATH,HOME,NODE_ENV,AWS_*']Got tired of deploys failing at runtime because someone forgot to add a new env var to the pipeline. Wanted something simpler than a shell script.
MIT