Setup & Auth
Initialize a project, manage your encryption key, run health checks, and install the pre-commit hook.
vars init
npx dotvars initSets up a new vars project. vars:
- Creates
config.vars— single encrypted secrets file (safe to commit) - Creates
.vars/key— master encryption key (gitignored) - Updates
.gitignore— key and swap files excluded - Adds
#varsimport topackage.jsonscripts
If a .env file exists, vars offers to import it. It reads the key-value pairs, guesses Zod schemas from the values, and encrypts everything before writing.
If config.vars already exists but .vars/key is missing (e.g., a fresh clone), running init again detects the incomplete setup and creates the missing key file.
Flags
| Flag | Default | What it does |
|---|---|---|
--file, -f | .env | Path to the .env file to import |
--env | dev | Environment name for imported values |
Example
# Import from a non-default path, label values as "staging"
npx dotvars init --file .env.staging --env stagingvars key
Subcommands for managing your encryption key.
vars key init
npx dotvars key initGenerates a new .vars/key file. Run this on a fresh clone that already has a config.vars committed.
vars key fingerprint
npx dotvars key fingerprintPrints a short fingerprint of the current key. Use it to verify that two machines share the same key without exposing the key itself.
vars key export
npx dotvars key exportPrints the raw key to stdout. Pipe it to a secure channel when sharing with a teammate or storing in CI.
# Copy key to clipboard (macOS)
npx dotvars key export | pbcopyvars doctor
npx dotvars doctorRuns health checks and prints a summary. Exits 1 if any check fails.
Checks
Files:
config.varsexists.vars/keyexists- Codegen is up to date (generated file matches current schemas)
Security:
.vars/keyis gitignored- Pre-commit hook installed
- All values are encrypted
Secrets Health:
- No expiring or deprecated secrets (warns if
@expiresis within 30 days, or past due)
Example output
◆ Files
│ ✓ config.vars found
│ ✓ .vars/key found
│ △ codegen up to date
│ Run vars gen to regenerate
◆ Security
│ ✓ .vars/key is gitignored
│ △ Pre-commit hook installed
│ Run vars hook to install
◆ Secrets Health
│ ✓ No expiring or deprecated secretsRun it in CI to catch drift before it bites you in prod.
vars hook
npx dotvars hookInstalls a pre-commit hook that blocks commits when any *.unlocked.vars file is staged. This prevents accidentally committing decrypted secrets.
Run it once after cloning — vars init does this automatically for new projects.
vars completions
npx dotvars completions <shell>Writes a shell completion script to stdout. Redirect it to wherever your shell loads completions from.
Supported shells
| Shell | Setup |
|---|---|
bash | npx dotvars completions bash >> ~/.bash_completion |
zsh | npx dotvars completions zsh > ~/.zsh/completions/_vars |
fish | npx dotvars completions fish > ~/.config/fish/completions/vars.fish |
Open a new shell after running and tab-completion works for all vars subcommands.