Command Line Flags

Just like configuration, 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

If you want to scan your project without comparing against any .env files, use:

Terminal
dotenv-diff --no-compare

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

You can also ignore specific URLs from being flagged during secret scanning using --ignore-urls.

Terminal
dotenv-diff --ignore-urls https://safe.com,https://cdn.local

This is useful when your project contains public or whitelisted URLs that should not trigger false positive secret warnings.

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

Configuration & Initialization

Create a sample configuration file in your project root using:

Terminal
dotenv-diff --init

This generates a dotenv-diff.config.json file with default settings, which you can edit and commit to version control.

dotenv-diff.config.json
{
  "strict": false,
  "example": ".env.example",
  "ignore": ["NODE_ENV", "VITE_MODE"],
  "ignoreUrls": ["https://example.com"]
}

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.