get-dotenv can power a standalone, generated CLI that you embed in your projects. This approach is great when you want a fixed command surface with minimal code in the host repository.
The plugin-first host (GetDotenvCli) resolves dotenv context once per invocation and provides:
--trace diagnostics).If you need custom commands, richer composition, or programmatic hooks, prefer the plugin host. You can still expose the same ergonomics as a CLI while enjoying better structure and observability.
The generator produces a Command wired with the base options, a default cmd subcommand, and the batch subcommand. You can set defaults from a getdotenv.config.json and forward variables to subprocesses.
Example:
# JSON config + .local variant, and a CLI skeleton named "acme"
npx getdotenv init . \
--config-format json \
--with-local \
--cli-name acme \
--force
# TypeScript config with a dynamic example; CLI named "toolbox"
npx getdotenv init ./apps/toolbox \
--config-format ts \
--cli-name toolbox
This scaffolds:
getdotenv.config.json (and .local variant if requested)src/cli/<name>/index.tsInside npm scripts, prefer the parent-level alias form to ensure flags apply to getdotenv rather than the inner shell command:
{
"scripts": {
"env-print": "getdotenv -c 'node -e \"console.log(process.env.APP_SETTING ?? \\\"\\\")\"'"
}
}
Then:
npm run env-print -- -e dev
The generated CLI uses the same always-on loader and post-composition checks as the plugin-first host:
requiredKeys or provide a JS/TS Zod schema. Warnings are printed by default; pass --strict (or set strict: true) to fail the run on issues.--redact with optional --redact-pattern <regex...> to mask secret-like keys in --trace and -l/--log outputs. Entropy warnings are on by default and can be tuned via:
--entropy-warn / --entropy-warn-off--entropy-threshold <n>--entropy-min-length <n>--entropy-whitelist <regex...>--trace [keys...] for per-key origin lines and --capture (or GETDOTENV_STDIO=pipe) for CI-friendly buffered output.See also:
See the Generated CLI guide for details.