Loading...
Loading...
MUST USE for any task involving the dotenvx CLI tool — encrypting .env files, running commands with injected env vars, managing secrets across environments, and decrypting at runtime. Use this skill whenever the user mentions dotenvx, dotenv encryption, DOTENV_PRIVATE_KEY, encrypted .env files, or the dotenvx encrypt/run/set/get/decrypt/keypair commands. Also trigger when the user wants to: commit .env files safely to git, stop sharing secrets over Slack/chat, encrypt environment variables with public-key cryptography, set up multi-environment .env configs (production/staging/ci), manage secrets in a monorepo with -fk flag, migrate from python-dotenv or plain dotenv to encrypted envs, inject env vars into any process across any language (Node, Python, Ruby, Go, Rust, etc.), or configure CI/CD pipelines (GitHub Actions, Docker) with encrypted env files. This skill contains the authoritative CLI reference — without it, responses will hallucinate non-existent commands and flags.
npx skill4agent add narasaka/skills dotenvxdotenvrundotenvx rundotenvx encrypt.envdotenvx setgetdotenvx decrypt.env-fDOTENV_PRIVATE_KEY_*# npm (local to project)
npm install @dotenvx/dotenvx --save
# global installs
curl -sfS https://dotenvx.sh | sh # curl
brew install dotenvx/brew/dotenvx # brew
winget install dotenvx # windows
docker run -it --rm -v $(pwd):/app dotenv/dotenvx help # dockerrequire('@dotenvx/dotenvx').config()
// or: import '@dotenvx/dotenvx/config'dotenvx run.envdotenvx run -- <command>| Flag | Description |
|---|---|
| Specify env file(s). Repeatable. Default: |
| Set inline env var |
| Later files/values override earlier ones (default: first wins) |
| Exit code 1 on any error (missing file, decrypt failure) |
| Ignore specific errors (e.g., |
| Load files using Next.js or dotenv-flow convention |
| Specify path to |
| Suppress all output except errors |
| Verbose logging |
| Debug-level logging |
| Set log level: |
# Basic usage
dotenvx run -- node index.js
# Specific env file
dotenvx run -f .env.production -- node index.js
# Multiple env files (first file's values win by default)
dotenvx run -f .env.local -f .env -- node index.js
# Override: last file wins
dotenvx run -f .env.local -f .env --overload -- node index.js
# Inline env var (overrides file values)
dotenvx run --env HELLO=String -f .env -- node index.js
# Any language works
dotenvx run -- python3 app.py
dotenvx run -- ruby index.rb
dotenvx run -- go run main.go
dotenvx run -- cargo run
dotenvx run -- php artisan serve
dotenvx run -- next dev
# Shell expansion (use subshell to prevent premature expansion)
dotenvx run --env="HELLO=World" -- sh -c 'echo Hello $HELLO'
# Strict mode for CI
dotenvx run -f .env.ci --strict -- node build.js.env-f--overload--env${VAR}.env# Variable expansion
USERNAME="admin"
DATABASE_URL="postgres://${USERNAME}@localhost/mydb"
# Default values (use fallback if unset/empty)
DB_HOST=${DB_HOST:-localhost}
DB_PORT=${DB_PORT:-5432}
# Alternate values (use alternate if variable IS set)
DEBUG_MODE=${NODE_ENV:+false}
# Command substitution
WHOAMI="$(whoami)"CERT="-----BEGIN CERTIFICATE-----
MIIB...
-----END CERTIFICATE-----"dotenvx keysdotenvx keypairdotenvx statusdotenvx rotatedotenvx set--env-name.env.vaultDOTENVX_PRIVATE_KEYDOTENV_PRIVATE_KEYpip install dotenvxdotenvx.load_dotenv()dotenvx run -- python app.pydotenvx encrypt.envDOTENV_PUBLIC_KEY.envDOTENV_PRIVATE_KEY.env.keysdotenvx encrypt # encrypts .env
dotenvx encrypt -f .env.production # encrypts specific file
dotenvx encrypt --stdout # output to stdout instead of in-place.envDOTENV_PUBLIC_KEY.env.keysDOTENV_PRIVATE_KEY.envdotenvx decrypt.envdotenvx decrypt # decrypts .env
dotenvx decrypt -f .env.production # decrypts specific file
dotenvx decrypt --stdout # output to stdout.env.keysDOTENV_PRIVATE_KEY*dotenvx set.envdotenvx set KEY value # set in .env
dotenvx set KEY value -f .env.production # set in specific file
dotenvx set KEY "multi word value" # quoted values
dotenvx set KEY value -fk .env.keys -f apps/app1/.env # monorepodotenvx getdotenvx get HELLO # from .env
dotenvx get HELLO -f .env.production # from specific file
dotenvx get HELLO --env HELLO=Override # from --env string
dotenvx get HELLO --overload # with overload semantics
dotenvx get HELLO --strict # exit 1 if key missing
dotenvx get HELLO --convention=nextjs # with convention
dotenvx get HELLO -fk .env.keys -f app/.env # monorepodotenvx get # all vars from .env as JSON
dotenvx get -f .env.production # all vars from specific file
dotenvx get --all # include DOTENV_PUBLIC_KEY
dotenvx get --format shell # output as KEY=value linesdotenvx keypair.envdotenvx keypair # all keypairs as JSON
dotenvx keypair DOTENV_PRIVATE_KEY # just the private key
dotenvx keypair -f .env.production # for specific file
dotenvx keypair DOTENV_PRIVATE_KEY_PRODUCTION -f .env.production# 1. Create your .env
echo "DATABASE_URL=postgres://localhost/mydb" > .env
echo "API_KEY=sk-secret123" >> .env
# 2. Encrypt it
dotenvx encrypt
# ✔ encrypted (.env)
# Creates .env.keys with your private key
# 3. Commit .env (encrypted, safe), do NOT commit .env.keys
echo ".env.keys" >> .gitignore
git add .env .gitignore
git commit -m "add encrypted env"# Encrypt each environment
dotenvx encrypt -f .env.production
dotenvx encrypt -f .env.staging
dotenvx encrypt -f .env.ci
# Each creates a corresponding private key in .env.keys:
# DOTENV_PRIVATE_KEY_PRODUCTION="..."
# DOTENV_PRIVATE_KEY_STAGING="..."
# DOTENV_PRIVATE_KEY_CI="..."DOTENV_PRIVATE_KEY_*dotenvx run# The private key suffix matches the file suffix
DOTENV_PRIVATE_KEY="key" dotenvx run -- node app.js # decrypts .env
DOTENV_PRIVATE_KEY_PRODUCTION="key" dotenvx run -- node app.js # decrypts .env.production
DOTENV_PRIVATE_KEY_CI="key" dotenvx run -- node app.js # decrypts .env.ci
# Combine multiple
DOTENV_PRIVATE_KEY="k1" DOTENV_PRIVATE_KEY_PRODUCTION="k2" dotenvx run -- node app.js
# Comma-separated keys for monorepos (same environment, different apps)
DOTENV_PRIVATE_KEY_CI="key1,key2" dotenvx run -f app1/.env.ci -f app2/.env.ci -- node app.js# GitHub Actions example
name: deploy
on: [push]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: curl -fsS https://dotenvx.sh/install.sh | sh
- run: dotenvx run -- node build.js
env:
DOTENV_PRIVATE_KEY_PRODUCTION: ${{ secrets.DOTENV_PRIVATE_KEY_PRODUCTION }}--convention=nextjs.env.$(NODE_ENV).local.env.local.env.$(NODE_ENV).envdotenvx run --convention=nextjs -- next dev--convention=flowDOTENV_ENVNODE_ENVDOTENV_ENV=development dotenvx run --convention=flow -- node app.js-fk.env.keys# Set values for different apps
dotenvx set HELLO app1 -fk .env.keys -f apps/app1/.env
dotenvx set HELLO app2 -fk .env.keys -f apps/app2/.env
# Run with shared keys
dotenvx run -fk .env.keys -f apps/app1/.env -- node apps/app1/index.js
# Get values
dotenvx get HELLO -fk .env.keys -f apps/app1/.envFROM node:latest
RUN curl -fsS https://dotenvx.sh/install.sh | sh
COPY . .
CMD ["dotenvx", "run", "--", "node", "index.js"]docker run -it --rm -v $(pwd):/app dotenv/dotenvx run -- node index.jsdotenvx set NEW_SECRET "value" -f .env.production
# Automatically re-encryptsdotenvx set API_KEY "new-key-value" -f .env.productiondotenvx get -f .env.production # needs private key available
dotenvx get API_KEY -f .env.production # single valuedotenvx encrypt -f .env.production
# Done. Commit the encrypted .env.production, store .env.keys privately.dotenvx run --quiet -- ./my-script.shdotenvx run -f .env.ci --strict -- npm test# Never commit private keys
.env.keys
# Encrypted .env files ARE safe to commit
# !.env
# !.env.production
# !.env.stagingMISSING_ENV_FILE.env--ignore=MISSING_ENV_FILEMISSING_KEY.envDOTENV_PRIVATE_KEY_*_PRODUCTION.env.productiondeno run npm:@dotenvx/dotenvx encrypt$VARSdotenvx run -- sh -c 'echo $MY_VAR'dotenvx extdotenvx ext genexample # generate .env.example from .env
dotenvx ext genexample -f .env.production # from specific file
dotenvx ext gitignore # append .env.keys to .gitignore
dotenvx ext ls # list all .env files in project
dotenvx ext ls -f .env.production # check specific file
dotenvx ext settings # view current dotenvx settings