Docs menuPer-environment scoping

Per-environment scoping

A project vault can hold a separate set of values for default, staging, production, or any other valid environment name.

lpm env set --env=staging DATABASE_URL=postgres://staging.db/app
lpm env set --env=production DATABASE_URL=postgres://production.db/app

lpm env list --env=staging
lpm env list --env=production

Without --env, local vault commands use the default environment.

Select an environment for execution

To select an environment for a script or the development server, add --env:

lpm run --env=staging dev
lpm run --env=production build
lpm dev --env=staging

The --env flag has the highest priority. Without it, LPM CLI uses the lpm.json > tasks.<name>.env value of the task. If the task has no such value, LPM CLI looks up the script name in the lpm.json > env mapping:

{
  "env": {
    "dev": ".env.development",
    "staging": ".env.staging",
    "prod": ".env.production"
  }
}

With this mapping, lpm run dev selects the development environment. LPM CLI takes that name from the .env.development file name. LPM CLI does not read an LPM_ENV environment variable to select an environment.

Environment inheritance

To share dotenv values between environments, define them under lpm.json > environments:

{
  "environments": {
    "base": ".env",
    "staging": {
      "extends": "base",
      "file": ".env.staging"
    },
    "production": {
      "extends": "base",
      "file": ".env.production"
    }
  }
}

LPM CLI loads the parent files first, and the child files override them. LPM CLI rejects circular inheritance and missing parents.

The LPM CLI lpm.json reference explains aliases, inheritance, and valid environment names.

How values are resolved

When LPM CLI runs a command in an environment, it resolves the values in this order:

  1. Dotenv files, including a configured inheritance chain.
  2. Vault secrets, which override dotenv values.
  3. The static values of a service, if the command selects one with --service.
  4. Personal overrides on this computer. The LPM Vault app sets them.
  5. Defaults and validation from envSchema.

LPM CLI applies personal overrides when it runs, prints, or checks a project. It leaves them out when it sends values elsewhere, such as to CI or a platform.

If the selected environment has vault secrets, LPM CLI uses only those secrets. It does not fill missing keys from the default environment. If the selected environment has no vault secrets, LPM CLI uses the default vault values.

So when you add the first secret to staging, staging stops using the default vault values. If staging must start with the default values, copy them first with lpm env copy default staging.

Copy values

lpm env copy default staging
lpm env copy staging production
lpm env copy staging production --overwrite

lpm env copy writes each source key that the destination does not have. It skips keys that already exist in the destination. To replace them, add --overwrite. The command does not rename keys or add prefixes to them.

Compare environments

lpm env diff
lpm env diff staging
lpm env diff staging production
CommandComparison
lpm env diffLocal default environment against cloud default
lpm env diff stagingLocal staging against cloud staging
lpm env diff staging productionTwo local environments

The output lists the keys that are added, removed, or changed, and counts the unchanged keys. It never prints the compared values.

A comparison with the cloud needs access to a synced personal vault on the Pro plan. A comparison of two local environments does not.

Validate all environments

lpm env check

lpm env check finds the environments in lpm.json and in the local vault. It resolves each environment and validates all of them against envSchema. To validate only one environment, add --env=<name>.

Cloud sync uses the complete vault

lpm env push
lpm env pull

Cloud sync uploads and downloads all environments together. A push encrypts every environment in the local vault into one project payload. A personal pull replaces the local vault with the complete remote set of environments.

An OIDC pull in CI is different. It returns one environment, and the policy must allow that environment for the verified workflow. OIDC for CI explains the policies.

See also