Command Line Flags

dotenv-diff supports many command line flags to customize its behavior. Here's a complete reference of all available options:

Core Operations

Scan your codebase for environment variable usage. This is the default behavior when no flags are specified.

Terminal
dotenv-diff

File Specification

Specify a custom path to your .env file instead of using the default location, which is the root of your project.

Terminal
dotenv-diff --env ./config/.env

Specify a custom path to your .env.example file.

Terminal
dotenv-diff --example ./templates/.env.template

It does not matter whether you use the --env or --example flag, as both will work as the environment variable source.

If you use both, --example will be prioritized over --env.

File Pattern Control

Completely replace the default file patterns with your own comma-separated list.

Terminal
dotenv-diff --files *.ts,*.js,src/**/*.vue

Add additional file patterns to the default scan patterns (extends rather than replaces).

Terminal
dotenv-diff --include-files *.php,*.rb

Exclude specific file patterns from being scanned.

Terminal
dotenv-diff --exclude-files *.test.js,dist/**/*

Filtering & Ignoring

Ignore specific environment variable keys during analysis.

Terminal
dotenv-diff --ignore DEBUG,NODE_ENV,PORT

Use a regex pattern to ignore matching environment variable keys.

Terminal
dotenv-diff --ignore-regex ^TEST_.*

Comparison Options

Compare all of your .env* files for differences.

Terminal
dotenv-diff --compare

Together with compare, check values between your .env* files

Terminal
dotenv-diff --compare --check-values

Together with compare, you can allow duplicate values.

Terminal
dotenv-diff --compare --allow-duplicates

Only run specific analysis categories. Available: missing, extra, empty, mismatch, duplicate, gitignore.

Terminal
dotenv-diff --compare --only missing,duplicate

By running --compare without having a .env or .env.example file, you will be prompted to create one.

You can automatically answer "Yes" to all prompts and run non-interactively. in this scenario, you will not be prompted to create a .env from your existing .env.example file.

Terminal
dotenv-diff --compare --yes

Automation & CI/CD

Run in CI mode: non-interactive and never creates files. Perfect for continuous integration.

Terminal
dotenv-diff --ci

Enable strict mode - the process will fail on warnings, not just errors.

Terminal
dotenv-diff --strict

Automatically fix common issues like removing duplicates and adding missing keys.

Terminal
dotenv-diff --fix

Output Control

Output results in JSON format instead of human-readable text.

Terminal
dotenv-diff --json

Disable colored output for terminals that don't support colors.

Terminal
dotenv-diff --no-color

Hide variables that are defined in .env but not used in your codebase.

Terminal
dotenv-diff --no-show-unused

Hide the statistics summary at the end of the report.

Terminal
dotenv-diff --no-show-stats

Security

Disable potential secret detection during codebase scanning (secret detection is enabled by default).

Terminal
dotenv-diff --no-secrets

If you only want to ignore a specific line in your codebase from potential secrets detection, you can add // dotenv-diff-ignore comment at the end of the line:

example.ts
const hardcodedURL = 'https://thisShouldBeIgnored.com'; // dotenv-diff-ignore

Note: This will only ignore potential secrets warnings for the specific line it is added to. Other errors on the same line will still be reported:

example.ts
const api = process.env.API_URL || 'https://api.dotenv-diff.com'; // dotenv-diff-ignore

In the above example, only the potential secret warning for the hardcoded URL will be ignored. The missing variable warning for API_URL will still be reported if it is not defined in .env.

Common Flag Combinations

CI/CD Pipeline:

This command sets up a CI/CD pipeline with strict mode and compare it to your .env.example file.

Terminal
dotenv-diff --ci --strict --example .env.example

This command works well in a turbo monorepo setup.

Terminal
dotenv-diff --include-files "./src/**/*,../../packages/**/*"

These flags give you complete control over how dotenv-diff analyzes your environment variables, making it perfect for any workflow or CI/CD pipeline.