Source: https://keypaste.com/developers/env/
Last updated: 2026-12-01

# keypaste env

Imports, exports and compares an environment’s variables, stage by stage.

## Synopsis

Terminal window

```
keypaste env ls     [<project>] [-p <stage>] [--profiles] [--json]keypaste env set    <project> <KEY[=value]> [-p <stage>] [--entry <item>] [--generate …]keypaste env rm     <project> <KEY> [-p <stage>] [--entry <item>] [--yes]keypaste env pull   <project> [<file>] [-p <stage>] [--entry <item>] [--yes] [--keep | --delete-source]keypaste env export [<project>] [<file>] [-p <stage>] [--dotenv] [--stdout] [--force] [--yes]keypaste env diff   [<project>] [<stage>] [<other>]keypaste env tag    <project> <item> [-p <stage>] [--yes]keypaste env untag  <project> <item> [-p <stage>] [--yes]
```

Every verb also takes `--vault <path>` and `--keyfile <path>` ([flags every command takes](https://keypaste.com/developers/cli/#flags-every-command-takes)).

`<project>` is the environment’s name; the argument keeps its earlier name. An environment’s variables are the custom fields of the items tagged `env:<project>`, for the `dev` stage, or `env:<project>:<stage>`. `set` and `pull` write on the stage’s home item, `env/<project>/.env` or `env/<project>/.env.<stage>`, created and tagged when missing, unless `--entry` names another. On those home items any name a shell can export is a variable, lower case included, such as `api_url`; on any other item tagged into the stage, such as a login, only fields named in capitals are, so its ordinary fields never join the stage.

## Options

| Option | Verbs | Effect |
| --- | --- | --- |
| `-p`, `--profile <stage>` | all but `diff` | The stage, `dev` by default; `export` in a folder the app saved uses that folder’s stage. |
| `--profiles` | `ls` | The environment’s stages only. |
| `--json` | `ls` | Machine-readable output. |
| `--entry <item>` | `set`, `rm`, `pull` | The item to write on, rather than the stage’s home item. |
| `--generate` | `set` | Generate the value. With `--length <N>` (20 by default), or `--words <N>` and `--separator <C>` (`.` by default), `--no-symbols` and `--no-lookalikes`. |
| `--keep` | `pull` | Keep the `.env` without asking. |
| `--delete-source` | `pull` | Delete the `.env` afterwards without asking. |
| `--dotenv` | `export` | Write the values in plain text as a `.env`, `./.env` by default, instead of `kp://` references. |
| `--stdout` | `export` | Print the values rather than write them. |
| `--force` | `export` | Replace a file that is there. It never overwrites a KeePass vault. |
| `--yes` | `rm`, `pull`, `export`, `tag`, `untag` | Go ahead without asking. Needed without a terminal. |

`export` and `diff` with no environment use the one the desktop app saved for this folder.

## Behaviour

- `set` asks for the value unless `KEY=value` gives it, so a value stays out of shell history.
- `pull` reads `./.env` unless you name a file, lists names and never values, and writes nothing if any line is malformed. Without `--keep` it then offers to delete the file.
- `export` prints `kp://` references, safe to commit ([kp:// references](https://keypaste.com/developers/references/)). With `--dotenv` it writes values in plain text, the one way keypaste puts them on disk unencrypted: on Linux and macOS only you can read the file; on Windows it takes its folder’s permissions.
- `diff` names a key one stage lacks or cannot release, and a value two stages share. It never prints a value.
- `prod`, `production` and their `-…` forms are [protected stages](https://keypaste.com/developers/policy/#protected-stages).

## How keypaste reads a `.env`

It differs from `motdotla/dotenv` in three ways:

- **Comments.** A `#` starts a comment only after a space, so `PASSWORD=hunter2#42` keeps `#42`.
- **Duplicate keys.** keypaste refuses them until you resolve them.
- **Escapes.** Inside double quotes, `\n`, `\r`, `\t`, `\\` and `\"` expand. For a literal Windows path, write `'C:\temp'` in single quotes.

Avoid `docker run --env-file` with an exported `.env`: it keeps quotes as literal text.

## What KeePassXC sees

Ordinary items: `env/<project>/.env`, tagged `env:<project>`, with a protected field per variable. You can edit them in KeePassXC without keypaste.

## Examples

Terminal window

```
keypaste env pull shop --keepkeypaste env set shop DATABASE_URL -p stagingkeypaste env set shop SESSION_SECRET --generate --length 40keypaste env ls shop --profileskeypaste env diff shop dev stagingkeypaste env export shop -p staging > .env.keypastekeypaste env export shop .env --dotenv
```

## Exit codes

| Code | Meaning |
| --- | --- |
| 0 | Success |
| 1 | Usage error |
| 2 | Internal or environment error |
| 3 | Vault, environment or item not found |
| 4 | Wrong master password |
