"Works on my machine" because someone forgot to add a variable to
.env.example? This is for you. envdrift keeps your.envfiles, your.env.exampleand the variables your code actually reads in sync.
Catch missing, empty and undocumented environment variables before they reach production.
Real output of envdrift --code src inside examples/app.
.env.example is the contract between your code and everyone who runs it. It drifts all the time:
- a teammate adds
REDIS_URLto the code but not to the example, and the next deploy crashes - your local
.envstill hasSTRIPE_SECRET_KEY=<your-key> - old keys pile up in
.envlong after the code stopped reading them
A plain linter checks syntax. envdrift checks the three-way contract: example file, real env files, and source code.
- 🔍 Check one or many env files against
.env.example:MISSING,EMPTY(blank or<placeholder>),EXTRA - 🧠 Code scan: finds env vars read in Python, JavaScript/TypeScript (incl.
import.meta.env), Go, Ruby, Rust, PHP, Java and Deno, and reportsUNDOCUMENTEDandUNUSEDkeys - 🩹 Sync: appends missing keys to
.envwith the example's default; never edits or deletes your lines (--dry-runto preview) - 🏗️ Init: turns a real
.envinto a.env.example, blanking secrets but keeping safe defaults likeDEBUG=trueorPORT=8080 - 🧹 Lint: duplicate keys, invalid names, spaces around
=, unquoted spaces, unclosed quotes, trailing whitespace; reads stdin with- - 🔧 Lint
--fix: rewrites spacing, quoting and trailing whitespace in place; removes duplicate keys only after you pick which copy stays (--dedupe first|lastor a prompt);--dry-runto preview - 🪝 pre-commit hooks:
envdrift-lintandenvdrift-lint-fix - 📦 Export to JSON, shell
export, Docker--env-file, or$GITHUB_ENV(multi-line safe) - 🙈 Ignore lists with globs (
--ignore 'AWS_*'or a.envdriftignorefile) - 🔒 Values are never printed by
check; 🪶 zero dependencies;--jsonand exit codes for CI
pip install git+https://github.com/purkat0301-sys/envdrift
envdrift --code src # compare .env, .env.example and the code in src/
envdrift sync # add whatever .env is missingflowchart LR
X[.env.example] --> C{compare}
E[.env / .env.production ...] --> C
S[source code] --> K[scan for os.getenv,<br/>process.env, ENV ...] --> C
C --> M[MISSING / EMPTY / EXTRA]
C --> U[UNDOCUMENTED / UNUSED]
M & U --> R[report + exit code]
| Command | What it does |
|---|---|
envdrift / envdrift check |
Compare env files (and optionally code) with the example. Exit 1 on missing, empty or undocumented keys; --strict also fails on extras |
envdrift scan [dir] |
List every env var the code reads, with file and line |
envdrift sync |
Append missing keys to .env |
envdrift init [.env] |
Print a safe .env.example built from a real .env |
envdrift lint [files or -] |
Syntax and style problems |
envdrift lint --fix [files] |
Fix formatting in place (--dry-run to preview, --dedupe first|last for duplicates) |
envdrift export [file] --format json|shell|docker|github |
Convert an env file |
- repo: https://github.com/purkat0301-sys/envdrift
rev: <commit SHA or release tag>
hooks:
- id: envdrift-lint-fixenvdrift-lint only reports; envdrift-lint-fix fixes formatting and fails the commit so you can review the change. Both skip .env.example.
- run: pip install git+https://github.com/purkat0301-sys/envdrift
- run: envdrift --env .env.ci --code srcInspired by dotenv-linter/dotenv-linter (MIT, Rust), a fast and mature .env linter, and by requests in its issue tracker:
--stdin (#803), filtering comparisons (#541),
filling missing keys (#728), an export command (#715) and .envignore (#773).
The code here is written from scratch.
| envdrift | dotenv-linter | |
|---|---|---|
| Syntax / style lint | ✅ basic set | ✅ larger set, very fast |
| Auto-fix lint problems | ✅ formatting only; duplicates need a choice | ✅ |
| Compare env files | ✅ against an example | ✅ |
| Scan source code for undocumented vars | ✅ 9 languages | ❌ |
| Fill missing keys from the example | ✅ sync |
requested in #728 |
| Read from stdin | ✅ lint - |
requested in #803 |
| Export to JSON / shell / Docker / GitHub | ✅ | requested in #715 |
| Ignore file with globs | ✅ .envdriftignore |
requested in #773 |
| Install | pip (Python) |
binary, brew, cargo, Docker |
Status of the dotenv-linter feature requests is as of 2026-11-29. If you need the fastest pure linter, use dotenv-linter; envdrift focuses on drift between files and code.
Will it leak my secrets in CI logs? check, lint, scan and sync print key names only. export prints values by design.
My code reads variables dynamically (os.environ[name]). Only string literals are detected. Put such keys in .envdriftignore or document them.
Does sync overwrite anything? No. It only appends missing keys under a comment.
What does lint --fix change? Spaces around =, trailing whitespace, and unquoted values with spaces (they get double quotes). It never renames keys, never touches multi-line values, and never prints values. A duplicate key stays until you choose which copy to keep.
- Code scanning is regex based: it finds literal names, not computed ones.
- The parser follows common dotenv rules; exotic variable expansion (
${A:-b}) is read as plain text. - Not on PyPI yet; install from GitHub.
See ROADMAP.md: type hints in .env.example (# type: url), monorepo mode, variable expansion.
By the same author: mcp-preflight (check MCP configs) · agent-skill-lint (lint Agent Skills)
Issues and pull requests are welcome. pip install -e '.[dev]' && pytest. New languages for the code scan go in CODE_PATTERNS with a test.