Varlock
This skill helps securely manage env vars and secrets in your project using varlock.
Varlock uses
(instead of
) to provide a single source of truth for your project's env vars. Schema info is expressed using
style comments. Sensitive values can be set in git-ignored
files, passed in via the environment, or use functions to load from secure backends like 1Password, Vault, AWS, etc.
env
# @defaultSensitive=false @defaultRequired=infer
# @currentEnv=$APP_ENV
# @generateTsTypes(path=env.d.ts)
# ---
# @type=enum(dev, staging, prod)
APP_ENV=dev
# @type=url
API_URL=https://api.example.com
# Description of this var
# @sensitive @required @type=string(startsWith=sk-)
# @docs(https://xyzapi.com/docs/auth)
XYZ_API_KEY=
Your
is committed to version control and safe for agents to read and update. The
CLI helps load and validate env vars while masking anything sensitive, and can securely inject env vars into commands.
NOTE: If varlock is installed locally via
(not as a standalone binary), invoke it via your package manager — e.g.,
,
,
. Check the project's package manager before running CLI commands.
CRITICAL: Security rules
These rules are non-negotiable:
Do not expose secrets
bash
# NEVER do these - exposes secrets to agent context
cat .env
cat .env.local
echo $SECRET_KEY
printenv | grep API
# SAFE alternatives
varlock load --agent # JSON output, sensitive values redacted
varlock load # human-readable, sensitive values masked
cat .env.schema # schema only, no secret values
If the user needs to see a sensitive value, tell them to run
.
File access rules
- Safe to read and edit: and any other git-committed files (usually env-specific files like )
- Do not read or edit: , , , or other gitignored value/override files — these may contain unencrypted secrets
- Do not log or quote raw secret values in code, comments, or chat
Sensitivity rules
- Items marked must not have that decorator removed without confirming with the user
- Ask the user to edit secret values in their local/gitignored env files or their secret provider (1Password, AWS, etc.) — never fill in secrets yourself
When the user asks to "show me the .env file"
Do not read
or
directly. Instead run
to show masked values, or read
to show the schema. Explain that reading env files directly could expose secrets.
When the user asks to "update/set a secret"
Do not write secret values yourself. Tell the user to either:
- Update it in their secret provider (1Password, AWS, etc.) and then help them wire it up
- Edit the value in their file manually
- ideally encrypt it by using as the value, then run to be prompted
File roles
| File | Role | Agent may edit? |
|---|
| Schema, defaults, decorators, descriptions | Yes |
| Environment-specific tracked config (e.g. ) | Yes |
| , | Local/gitignored values and overrides | No — tell user to edit |
| Environment-specific local overrides (gitignored) | No — tell user to edit |
| Legacy example file; migrate into schema | Review with user |
Ensure
and tracked env-specific files are not gitignored (
,
, etc. in
if needed).
Environment-specific files and precedence
When
is set in
(e.g.,
), varlock automatically loads matching environment-specific files. Files are applied in increasing precedence order:
For example, if
, then
and
will be loaded automatically if they exist. A value in
overrides one in
, and
always wins.
Schema syntax
Root decorators (file header)
Root decorators go in comment blocks at the top of the file, before the first item. A
divider usually separates the header from items.
| Decorator | Purpose | Default |
|---|
| Sets which item determines the active environment | — |
@defaultRequired=bool|infer
| Default required state for items in this file | |
@defaultSensitive=bool|inferFromPrefix(PREFIX)
| Default sensitive state for items in this file | |
@generateTsTypes(path=./env.d.ts)
| Auto-generate TypeScript env declarations (deprecated alias: ) | — |
| / / / / / | Generate a typed env module for that language | — |
| Import schema/values from another .env file or directory | — |
@plugin(@varlock/name-plugin)
| Load a plugin | — |
| Inject multiple values from an external source | — |
| Disable loading this file (can use ) | |
- defaults to — all items are sensitive unless explicitly marked or . Set to flip the default.
- (the default): items with a value in the schema are required, items without are optional
@defaultSensitive=inferFromPrefix(PUBLIC_)
: items with keys starting with are not sensitive, all others are
- accepts for conditional imports and for optional imports
Item decorators
Decorators in comment lines directly preceding a config item are attached to that item. A blank line breaks the association.
| Decorator | Purpose |
|---|
| / | Override default required state |
| / | Override default sensitive state |
| Set validation/coercion type |
| Example value (for docs, not used at runtime) |
| or | Link to related documentation (can be used multiple times) |
| Iconify icon ID for generated docs |
| Suppress "unused in code" warning from |
Decorator values can use resolver functions:
,
@sensitive=not(forEnv(dev))
.
Common data types ()
Plain
is the default — do not add
, just omit
entirely. Only use
when you need a specific type or string constraints. See
https://varlock.dev/reference/data-types/
Resolver functions (values)
Instead of static values, items can use resolver functions:
env
# Reference another item ($VAR and ${VAR} are shorthand for ref(VAR))
FULL_URL=${API_URL}/v2/users
# Execute a CLI command
SECRET=exec(`op read "op://vault/item/field"`)
# Conditional logic
API_URL=if(eq($APP_ENV, prod), https://api.example.com, http://localhost:3000)
# First non-empty value
FALLBACK_VAR=fallback($PRIMARY, $SECONDARY, "default")
# Map one value to another
APP_ENV=remap($CI_BRANCH, "main", production, /.*/, preview, undefined, development)
# Check environment (based on @currentEnv)
# @required=forEnv(prod, staging)
PROD_ONLY_KEY=
Key functions:
,
,
,
,
,
,
,
,
,
,
Setting sensitive values
There are two main approaches — they can be used together.
Approach 1: Plugins (version-controlled secret references)
Varlock plugins let you declaratively reference secrets from external providers directly in your
. The references are safe to commit — actual values are fetched at load time.
env
# @plugin(@varlock/1password-plugin)
# @initOp(token=$OP_TOKEN, allowAppAuth=forEnv(dev))
# ---
# @sensitive @type=opServiceAccountToken
OP_TOKEN=
# @sensitive
MY_SECRET=op(op://my-vault/item-name/field-name)
Each plugin provides its own resolver functions (e.g.,
for 1Password,
for AWS). See
Plugins below for the full list and
https://varlock.dev/guides/plugins/ for setup details.
Approach 2: Local encryption with (git-ignored files)
For secrets stored locally in git-ignored files like
, use the
function for device-local encryption so nothing is stored in plaintext:
env
# Encrypted value — decrypted automatically at load time
API_KEY=varlock("local:<encrypted-payload>")
# Prompt mode — on next `varlock load`, user is prompted to enter the value
# which is encrypted and written back to this file automatically
NEW_SECRET=varlock(prompt)
How to encrypt values:
- Interactive prompt: Set the value to and run — the user will be prompted securely, and the encrypted value replaces the placeholder automatically
- Encrypt in bulk:
varlock encrypt --file .env.local
encrypts all sensitive plaintext values in-place
- Encrypt a single value: prompts for a value and prints the encrypted result to copy/paste
- Pipe via stdin: To encrypt a value without exposing it in your context (e.g., a generated key or a value read from another tool), pipe it into :
bash
some-cli-that-outputs-secret | varlock encrypt
# prints: SOME_SENSITIVE_KEY=varlock("local:<encrypted>")
This keeps the plaintext secret out of shell history and agent context.
Encryption is hardware-backed on macOS (Secure Enclave + Touch ID), Windows (DPAPI + Windows Hello), and Linux (TPM2), with a file-based fallback on all platforms. On macOS,
is also available as a built-in alternative that stores values in the system keychain.
Organization
Ask the user how their repo is structured before designing the env layout.
Single project: one
at the repo root is usually enough.
Monorepo / multi-app: use
to share common config:
env
# Import shared config from root (directory form: also loads root .env / .env.local)
# @import(../../)
# Import from a sibling service (specific keys only)
# @import(../api/.env.schema, pick=[SHARED_API_URL, SHARED_DB_HOST])
# ---
APP_PUBLIC_URL=http://localhost:3000
- Root schema — shared service URLs, org-wide defaults, common keys
- Per-app schemas — app-specific items, importing what they need from root/siblings
- Keep imports explicit; avoid circular imports
Discuss with the user: which values belong at the root vs per-package, which environments they use.
Plugins
Plugins add resolver functions, data types, and decorators for external secret providers. Install with
in your
:
env
# @plugin(@varlock/1password-plugin)
In JS projects, also install the npm package. With the standalone binary, pin a version:
@plugin(@varlock/1password-plugin@1.2.3)
.
Available plugins: 1Password, AWS Secrets Manager, Azure Key Vault, Bitwarden, Dashlane, Doppler, Google Secret Manager, HashiCorp Vault, Infisical, Akeyless, KeePass, Keeper, Passbolt, Proton Pass, Pass, macOS Keychain (built-in).
See
https://varlock.dev/plugins/overview/ for setup details for each plugin.
Integrations (frameworks / runtimes)
Pick the official integration for the project's framework — do not guess. Check
https://varlock.dev/integrations/overview/ for the specific guide (Next.js, Vite, Astro, SvelteKit, Bun, Cloudflare, Expo, etc.).
Typical steps:
- Confirm is installed ( or existing dependency)
- Follow the integration guide for build/dev wiring, generated types, and any required config
- Prefer the integration's recommended entry point (, Vite plugin, etc.) over ad-hoc usage
When a framework integration is active, it handles loading and injecting env vars automatically —
is
not needed for the framework's own dev/build commands. Only use
for other scripts or tools that the integration doesn't cover (e.g., one-off migrations, CLI tools, non-JS commands).
Migrating from dotenv: replace
or
with the varlock equivalent — see
https://varlock.dev/guides/migrate-from-dotenv/
Non-JS apps/services: use
or pipe
varlock load --format shell
— see
https://varlock.dev/integrations/other-languages/
Setup
Installing varlock:
- JS projects: Install as a dev dependency — (or , )
- Standalone binary (non-JS or global use): See https://varlock.dev/getting-started/installation/
Getting started:
- Run to auto-generate an initial from existing / files
- Review the generated schema with the user — init heuristics are a draft, not final
- Optionally install this skill:
- skills (recommended):
npx skills add dmno-dev/varlock
— update with npx skills update varlock
- GitHub CLI (v2.90+):
gh skill install dmno-dev/varlock varlock
— update with
Schema checklist
After init or when editing
:
- Review auto-generated items — heuristics are not final
- Add description comments where names are not self-explanatory
- Set only when not a plain string (omit )
- Mark / as needed (or adjust root )
- Confirm on secrets, keys, tokens, and credentials with the user
- Move useful values to ; delete dummy placeholders
- Add links where helpful
- Remove redundant values from other files after defaults move into the schema
Validation loop
After schema changes:
Fix schema and tracked env files based on validation errors. Do not patch gitignored
value files to silence schema errors — ask the user to update secrets locally.
CLI quick reference
Run
or
for full flags and options.
| Command | Use when |
|---|
| Setting up varlock non-interactively |
| Validating config safely (JSON, sensitive values redacted) |
| Showing human-readable validation to the user |
| Injecting resolved env into a process |
varlock printenv VAR_NAME
| Print a single resolved env var to stdout |
| Securely view/copy a sensitive value |
| Encrypt values (single or for bulk) |
| Scan files for leaked secrets ( for pre-commit, to set up) |
| Detect drift between schema and code usage |
| Explicitly trigger code generation from schema (usually triggered automatically; is a deprecated alias) |
| Lock biometric session (requires re-auth on next decrypt) |
Updating an existing project
Keep
as the source of truth. Edit schema and tracked
files only — not gitignored
files.
- Schema changes — add/remove/rename items in , update code to match, then
- Secrets — leave sensitive values empty in schema; ask the user to set them locally or in their secret provider
- Plugins — add in the header and prefer plugin resolvers over raw when available
- Codegen — (and the other decorators) run on load by default; use and if you need explicit control
- Before commit — , then ; run if you renamed keys or suspect drift
See
Schema,
Secrets, and
Monorepos for deeper patterns.
Advanced
Docs
For details beyond this skill, use the Varlock Docs MCP tool if installed in your AI tool, or refer to
https://varlock.dev/guides/schema as a starting point.