Skip to content

keypaste hook

keypaste hook puts an environment’s variables into your terminal when you cd into its folder, and takes them out when you leave or keypaste locks. It is keypaste’s answer to direnv, with the values coming from your vault instead of a file.

Print the line for your shell and add it to the file it names. keypaste never edits that file.

Terminal window
keypaste hook zsh
ShellLineFile
zsheval "$(keypaste hook init zsh)"~/.zshrc
bash, Git Bash tooeval "$(keypaste hook init bash)"~/.bashrc
fishkeypaste hook init fish | source~/.config/fish/config.fish
PowerShell 5.1 and 7keypaste hook init pwsh | Out-String | Invoke-Expression$PROFILE

Open a new terminal. The line runs keypaste hook init, which prints the hook with the absolute path of that keypaste in it, so a later change to PATH can’t swap what the hook runs. cmd.exe has no hook. To remove the hook, delete the line.

The hook runs at each prompt. It acts only in a folder projects.json maps to an environment, which you set in the app’s Environments screen with the folder line under the environment’s name, and only while the app or keypaste approve holds the vault unlocked.

  • Entering the folder or a folder inside it loads the folder’s stage, dev unless you chose another. The first time in each terminal, keypaste asks you in its window: Deny, or Allow in this terminal. While it waits, the terminal shows allow in the keypaste window, Ctrl+C to skip, for up to 45 seconds.
  • After you allow, that terminal reloads the stage without asking each time it comes back to the folder, until keypaste locks.
  • Deny, Ctrl+C or no answer loads nothing, and that terminal doesn’t ask again until it leaves the folder.
  • Another question open in keypaste, or a refusal of the same load a moment ago, loads nothing yet, and the terminal asks again at a later prompt.
  • Leaving the folder unloads the variables and puts back any value a name had before.
  • Locking keypaste, or quitting it, unloads them at the terminal’s next prompt. While it is locked, the hook loads nothing and says so in one dim line.
  • A protected stage such as prod never loads into a terminal. Use keypaste run -p prod -- <command> for one command.
  • A folder saved without autoload loads only a stage you choose with keypaste stage.

Every load is recorded in the audit log, as prompt when you were asked and shell-grant when it reloaded under your allow. The hook itself never opens the vault or asks for the master password.

Terminal window
keypaste stage staging

This asks for that stage in this terminal, as entering the folder asks for the folder’s own, and unloads the stage loaded before. The folder’s saved stage doesn’t change; the app’s folder line sets it for new terminals. The choice lasts until the terminal leaves the folder.

Just before you start claude, codex, cursor-agent or aider from a terminal with variables loaded, zsh, bash and fish stop exporting them, so the tool doesn’t inherit them, and export them again at the next prompt. To change the list, set KEYPASTE_HOOK_STRIP before the hook’s line, such as KEYPASTE_HOOK_STRIP='claude codex my-agent'. Set it to empty to turn this off.

It reads the command as you typed it, so a tool started any other way, through a script, npx, an alias of a different name or another program, still inherits the values. bash keeps an existing DEBUG trap, and then nothing is stripped. PowerShell has no hook before a command starts, so it never strips.

The hook loads nothing into a terminal an AI agent runs: it refuses when CLAUDECODE or CODEX_SANDBOX is set, or when the terminal isn’t interactive.

A variable that changes how the shell runs or finds programs is never loaded, and the terminal names it: PATH, PROMPT_COMMAND, PS0 to PS4, PROMPT, RPROMPT, IFS, BASH_ENV, ENV, ZDOTDIR, HOME, SHELL, NODE_OPTIONS, PSModulePath, and every name starting LD_, DYLD_, fish_ or KEYPASTE_, in any case. keypaste run passes such a name to one command. A value holding a NUL character isn’t loaded either.

The values go only into the shell’s memory. The hook writes no file and uses no here-document, which some shells write to a temporary file. It turns tracing off while it runs, so set -x shows no value, and nothing it does enters your history. PowerShell reads keypaste’s answer as data and sets each variable with [Environment]::SetEnvironmentVariable; nothing in a value is run.

  • Everything the terminal starts inherits the values, as it would from a .env loaded by direnv. A program started from the terminal keeps them after you leave or lock.
  • A shell started inside a loaded terminal inherits the values and doesn’t unload them.
  • Any program running as you can read a process’s environment or type into your terminal (THREATS).
  • The hook follows the vault keypaste uses, from KEYPASTE_VAULT or keypaste use, and the folder with links resolved, so a folder saved through a link, such as macOS’s /tmp, matches either way.
  • The hook runs keypaste at each prompt, which takes a few milliseconds.