CLI Commands
Varlock provides a command-line interface for managing environment variables and secrets. This reference documents all available CLI commands.
See installation for instructions on how to install Varlock. You can also enable shell completion for tab completion of commands and flags.
Running commands in JS projects
Section titled “Running commands in JS projects”If you have installed varlock as a package.json dependency, rather than a standalone binary, the best way to invoke the CLI is via your package manager:
npm exec -- varlock ...pnpm exec -- varlock ...bunx varlock ...vlx -- varlock ...yarn exec -- varlock ...Also note that within package.json scripts, you can use it directly:
{ "scripts": { "start": "varlock run -- node app.js" }}package.json configuration
Section titled “package.json configuration”You can configure varlock’s default behavior by adding a varlock key to your package.json:
{ "varlock": { "loadPath": "./envs/" }}| Option | Description |
|---|---|
loadPath | Path (or array of paths) to a directory or specific .env file to use as the default entry point. Defaults to the current working directory if not set. Use a directory path (with trailing /) to automatically load all relevant files (.env.schema, .env, .env.local, etc.); a file path only loads that file and its explicit imports. When an array is provided, all paths are loaded and combined — later entries take higher precedence. Can be overridden by the --path CLI flag. Varlock looks for this config in the package.json in the current working directory only. |
Commands reference
Section titled “Commands reference”varlock init
Section titled “varlock init”Starts an interactive onboarding process to help you get started. Will help create your .env.schema and install varlock as a dependency if necessary.
varlock init [options]Options:
--agent: Run non-interactively for agent/automation workflows. Skips confirmation prompts and uses deterministic defaults for schema generation.
Examples:
# Interactive setup wizardvarlock init
# Non-interactive setup for AI agentsvarlock init --agentvarlock load
Section titled “varlock load”Loads and validates environment variables according to your .env files, and prints the results. Default prints a nicely formatted, colorized summary of the results, but can also print out machine-readable formats.
Useful for debugging locally, and in CI to print out a summary of env vars.
varlock load [options]Options:
--format: Format of output [pretty|json|env|shell|json-full]--agent: Agent-safe mode — defaults to JSON output and redacts sensitive values. Not compatible with--format envor--format shell.--compact: Compact output (json-full: no indentation, env/shell: skip undefined values)--show-all: Shows all items, not just failing ones, when validation is failing--env: Set the default environment flag (e.g.,--env production), only useful if not using@currentEnvin.env.schema--path/-p: Path to a specific.envfile or directory to use as the entry point (overridesvarlock.loadPathinpackage.json). Can be specified multiple times to load from multiple paths — later paths take higher precedence.
Examples:
# Load and validate environment variablesvarlock load
# Load and validate for a specific environment (when not using @currentEnv in .env.schema)varlock load --env production
# Output validation results in JSON formatvarlock load --format json
# Output full serialized graph (including errors/configErrors fields)varlock load --format json-full
# Compact outputvarlock load --format json-full --compact
# Output as shell export statements (useful for direnv / eval)eval "$(varlock load --format shell)"
# When validation is failing, will show all items, rather than just failing onesvarlock load --show-all
# Load from a specific .env filevarlock load --path .env.prod
# Load from a specific directoryvarlock load --path ./config/
# Load from multiple directories (later paths take higher precedence)varlock load -p ./envs -p ./overrides
# Agent-safe JSON output with sensitive values redactedvarlock load --agentvarlock run
Section titled “varlock run”Executes a command in a child process, injecting your resolved and validated environment variables from your .env files. This is useful when a code-level integration is not possible.
varlock run -- <command>Options:
--no-redact-stdout: Disable stdout/stderr redaction to preserve TTY detection for interactive tools--no-inject-graph: Disable injection of__VARLOCK_ENVserialized config graph into the child process environment--path/-p: Path to a specific.envfile or directory to use as the entry point. Can be specified multiple times to load from multiple paths — later paths take higher precedence.
Examples:
varlock run -- node app.js # Run a Node.js applicationvarlock run -- python script.py # Run a Python script
# Use a specific .env file as entry pointvarlock run --path .env.prod -- node app.js
# Use a specific directory as entry pointvarlock run --path ./config/ -- node app.js
# Use multiple directories as entry pointsvarlock run -p ./envs -p ./overrides -- node app.jsvarlock printenv
Section titled “varlock printenv”Resolves and prints the value of a single environment variable to stdout. Only the requested item and its transitive dependencies are resolved, making this faster than loading the full graph.
This is useful within larger shell commands where you need to embed a single resolved env var value.
varlock printenv <VAR_NAME> [options]Options:
--path/-p: Path to a specific.envfile or directory to use as the entry point. Can be specified multiple times to load from multiple paths — later paths take higher precedence.
Examples:
# Print the resolved value of MY_VARvarlock printenv MY_VAR
# Use a specific .env file as entry pointvarlock printenv --path .env.prod MY_VAR
# Use multiple directories as entry pointsvarlock printenv -p ./envs -p ./overrides MY_VAR
# Embed in a shell command using subshell expansionsh -c 'some-tool --token $(varlock printenv MY_TOKEN)'varlock scan
Section titled “varlock scan”Scans your project files for sensitive config values that should not appear in plaintext. Loads your varlock config, resolves all @sensitive values, then checks files for any occurrences of those values.
This is especially useful as a pre-commit git hook to prevent accidentally committing secrets into version control, and for scanning build output to ensure no secrets leaked into files that will be published or deployed.
varlock scan [paths...] [options]Positional arguments:
[paths...]: Optional list of file paths, directories, or glob patterns to scan. When provided, only these targets are scanned — git filtering (--staged,--include-ignored) is bypassed and build-output directories that are normally skipped (such asdist,.next,build) are included.
Options:
--staged: Only scan staged git files (ignored when explicit paths are provided)--include-ignored: Include git-ignored files in the scan (ignored when explicit paths are provided)--install-hook: Set upvarlock scanas a git pre-commit hook--path/-p: Path to a specific.envfile or directory to use as the schema entry point. Can be specified multiple times to load from multiple paths — later paths take higher precedence.
Examples:
# Scan all non-gitignored files in the current directoryvarlock scan
# Only scan staged git filesvarlock scan --staged
# Scan all files, including gitignored onesvarlock scan --include-ignored
# Scan a specific build output directory (e.g. to check for leaked secrets before publishing)varlock scan ./dist
# Scan multiple directoriesvarlock scan ./dist ./public
# Scan files matching a glob patternvarlock scan './dist/**/*.js'
# Use a specific .env file as the schema entry pointvarlock scan --path .env.prod
# Use multiple schema entry pointsvarlock scan -p ./envs -p ./overrides
# Set up as a git pre-commit hookvarlock scan --install-hookvarlock encrypt
Section titled “varlock encrypt”Encrypts sensitive values using device-local encryption. Encrypted values are stored in .env files using the varlock() resolver function and are automatically decrypted at load time.
On macOS, encryption is hardware-backed via the Secure Enclave (with Touch ID / biometric authentication). On Windows and Linux, platform-specific secure storage is used. A pure-JavaScript file-based fallback is available on all platforms.
varlock encrypt [options]Options:
--file: Path to a.envfile — encrypts all sensitive plaintext values in-place
Examples:
# Interactive mode: encrypt a single value (prompts with hidden input)varlock encrypt
# Pipe a value via stdin (keeps secrets out of shell history)printf '%s' "$SECRET" | varlock encryptvarlock encrypt < secret.txt
# Encrypt all sensitive plaintext values in a .env filevarlock encrypt --file .env.localIn single-value mode, you’ll either be prompted to enter a value (hidden input) or the value will be read from stdin when piped. The encrypted output is printed for you to copy into your .env.local file:
SOME_SENSITIVE_KEY=varlock("local:<encrypted>")In file mode, varlock loads the env graph, identifies @sensitive items with plaintext values, and lets you select which to encrypt in-place.
varlock reveal
Section titled “varlock reveal”Securely view or copy the value of a @sensitive environment variable. The value is displayed in an alternate terminal screen buffer so it doesn’t persist in your scrollback history.
🔒 Usually sensitive values are redacted, so this is needed to actually view the value without exposing it in plaintext on disk or in your terminal history.
varlock reveal [VAR_NAME] [options]Options:
--copy: Copy the value to clipboard instead of displaying (auto-clears after 10s)--path/-p: Path to a specific.envfile or directory to use as the entry point--env: Set the environment (e.g., production, development, etc)
Examples:
# Interactive picker to browse and reveal sensitive valuesvarlock reveal
# Reveal a specific variablevarlock reveal MY_SECRET
# Copy a value to clipboard (auto-clears after 10s)varlock reveal MY_SECRET --copyvarlock lock
Section titled “varlock lock”Locks the encryption daemon, requiring biometric authentication (e.g., Touch ID) for the next decrypt operation. This invalidates the current biometric session cache.
varlock lockThis command only has an effect when using a biometric-enabled encryption backend (macOS Secure Enclave, Windows Hello, or Linux with polkit/PAM biometric setup). On other backends, it will display a message and exit.
varlock audit
Section titled “varlock audit”Scans your source code for environment variable references and compares them against keys defined in your schema.
This command reports two drift categories:
- Missing in schema: key is used in code but not declared in schema
- Unused in schema: key is declared in schema but not referenced in code
Exit codes:
0when schema and code are in sync1when drift is detected
varlock audit [paths...] [options]Positional arguments:
[paths...]: Optional list of directories to scan. When provided, only these directories are scanned instead of the auto-detected scan root.
Options:
--path/-p: Path to a specific.envfile or directory to use as the schema entry point--ignore/-i: Directory to exclude from code scanning (can be specified multiple times)
Examples:
# Audit current projectvarlock audit
# Audit using a specific .env file as schema entry pointvarlock audit --path .env.prod
# Audit using a directory as schema entry pointvarlock audit --path ./config
# Only scan specific directoriesvarlock audit ./src ./lib
# Exclude directories from scanningvarlock audit --ignore vendor
# Exclude multiple directoriesvarlock audit -i vendor -i generatedvarlock typegen
Section titled “varlock typegen”Generates type files according to @generateTypes and your config schema. Uses only non-environment-specific schema info, so output is deterministic regardless of which environment is active.
This command is particularly useful when you have set auto=false on the @generateTypes decorator to disable automatic type generation during varlock load or varlock run.
varlock typegen [options]Options:
--path/-p: Path to a specific.envfile or directory to use as the entry point. Can be specified multiple times to load from multiple paths — later paths take higher precedence.
Examples:
# Generate types using the default schemavarlock typegen
# Generate types from a specific .env filevarlock typegen --path .env.prod
# Generate types from multiple directoriesvarlock typegen -p ./envs -p ./overridesvarlock telemetry
Section titled “varlock telemetry”Opts in/out of anonymous usage analytics. This command creates/updates a configuration file at $XDG_CONFIG_HOME/varlock/config.json (defaults to ~/.config/varlock/config.json) saving your preference.
varlock telemetry disablevarlock telemetry enablevarlock help
Section titled “varlock help”Displays general help information, alias for varlock --help
varlock helpFor help about specific commands, use:
varlock subcommand --help