pamenv-cli
- npm: pamenv-cli · @pamenv/next · @pamenv/vite
pamenv uses and manages PAM multi-environment variables:
- For day-to-day development,
pamenv runinjects variables straight into a command's process, so no plaintext file stays on disk. - For Next / Vite you can also use
@pamenv/nextor@pamenv/viteto inject at config time (see "Framework plugins") without wrappingpamenv run. - When you need a file,
pamenv renderoutputs dotenv / JSON / YAML / TOML, andpull/pushsync with.env.<environment>files. - Sensitive values only reach a process through
run/ framework plugins; the web UI,renderandpullnever return them in plaintext (see "Marking sensitive variables"). initcreates a project from the current directory.
Install
npm install -g pamenv-cli
# or run once
npx pamenv --help
Package: https://www.npmjs.com/package/pamenv-cli
Quick start
pamenv login # browser sign-in (default https://pam.qlover.top)
cd your-project
pamenv init # create a project interactively (defaults from the cwd)
pamenv push <slug> -e local # upload .env.local
pamenv run <slug> -e local -- pnpm dev # start with variables injected, no files written
pamenv pull <slug> -e staging # download into .env.staging (export permission)
Commands
| Command | Description |
|---|---|
pamenv login | Sign in through the browser |
pamenv logout | Sign out and revoke the current CLI credential |
pamenv projects | List projects (aligned table: slug / name / role / envs; -v adds id) |
pamenv init | Create a project interactively |
pamenv fork <slug|id> | Fork a readable project into your own private project |
pamenv run <slug|id> -- <command> | Run a command with variables injected into its process; no files written |
pamenv render <slug|id> | Output variables as dotenv / json / yaml / toml |
pamenv pull <slug|id> | Write remote variables into a local file |
pamenv push <slug|id> | Push variables from a local file to PAM |
pamenv remove <slug|id> -e <env> | Delete a remote environment |
pamenv config set|list | View or change CLI settings |
<slug|id> accepts either the project slug or the project id.
Global options
| Option | Description |
|---|---|
--url <url> | Override PAM origin (default https://pam.qlover.top; login no longer prompts) |
--domain <host> | Same as --url but accepts a bare host; localhost and private addresses default to http, others to https |
--local | Force cwd .pam/; auto mode walks up to a monorepo-root .pam/ |
-g, --global | Force ~/.pam even when cwd or an ancestor has .pam/ |
Do not pass --url and --domain together, or --local and --global together. Add .pam/ to .gitignore.
Monorepo: run pamenv login --local once at the repo root (creates root .pam/); nested dirs (e.g. apps/pam) walk up to that .pam and need no second login. A nested dir can still pamenv login --local for its own .pam/; the nearest .pam wins and stays isolated from the root. Explicit --local always means cwd only. Walk-up is capped at 32 parent hops and stops at .git (never picks a .pam outside the work tree).
Login location (TBD): default global ~/.pam vs default local / monorepo — undecided. Today: global when no .pam is found; nearest ancestor .pam when present.
pamenv login # default pam.qlover.top
pamenv --domain pam.localhost:3400 login # override origin via flag only
pamenv --local --domain pam.localhost:3400 login # first write to cwd/.pam
pamenv projects # local identity when .pam/ exists (incl. ancestors)
pamenv -g projects # force global sign-in
pamenv projects
Lists projects visible to the current identity. Uses the same GET /api/pam/search as the web home list; CLI prints an aligned table (slug / name / role / envs; -v adds id) plus a page footer (page / count / total / next-page hint) — not web card fields like description, category, or timestamps.
Role column: owner · admin · member · member, writable · readonly.
pamenv projects
pamenv projects -v # include id column
pamenv projects fe
pamenv projects --visibility private
pamenv projects --category frontend --sort updated_at --order desc
pamenv projects --mine
pamenv projects --writable
pamenv projects --page 2
pamenv projects fe --writable --page 1 --page-size 20
| Option | Wire param | Description |
|---|---|---|
[keyword] | keyword | Optional search keyword (slug / name; compact view skips card text fields) |
--category <name> | filters.category | Filter by category (same as Web) |
--visibility <public|private> | filters.visibility | Visibility; omit for the default “all visible” scope (public + owned / team) |
--sort <created_at|updated_at> | sort | Sort field (server still sorts is_public first) |
--order <asc|desc> | sort | Sort direction, default desc |
--page <n> | page | 1-based page, default 1; pass --page for more |
--page-size <n> | pageSize | Page size, default 10 (same as Web), max 100 |
--mine | filters.mine | Server-side: strict project owner (owner_id = me) |
--writable | filters.writable | Server-side: owner or active team member; with --mine → intersection |
-v, --verbose | — | Show the project id column |
| (fixed) | view=compact | CLI compact payload (slug/name/role/envs; -v includes id); web cards use full (default) |
Also accepts global options: --url / --domain / --local / -g.
--mine/--writableare applied in SQL before pagination (correct totals — not post-filter).- Pagination follows
--page/--page-sizeexactly (same as Web).
Testing
# Default: unit + mock contract integration (no PAM account)
pnpm --filter pamenv-cli test
# Optional: live PAM (dedicated harness project + tokens; never commit secrets)
PAMENV_LIVE=1 \
PAMENV_BASE_URL=https://pam.example.com \
PAMENV_OWNER_TOKEN=... \
PAMENV_MEMBER_TOKEN=... \
PAMENV_PROJECT_SLUG=ci-pamenv-harness \
PAMENV_ENV_NAME=dev \
PAMENV_PROTECTED_ENV_NAME=secret \
pnpm --filter pamenv-cli test:live
Contract tests (~78) use an in-memory mock PAM covering identity / exact slug / -o, pull (403/401/leaks/multi-env/--file), bindings + --force TTY, run (403/protected/404 fallback/slug mismatch/keepEnv/warnings), pull/push three-way sync and conflicts, render (yaml/toml/--only), remove (clears snapshot), and over-permissive files.
Security model
- Identity isolation: walk up from cwd to the nearest
.pam/and use only that local identity — never fall back to~/.pam. Missing token fails immediately. Use-gfor the home root. - Exact project:
pull/push/run/render/remove/forkaccept an exact slug or uuid only (no substring match likepam→pamenv-…). - Fail-closed permissions: trust server
permissions[]; on missing permission or 401/403 there is no disk write and no injection. CLI checks are not a substitute for server auth. - pull ≠ run:
pull/renderneedpam_environments_export(admin+); sensitive values are placeholders.runneedspam_environments_inject(member+); plaintext stays in the child process only. - Protected envs: with
is_protected=true, both resolve and variable writes require export-tier permission — members cannotrun,push, or edit that environment in the web UI. - On disk: refuses to overwrite files readable by group/others; writes are atomic +
0600. On Windows, the current user is granted access and Everyone / Users entries are removed (best-effort).--forcerebind requires interactive confirmation (non-TTY is refused).
Environments and local files
-e <env>selects the environment:-e localmaps to.env.local,-e stagingto.env.staging.- Without
-e, the project's first environment is used (removealways requires-e). --file <path>uses another file, relative to the current directory (or-o), or an absolute path.- Multiple projects in one cwd: the default filename is only the env name. After
pull fe-base -e dev(owns.env.dev),pull pam -e devis refused — use--file .env.pam.dev, another directory, or--forcein a TTY with confirmation.
pamenv pull <slug> -e local --file .env # write .env instead of .env.local
pamenv push <slug> -e local --file .env # read .env and push to local
pamenv pull pam -e dev --file .env.pam.dev
pamenv init
Run it in your project directory after signing in, similar to npm init: the CLI scans the directory for defaults and only creates the project after you confirm.
pamenv init
pamenv init -o ./packages/app # use another working directory
Defaults
| Field | Default | Otherwise |
|---|---|---|
| name | package.json name, else the git origin repo name | typed by you |
| slug | derived from the confirmed name (lowercase, @scope/foo → scope-foo) | typed by you |
| description | package.json description | may be empty |
| category | — | choose backend or frontend (default backend) |
| repository url | git origin (normalized to https when possible) | may be empty |
| environments | see below | may create none |
Environment detection
- Scans
.env,.env.localand.env.<xxx>in the directory (not recursive). .envand.env.localmerge into environmentlocal;.env.xxxbecomes environmentxxx.- When env files exist, pick the environments to create and confirm each name and URL. The URL defaults to
package.jsonhomepage; otherwise enter a valid http/https URL. - With no env files, no environments are created.
initonly creates the project and empty environments. It does not upload variables. Afterwards run:
pamenv push <slug> -e local
Slug rules
- Slugs are unique among non-deleted projects; a deleted project's slug can be reused.
- If the slug exists and belongs to you, the CLI tells you to
pushinstead. - If someone else owns it, choose another slug and run
initagain.
pamenv fork
Copies a project you can read (yours or public) into a private project. Structure and non-sensitive values are copied; sensitive values are cleared.
pamenv fork <slug|id>
pamenv fork <slug|id> --slug my-app-fork --name "My App (fork)"
pamenv fork <slug|id> -y # accept the default slug / name without prompts
Then fill in secrets with pamenv push <new-slug> -e <env>.
pamenv run
Runs a command with environment variables injected into its process. Values only live in the memory of pamenv and the child process: nothing is written to disk and the CLI never prints values.
Plaintext boundary: Sensitive values are real plaintext in the child process environment. The CLI guarantees no disk writes and no printing; it cannot stop the launched app from logging secrets, another local process from reading that process's env, or a debugger attach. Do not print secrets in your app; prefer --only to narrow the injection surface in production-like runs.
pamenv run <slug|id> -e local -- pnpm dev
pamenv run <slug|id> -e local --only DATABASE_URL,API_KEY -- node server.js
pamenv run <slug|id> -e local --keep-env PORT -- pnpm dev
| Option | Description |
|---|---|
-e, --env <name> | Environment name (default: first) |
--only <keys> | Only inject these keys (comma-separated) |
--keep-env <keys> | Keep the shell's value for these keys when already set |
--no-warn | Disable the pre-run checks |
--env-priority <remote|local> | Overlap priority: remote (default, PAM wins) | local (process → on-disk .env* → PAM, for temporary local overrides) |
--client-public-prefixes <list> | Prefixes for the sensitive client-bundle warning (comma-separated; built-in default); pass empty to disable |
- Everything after
--goes to the child unchanged, including the child's own options. - PAM wins for keys that also exist in the shell (except
--keep-envkeys). - Signals such as
Ctrl+Care forwarded to the child, and pamenv exits with the child's exit code. - Put it in
package.jsonso teammates need no.envfile:
{
"scripts": {
"dev": "pamenv run my-app -e local -- next dev"
}
}
With the framework plugins below, dev can stay plain next dev / vite.
Before starting, pamenv checks for the following and warns on stderr (it never blocks):
| Check | Why |
|---|---|
A .env* file in the cwd defines the same key | If dotenv loads it with override, the file value wins over the injected one |
A sensitive key starts with NEXT_PUBLIC_ / VITE_ | It gets bundled into client code at build time |
turbo.json uses strict env mode and the key is not declared | Turbo filters undeclared variables |
If an environment is marked protected in the web UI, only project admins / owners can run it or change its variables (including push).
Framework plugins (@pamenv/next / @pamenv/vite)
These call injectPamenvProcessEnv while the framework loads config, writing PAM into the current Node process.env so scripts need not wrap pamenv run … --.
@pamenv/next | @pamenv/vite | |
|---|---|---|
| Install | pnpm add @pamenv/next pamenv-cli | pnpm add @pamenv/vite pamenv-cli |
| Wire-up | wrap next.config with createPamenvPlugin | plugins: [pamenv({ … })] |
| Default inject | next dev only | vite / vite dev (serve) only |
| Credentials | nearest project .pam walking up; else ~/.pam (same as CLI auto) | same |
First-time login at the repo / project root (monorepo: once at root):
pamenv login --local
Next.js
// next.config.ts
import { createPamenvPlugin } from '@pamenv/next';
const withPamenv = createPamenvPlugin({
slug: 'my-app',
env: process.env.PAM_ENV,
keepEnv: ['PAM_ENV', 'VERCEL', 'VERCEL_ENV', 'NODE_ENV'],
// envPriority: 'local', // when overriding via .env / process
debug: true,
enabled: true
});
export default withPamenv(nextConfig);
{ "scripts": { "dev": "next dev" } }
Vite
// vite.config.ts
import { defineConfig } from 'vite';
import pamenv from '@pamenv/vite';
export default defineConfig({
plugins: [
pamenv({
slug: 'my-app',
env: 'local',
debug: process.env.PAMENV_DEBUG === '1',
clientPublicPrefixes: ['VITE_'] // do not put secrets on VITE_; [] disables
})
]
});
Client-readable keys still need Vite’s public prefix (VITE_* → import.meta.env.VITE_*). Example app: apps/pamenv-vite-app.
Common options
| Option | Description |
|---|---|
slug / env | Same as pamenv run <slug> -e <env> |
keepEnv | Keep process values for these keys when already set |
envPriority | remote (default) | local (process → .env* → PAM) |
debug | Metadata on stderr (paths / key names); never values |
enabled | Master switch: false off; omit / true allows inject (timing is internal; Vite may still use a command predicate) |
clientPublicPrefixes | Sensitive + public-prefix warning (e.g. ['VITE_']); [] disables |
preferLocal | When omitted, same as CLI auto (project .pam if present, else ~/.pam); false when OIDC is active; never put a token in the plugin options |
See packages/pamenv-next/README.md, packages/pamenv-vite/README.md, and docs/pamenv-v2.md.
pamenv render
Outputs variables in the chosen format, to stdout by default; requires export permission (project admin / owner). Sensitive values are output as this environment's placeholder (__PAM_SENSITIVE_…__) and their key names are listed on stderr; real values only reach a process via pamenv run.
pamenv render <slug|id> -e dev # dotenv to stdout
pamenv render <slug|id> -e dev --format json
pamenv render <slug|id> -e dev --format toml --out config.toml
pamenv render <slug|id> -e dev --out .env.local --only API_URL,API_KEY
| Option | Description |
|---|---|
--format <format> | dotenv (default; keeps comments), json, yaml, toml; the last three are flat key/values with double-quoted, escaped values |
--out <file> | Write to a file (mode 0600); omit or use - for stdout |
--only <keys> | Only output these keys |
pamenv pull / pamenv push
pamenv pull <slug|id> -e staging
pamenv pull <slug|id> -e staging -f # conflicting keys take remote values without asking
pamenv push <slug|id> -e staging
pamenv push <slug|id> -e staging -y # skip ordinary confirmations
pamenv push <slug|id> -e staging -f # conflicting keys take local values without asking
pamenv push <slug|id> -e staging --show-values # show non-sensitive values in the preview
pamenv push <slug|id> -e staging JWT_SECRET=new… # inline override on top of the local file
pamenv push <slug|id> -e staging --unset OLD_KEY # delete keys (local lines removed after success)
pullrequires export permission (project admin / owner). Already-sensitive keys are written with# pam:sensitiveand this environment's placeholder__PAM_SENSITIVE_…__(different per environment); leftover local plaintext for those keys is replaced. Unmarked keys (even names likeDATABASE_URL) stay as plain values. If the server sends no placeholder, sensitive keys are kept with an empty value (empty on push means keep). Preferpamenv runfor development.- File push = full desired state: a missing key in the file means delete it remotely; push does not auto-pad sensitive keys back in.
- On
push, a placeholder (or an empty value) for an already-sensitive key means "keep the PAM value"; a new value rotates it. New unmarked keys can be picked interactively (lookalike names are pre-checked as a hint);-yskips the picker and only warns about lookalikes. Use# pam:sensitiveto upgrade an existing plain key; sensitive cannot be downgraded. Remote values are not written into the local file until the push succeeds. After success, sensitive values in the local file are switched back to the placeholder (or empty when none exists). - Inline
KEY=valueoverlays the local file before a full replace;--unset <keys>removes keys from the final set (applied after overrides). - Placeholders from another environment (e.g. a copied file) are rejected, so a placeholder is never stored as a secret.
| Final local value | Already-sensitive key | Normal key |
|---|---|---|
| This env's placeholder | keep | (should not appear) |
| Empty string | keep | key kept, value cleared |
| New plaintext | rotate | update |
Missing line / --unset | delete | delete |
- Changes are merged key by key against the last pull/push baseline: a key changed on one side only takes that side; only keys changed on both sides conflict.
- On conflict,
pulldefaults to remote values andpushdefaults to local values. The conflicting keys are listed and you confirm (or pick the other side, or abort); you are then told to edit the local file manually andpush. pullkeeps unpushed local edits of ordinary keys and tells you about them. Already-sensitive keys are always replaced with the placeholder.pushmerges keys changed only on the remote into your local file after a successful push, instead of overwriting your other edits.- Without a baseline (never pulled/pushed here): one-sided keys are kept; only keys present on both sides with different values conflict. A first
pushtherefore does not silently drop remote-only keys (use--unset, or sync then delete the line); a firstpulldoes not silently drop local-only keys. - After a baseline exists, a missing file key /
--unsetmeans delete (full desired state). pullkeeps comments in your local file where possible. If only the remote changed,pushasks you topullfirst.- The diff masks every value as
*****by default;--show-valuesreveals non-sensitive values only. Names likeSECRET,TOKEN,PASSWORD,ACCESS_KEY,APIKEY,JWT,SESSION,COOKIE, orDATABASE_URLstay masked. - If the
-eenvironment does not exist,pushasks for its URL, validates everything, then creates the environment and uploads the variables together.
-y and -f
| Option | Effect |
|---|---|
-y | Skips ordinary confirmations: no-baseline prompt, final push, creating a missing environment, sensitive picker, remove. Lookalike new keys are only hinted, never auto-marked. Large deletions of remote keys still require one more confirm |
-f | Skips conflict confirmation only and uses the default side (remote for pull, local for push) |
Neither implies the other; pass both to skip everything.
Marking sensitive variables
Put # pam:sensitive above the key (other comments may sit in between). Comments above a key and inline comments are preserved.
# DB password
# pam:sensitive
API_TOKEN=xxxx # production only
NORMAL=1
Sensitive values are stored encrypted in PAM. Only run decrypts them (on the server) and injects them into the child process; the CLI never prints them. The web UI, render, pull and fork never get plaintext, owners included. Plaintext exists only in the child process environment; if the app prints, logs, or another local reader inspects that env, that is outside the CLI's control.
pamenv remove
Deletes a remote environment. Requires project admin (including the project owner) and asks for confirmation twice. Local .env.* files are not deleted.
pamenv remove <slug|id> -e local
pamenv remove <slug|id> -e local -y
Settings and language
pamenv config set domain pam.example.com # save the default PAM origin
pamenv config set locale zh # pin the CLI language (en | zh)
pamenv config list
pamenv locales pull # refresh server error messages
| Key | Description |
|---|---|
domain / url | Default PAM origin, so you don't need --domain every time |
locale | en or zh; once set, browser sign-in no longer changes the CLI language |
Without locale, the CLI follows the language of the browser sign-in page.
When a request fails, the CLI prints a readable message plus the error code (e.g. api:not_authorized) and a requestId. Include both when reporting a problem.
Sign-in and local credentials
- A CLI sign-in lasts 30 days by default; run
pamenv loginagain when it expires. pamenv logoutrevokes the credential on the server immediately and clears local sign-in and sync records.config.json(mode 0600) keeps only non-secret fields (baseUrl / locale / email). The bearer token goes into an OS-bound vault: DPAPI-protectedcredentials.encon Windows, the login keychain on macOS, and a 0600 private file elsewhere. Tokens still sitting in an old config.json are migrated out on the next read. Different.pamroots do not share credentials.
Project permissions
Access comes from your team role on the project; teams are managed in the PAM web UI.
| Role | run | push | pull / render (no sensitive values) | remove environment |
|---|---|---|---|---|
| owner / admin | ✓ | ✓ | ✓ | ✓ |
| member | ✓ (except protected environments) | ✓ (except protected environments) | — | — |
- Every
run,pullandrenderread is logged (who, which environment, how many keys; never values). Admins / owners can view the log on the environment page in the web UI. - Once a member is removed from the team, their CLI credential can no longer read the project's variables.
Only the project owner can transfer or delete a project, from the web UI's General tab. The CLI has no command for either.