Use your vault's env in a project
Your project’s variables move from .env into the vault. The repository keeps only references, and keypaste run fills them in when your program starts.
Prerequisites
Section titled “Prerequisites”- The
keypastecommand and a vault chosen withkeypaste use(Give an AI agent its first key makes one). - A project with a
.env.
1. Import the .env
Section titled “1. Import the .env”From the project’s folder:
keypaste env pull shopMaster password:shop/dev: 3 new, 0 updated, 0 unchanged new DATABASE_URL, PORT, STRIPE_KEY on env/shop/.envenv/shop/.env will be created and tagged into shop/dev.Import 3 variables into shop/dev? [y/N] yImported 3 variables into shop/dev.Deleting removes the file from the directory. It does not overwrite the blocks itused: on an SSD, on a copy-on-write filesystem, or on any volume with snapshots orbackups, the old contents can outlive the file. If these values may have leaked, rotate them.Delete '/repo/shop/.env'? [y/N] yshop names the environment, the vault’s set of this project’s variables, and dev is its stage. keypaste lists names, never values, and writes nothing if a line is malformed. Deleting doesn’t remove the file from git history either: if git log -- .env prints anything, treat those values as leaked.
2. Write the reference file
Section titled “2. Write the reference file”keypaste env export shop > .env.keypastecat .env.keypaste ✓ wrote 3 references · 0 values · safe to commit# keypaste references: safe to commit, no value is stored here.# `keypaste run --env-file .env.keypaste -- <command>` resolves them.DATABASE_URL=kp://shop/dev/DATABASE_URLPORT=kp://shop/dev/PORTSTRIPE_KEY=kp://shop/dev/STRIPE_KEYCommit .env.keypaste, and keep .env in .gitignore.
3. Run
Section titled “3. Run”keypaste run --env-file .env.keypaste -- npm startkeypaste run: resolving .env.keypaste → environment shop stage devEverything after -- is your command. It gets the variables in its environment, and no file holds them. While the desktop app or keypaste approve holds the vault, it asks there instead of for your master password, every time.
4. Add a variable
Section titled “4. Add a variable”keypaste env set shop SENTRY_DSNValue for SENTRY_DSN:Set SENTRY_DSN on env/shop/.envIt asks for the value, so it stays out of your shell history. Export the reference file again to add it there.
In the app, the stage’s last row adds one: a Name and a Value. The Name turns into capitals as you type, so sentry dsn becomes SENTRY_DSN. In the app, a lower-case name such as api_url comes in by pasting NAME=value lines or importing a .env.
From the desktop app
Section titled “From the desktop app”Environments does steps 1 and 2 in one. Its + › Import .env… brings a .env from any folder into a new environment, and an environment’s ⋯ › Import .env… into that one, with a Stage menu. Then Import and keep the file saves the values and leaves the file as it is, or Import and convert to references saves them, writes .env.keypaste, adds .env to .gitignore and removes .env if it hasn’t changed since keypaste read it (desktop guide).
Load them in every terminal
Section titled “Load them in every terminal”Instead of keypaste run for each command, the shell hook loads the stage into your terminal when you cd into the folder and unloads it when you leave. Choose the environment’s folder in the app, add the line keypaste hook zsh (or bash, fish, pwsh) prints to your shell’s startup file, and allow each terminal once (keypaste hook).
Next steps
Section titled “Next steps”- Run in CI
- keypaste hook: every shell, what it never loads, and switching stages
- keypaste env: stages, comparing them, exporting a plain
.env, and how keypaste reads one - keypaste run and kp:// references