Skip to content

Encryption commands

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, keys are TPM-sealed when a TPM is available (Windows Hello gates interactive decrypts). On Linux, TPM2 and/or Secret Service is used. A pure-JavaScript file-based fallback is available on all platforms.

See the local encryption guide for platform details. On Windows, existing DPAPI keys are automatically upgraded to TPM sealing on the next decrypt.

Terminal window
varlock encrypt [options]

Options:

  • --file: Path to a .env file; encrypts all sensitive plaintext values in-place

Examples:

Terminal window
# 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 encrypt
varlock encrypt < secret.txt
# Encrypt all sensitive plaintext values in a .env file
varlock encrypt --file .env.local

In 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.

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.

Terminal window
varlock reveal [VAR_NAME] [options]

Options:

  • --copy: Copy the value to clipboard instead of displaying (auto-clears after 10s)
  • Common options: --path / -p, --env

Examples:

Terminal window
# Interactive picker to browse and reveal sensitive values
varlock reveal
# Reveal a specific variable
varlock reveal MY_SECRET
# Copy a value to clipboard (auto-clears after 10s)
varlock reveal MY_SECRET --copy

Locks the encryption daemon, requiring biometric authentication (e.g., Touch ID) for the next decrypt operation. This invalidates the current biometric session cache.

Terminal window
varlock lock

This 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.

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

Pure execution-environment plumbing, meaning variables that reflect where/how the process runs (e.g. PATH, HOME, SHELL, NODE_OPTIONS, npm_*), is read from process.env in normal code but is never part of your schema, so it is not reported as missing. Semantically meaningful variables your app or CI may depend on (e.g. NODE_ENV, CI, GitHub Actions vars) are still reported, so you can decide whether to declare them or suppress them with @auditIgnore.

Exit codes:

  • 0 when schema and code are in sync
  • 1 when drift is detected
Terminal window
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:

  • Common options: --path / -p (here it sets the schema entry point, single path only)
  • --ignore / -i: Directory to exclude from code scanning (can be specified multiple times)

Examples:

Terminal window
# Audit current project
varlock audit
# Audit using a specific .env file as schema entry point
varlock audit --path .env.prod
# Audit using a directory as schema entry point
varlock audit --path ./config
# Only scan specific directories
varlock audit ./src ./lib
# Exclude directories from scanning
varlock audit --ignore vendor
# Exclude multiple directories
varlock audit -i vendor -i generated

Generates a random 256-bit encryption key for use with _VARLOCK_ENV_KEY. This key is used to encrypt the resolved env blob that gets baked into your build output on certain frameworks/platforms.

Terminal window
varlock generate-key
varlock generate-key --plain

Flags:

  • --plain: Print only the key (no surrounding help text). Useful for piping into platform CLIs, e.g. varlock generate-key --plain | vercel env add _VARLOCK_ENV_KEY production --sensitive.

See the encrypted deployments guide and the Next.js / Vite integration docs for setup instructions.