Skip to content

keypaste run

keypaste run <project> -- <command> starts a command with an environment’s variables from your vault. keypaste reads the variables, closes the vault, then starts the command with them laid over your own environment. It writes no .env file, and once the command starts, its exit code is keypaste’s.

Use your vault’s env in a project and Run in CI walk through it.

Terminal window
keypaste run [<project>] [options] -- <command> [args...]
Terminal window
keypaste run dev -- npm start
keypaste run -p staging acme-api -- ./deploy.sh

<project> names an environment in the vault: the items tagged env:<project>, or env:<project>:<stage> for one stage, whose custom fields are the variables. With none, keypaste uses the environment the desktop app saved for this folder (in projects.json), in the stage set for that folder, and the folder’s .env.keypaste only when it names nothing but that environment’s variables.

The desktop app starts no program itself: its Copy ▾ › Copy run command gives you this command for a terminal. To load a stage into the terminal itself, use keypaste hook.

OptionEffect
--vault <path>Which vault to use. Or set KEYPASTE_VAULT.
-p <stage>, --profile <stage>The stage. By default the one the app set for this folder, else dev.
--project <name>The environment, even one whose name starts with -.
--env-file <file>Run with the variables a file of kp:// references names, such as .env.keypaste, instead of an environment. Every reference resolves, or nothing starts.
--keyfile <path>The vault’s key file. Or set KEYPASTE_KEYFILE.
--sessionOnly ask the desktop app or keypaste approve holding the vault, and never open it here.
--no-sessionOpen the vault here with its master password, even while the app or keypaste approve holds it.
--approver <name>Which approver to ask, when you run more than one.
--token <token|-|env>Release what a scoped token’s scope covers, through the process holding the vault. - reads the token from standard input, env from KEYPASTE_TOKEN.
--bundle <file>Open a token bundle, which needs no vault.

The -- is required. Without it, keypaste run dev npm start cannot be told apart from an environment called npm. Only the first -- is keypaste’s: everything after it belongs to the command, including flags keypaste also understands, so keypaste run dev -- mytool --vault x gives mytool its own --vault.

With nothing holding the vault, keypaste run asks for the master password, reads the variables and closes the vault before the command starts, so a long-running server does not keep the vault unlocked. With its standard input piped, it reads exactly one line there as the master password and leaves the rest to the command.

While the desktop app or keypaste approve holds the vault unlocked, keypaste run from a terminal asks that process instead, and you type no password. The prompt names the environment, the variable names, the command and the directory, never a value, and the run is logged. It is asked every time, and a refusal starts nothing. With its standard input piped, it still opens the vault itself.

The command inherits your environment with the stage’s variables laid over it, and keypaste’s standard input, output and error, so terminal prompts and output work as usual.

A variable named PATH is passed to the command, but the command itself is still found through your own PATH, and keypaste warns. An invalid variable name, or two names that differ only in case, stops the run before anything starts, and the error lists every such name.

keypaste writes no file holding the values; CI checks that a run leaves the temporary folders empty. The values are in the command’s environment, so the command, its child processes, crash reporters and logs can read, print or write them, and anything running as you can inspect a process’s environment. Locking the vault does not take them back.

CodeMeaning
The command’s ownThe command started; its exit code is passed through
127No such command
126The command is not executable
1Usage error, such as a missing -- or no command after it
2Internal or environment error, such as an invalid variable name
3The vault, or the environment in it, was not found
4Wrong master password

keypaste’s own failures print a line beginning keypaste run:.

Ctrl+C, docker stop and timeout reach the command, and keypaste waits for it to exit and returns its status. On Linux and macOS, when keypaste’s standard input is a terminal, the terminal already sends Ctrl+C to the command, so keypaste does not send it a second time. When standard input is not a terminal, as in CI, under systemd or as a container’s first process, keypaste forwards SIGINT, SIGQUIT and SIGHUP itself. It always forwards SIGTERM. It never escalates to a hard kill, so a command that ignores termination keeps keypaste waiting. On Windows, closing the console can end keypaste while the command keeps running.