dotenv-diff is a CLI-first tool and does not manage git hooks or CI workflows by itself.
Instead, it is built to integrate cleanly with your existing tooling, such as Husky pre-commit hooks and GitHub Actions.
Running dotenv-diff before each commit helps catch missing, unused, and misused environment variables early.
A common setup is to use Husky to run dotenv-diff:
{
"scripts": {
"dotenv-diff": "dotenv-diff --example .env.example"
}
}Best practice if to set the example file to .env.example (default is .env) to ensure you are validating against your reference file.
Use dotenv-diff in CI to validate environment variable consistency on pull requests.
This is especially useful to keep .env.example in sync with real usage in code.
.github/workflows/dotenv-diff.yml
name: dotenv-diff
on: [pull_request]
jobs:
env-validation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-node@v6
- run: npm ci
- run: npx dotenv-diff --example .env.example --strict- Prevent commits that introduce undocumented environment variables
- Catch framework-specific env usage issues early
- Keep
.env.exampleaccurate across contributors and pull requests
- Use
--exampleto validate against your reference file - Use
--strictin CI for fail-fast behavior on warnings - Keep hook checks fast and predictable
- Pair with monorepo patterns (
--include-files) where relevant
