DocsAutomation

Worktrees & env files

Every off-main session runs in its own git worktree, and Plexus copies the env files it needs in as the worktree is created.

Where worktrees live

When you start a session, Plexus cuts a git worktree from the base branch you picked. By default it lands at:

text
<project>/worktrees/<session-name>

The subfolder comes from worktree.location (default worktrees); the session name is slugified and appended automatically. The value is always a relative path under the project root — it can never escape it. Root-tree sessions don't get a worktree; they run directly in the project's root working tree. See Sessions for the full lifecycle.

Auto-gitignore

When a worktree is created inside the repo, Plexus adds its parent folder to the repo's .gitignore so worktree contents never surface as untracked changes. This is worktree.autoGitignore (default on). Leave it on unless you're managing the ignore entry yourself.

Why env files need copying

A fresh worktree is a clean checkout — it holds only tracked files. Anything gitignored, most importantly .env and .env.local, is not carried over. A dev server or test runner that reads those files would break the moment the agent runs it inside the worktree.

So as each worktree is created, Plexus copies the paths you configure into it — regardless of .gitignore.

Copying paths into worktrees

Two settings control the copy:

SettingDefaultWhat it does
worktree.copyEnabledonWhether to copy any paths into a new worktree
worktree.copyPaths.env, .env.localThe files and folders to copy

Out of the box, .env and .env.local land in every new session worktree.

Adding paths

  1. Open Settings and go to the Worktrees category.
  2. Make sure Copy files into new worktrees is on.
  3. Add each file or folder you want copied to the paths list, using the add/remove controls.

The Worktrees settings panel: the worktree folder field, the auto-gitignore and copy-into-new-worktrees toggles, and the paths-to-copy list with .env, .env.local, vendor/, and node_modules entries plus add and remove controls.

Paths are relative to the project root and copied as-is whether or not git tracks them; folders are copied recursively. Common additions are .env.development, a local config/ folder, or service-account credentials that live outside version control. Like any setting, these layer per scope — set a baseline globally and override it for one project.

Path safety

Plexus validates every copy path so a worktree can't be corrupted or used to escape the repo:

  • Absolute paths and .. traversal are rejected.
  • . and empty entries are rejected.
  • Symlinks are skipped — a top-level symlink copies nothing, and symlinks inside a copied folder are skipped — so the copy can't leak files from outside the repo.
  • Missing sources are silently skipped, so a path that doesn't exist in a given project won't fail the launch. A path that disappears mid-copy — e.g. a tool rewriting .env at that instant — is skipped the same way rather than failing the launch. A genuine error (an unreadable file, a full disk) still stops the launch, but the message names the exact path so you know what to fix.

Plexus does not auto-assign or remap dev-server ports. If two sessions' dev servers bind the same port, that conflict is yours to resolve — read a port from the .env you copy in, or set one from a hook.

  • Hooks — run your own scripts at create, run, and teardown; the copy-paths step is a built-in that runs during create.
  • Secrets — keep API keys in your OS keystore instead of committing or copying them through .env files.
  • Settings — the full list of worktree.* keys and their defaults.