Skip to main content

envshed init

Connect local application folders to Envshed projects. Init reuses a valid login or opens the existing device authorization flow, detects applications, prepares a plan and asks before creating projects or changing configuration.

terminal
npx envshed@latest init
npx envshed@latest init -o my-team -p my-app -e development

Run inside the application folder or the common parent of several applications. Node.js and npm are required for npx; the package is downloaded to the npm cache, not installed globally. An installed CLI can use envshed init directly.

Options​

OptionDescription
-o, --org <slug>Use an existing organization/workspace
-p, --project <slug>Reuse this project for the selected application(s); missing projects require interactive creation review
-e, --env <slug>Shared default environment to save; missing environments are included in the creation plan
-w, --workspace <path>Select one application directory explicitly, relative to the setup root
--allSelect all suggested runnable applications; libraries and root orchestrators remain optional
-y, --yesAccept the printed setup plan without prompts; may create projects/environments
--no-guideSave validated configuration without the interactive run guide. Does not affect the env file import, see --no-import
--personalSave the connection on this machine only, outside the project. Nothing is created or changed in the repository. See Only for me
--importImport the env files found in the connected folders without asking first. Without a TTY, uses the suggested environment of each file
--no-importDo not look for env files
--import-map <pairs>Map files to environments without prompts, e.g. .env.local=development,.env.production=production. Files not listed are skipped
--create-envsCreate the environments named by --import-map (or suggested by file names) when they do not exist. Needs permission to create environments
--api-url <url>Explicitly select and persist a personal API destination outside the repository. Must be HTTPS (plain HTTP only for localhost). Switching to a different destination discards the saved token, so you sign in again there; a token is never sent to another API

Interactive input is required for unresolved choices. Noninteractive runs require authentication and explicit answers; use --yes only when the printed plan's possible resource creation is intended. Init never falls back to another credential when ENVSHED_TOKEN is invalid. A 403 is an access/plan failure, not a reason to reopen login.

One application​

Init reuses existing mappings and development environments when available. It saves shared metadata in .envshed.json:

json
{
"org": "my-team",
"project": "my-app",
"defaultEnv": "development"
}

This file contains no tokens or secret values. Personal environment selections remain in ~/.envshed/contexts.json and are not overwritten by init. The first guided run explicitly targets the environment reviewed in setup; later normal runs use the context precedence.

When the folder already has env files, init offers to import them right after the connection is saved. See Import existing env files. New applications can add values in the dashboard. No env file is created or synchronized implicitly.

When a runnable command is known, init offers to execute it through the existing run path. Starting a process does not prove the application is ready: the guide asks for your confirmation separately. Repeat init to reopen the guide.

Import existing env files​

After the connection is saved, init looks for env files in each connected application folder and offers to import them into Envshed:

output
Found 2 env files with secrets:
.env.local (12 keys)
.env.vercel.production (18 keys)
? Import them into Envshed? (Y/n)

Only file names and key counts are shown, never values.

Which files. .env, .env.* and *.env in each connected application folder (in a monorepo, each selected package). Init skips templates (.env.example, .env.sample, .env.template, also as .env.local.example), the dotenvx companions .env.vault and .env.keys, symlinks, files over 1 MB, empty files and any output file configured for envshed pull in .envshed.json. Subfolders are not searched. In a monorepo where the root folder is not one of the connected applications, env files at the root are not imported: init lists them with the envshed import <file> -p <project> -e <env> command to run for each.

Where each file goes. For each file, pick an existing environment of the project, Create new environment (name prefilled from the file name) or Skip this file. Back reopens the previous file with its answer kept. The suggested environment comes from the file name:

FileSuggested environment
.env.production, .env.prod, .env.vercel.production, .env.production.localproduction (or an existing prod/prd/live)
.env.staging, .env.previewstaging (or an existing stage/stg/preview/uat)
.env.testtest
.env, .env.local, .env.development, .env.devthe default environment chosen in init
anything else, e.g. .env.qathe file suffix (qa)

Two files may go to the same environment. Files are applied in alphabetical order, so .env.local overrides .env, and every key that differs between them is listed by name.

Plan. Before anything is written, init shows per environment how many keys are new, how many would change and how many stay the same, and which files feed it. Choose Import, Back to change the mapping, or Cancel. The import uses the same write path as envshed import, one environment at a time. New environments are created through the API with the same permission checks as envshed envs create.

After the import. Init prints the next step (envshed run -- <dev command>) and then:

  • warns when an imported file is tracked by git: its values are already in the repository history, so remove it with git rm --cached and rotate those secrets;
  • offers to add files that git does not ignore to .gitignore. For a personal connection it uses .git/info/exclude instead, so no file of the repository changes. Default: no;
  • offers to delete the imported files now that Envshed holds the values. Default: no.

Existing loaders (for example Next.js reading .env.local) may still read files you keep and override injected values; review them before relying only on Envshed.

Scripts and CI​

Without a TTY, init never imports unless asked:

terminal
# Map files explicitly; files not listed are skipped
envshed init -o my-team -p my-app -e development --yes \
--import-map .env.local=development,.env.production=production

# Use the suggested environments; files whose environment does not exist are skipped
envshed init -o my-team -p my-app -e development --yes --import

# Create environments that do not exist yet
envshed init -o my-team -p my-app -e development --yes --import-map .env.qa=qa --create-envs
  • In a monorepo, a file name present in several packages must be written with its path, e.g. apps/web/.env.local=development.
  • --import-map fails for a file it cannot find, and for an environment that does not exist unless --create-envs is passed.
  • Without a TTY, an import that would change existing values stops unless --yes is passed.
  • --no-import cannot be combined with --import-map or --create-envs.
  • --yes accepts the setup plan without prompts, so it also skips the import offer. Add --import or --import-map to import in the same run.

Only for me​

Before writing anything, init asks who the connection is for:

  • The team (default): creates .envshed.json in the project, to commit, as described above.
  • Only me: saves the same connection on this machine, outside the project. Nothing in the repository is created or changed, so nobody else sees that you use Envshed. --personal picks this without asking.
terminal
npx envshed@latest init --personal

The personal connection is stored in ~/.envshed/connections/<id>/.envshed.json (folder 0700, file 0600), where <id> is a hash of the real path of the checkout root (the folder with .git). It has exactly the same content as a project .envshed.json, monorepo workspaces included, and every command uses it the same way. From any folder of that checkout, run commands without -o -p -e:

terminal
npx envshed@latest run -- npm run dev
  • It needs a git checkout, and it applies to that checkout only: another clone or worktree, or the same folder after being moved or renamed, is not connected. Run init --personal there again.
  • If the repository gets a .envshed.json later (for example when the team adopts Envshed), that file is used and the personal connection is ignored. To share yours with the team, run init again and choose "The team", then delete the personal folder.
  • Commands that change the connection (workspace add, workspace remove, changing or renaming the default environment) save to the personal file. No command creates .envshed.json in the repository for a personal connection.
  • The optional script integration below is not offered, because it would change package.json.
  • To remove it, delete its folder under ~/.envshed/connections/.

Multiple applications​

Declared monorepos and common parent folders containing independent applications use the same command:

terminal
npx envshed@latest init -o my-team

Select one or several detected applications. For each, reuse a remote project or name a new one and choose an environment. Review the consolidated plan (paths, targets, create/reuse actions and configuration files) before applying it. Project creation and environment creation remain subject to server permissions and plan limits. A remote project for the root is not required.

Discovery is read-only: package.json scripts, Python manifests, go.mod and Cargo.toml identify candidates. It traverses at most four directory levels and 500 directories, skips dependencies, build outputs, hidden directories and directory symlinks, and never executes project code. Libraries are selectable but not automatically turned into remote projects. Use --workspace <path> for a missed application; external symlinks are refused. Automatic command suggestions cover recognized Node scripts and simple Go/Rust entry points; Python/custom applications use their own command with run.

Monorepo mappings share a root .envshed.json without replacing existing root projects or unselected mappings. Independent repositories use application-local configuration rather than adding a common ancestor config. The plan names every file that will be written. Each application keeps its own environment and secrets; configuring several does not start them all in one process.

For an intentional noninteractive setup of all suggested apps:

terminal
envshed init --all -o my-team -e development --yes --no-guide

New project names are suggested from local application names in this mode. Collisions between new project plans are rejected. Pass -p only to intentionally reuse that same existing remote project for the selected applications.

Retrying and cancellation​

No project/environment is created before plan confirmation. Completed application mappings are saved incrementally and atomically. If setup stops, it reports partial completion; a remote resource may exist even if its response was lost. Rerunning init re-lists projects/environments and reuses those resources. There is no distributed transaction and no automatic deletion of successful resources. Concurrent local edits are detected and preserved.

An explicit API destination has its own confirmation and is saved as a personal setting. A reviewed configuration update removes a legacy project API override when necessary; implicit repository remote redirects remain ignored. Changing the destination does not copy credentials into the project.

Optional script integration​

For recognized Node scripts, init previews an optional integration: preserve dev as dev:local and replace dev with a pinned npx envshed@<version> run -- <package-manager> run dev:local. It keeps other scripts unchanged, refuses a collision with an existing :local name and does not wrap an existing envshed script again. Applying it is a separate explicit choice. The wrapper obtains the released CLI version on demand, avoiding a global dependency; testing an unpublished build should use the local CLI directly until that version is released.

Recovery​

  • Missing/expired saved login: device authorization, then resume.
  • Invalid ENVSHED_TOKEN: update/unset it and authenticate explicitly.
  • Access or plan refusal: select an accessible target or ask an administrator/owner.
  • Invalid JSON: repair the named file; init preserves it.
  • Network failure: retry init; inspect the printed partial progress.
  • Application failure: configuration remains saved; inspect application output and retry.