Skip to content

Load your environment in the terminal automatically

Have your terminal pick up an environment’s variables, the keys and settings your code reads such as DATABASE_URL, when you go into its folder, and drop them when you leave.

Before you start:

  • An environment in keypaste holding your variables, under Environments in the sidebar.
  • zsh, bash or fish on a Mac or Linux, or PowerShell on Windows.
  1. In Environments, choose your environment.
  2. Under its name, click Choose folder… and pick your code’s folder. If a folder is already shown, Change… picks another folder or stage.

The folder uses the dev stage unless you choose another.

  1. Open Settings › General. Under Shell hook, keypaste shows the line for your shell.
  2. If it says a terminal can’t run keypaste yet, link the keypaste command first, as it offers.
  3. Copy the line, paste it at the end of the file keypaste names, such as ~/.zshrc, and save the file. keypaste never edits it for you.
  4. Open a new terminal window.
  1. Keep keypaste open with your vault unlocked.
  2. In the terminal, go into the folder, such as cd ~/code/shop.
  3. The first time in each terminal window, keypaste asks, naming the environment, the stage, the variables and the folder. Click Allow in this terminal.

Everything you start in that terminal now gets the variables, and leaving the folder removes them. The terminal loads them again without asking each time it comes back, until keypaste locks or quits, which removes them too.

To use another stage in this terminal, type keypaste stage staging.

  • Nothing loads. Check that keypaste is unlocked and that you opened a new terminal after adding the line.
  • You clicked Deny. That terminal doesn’t ask again until it leaves the folder. Go out and back in.
  • prod doesn’t load. A protected stage never loads on its own. Run one command with it instead: keypaste run -p prod -- npm start.
  • An AI tool started there doesn’t get the variables. That’s on purpose: keypaste holds them back from claude, codex, cursor-agent and aider started in that terminal.