npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

worktree-env-sync

v2.0.8

Published

CLI tool for syncing environment files across git worktrees with template interpolation and symlink support for monorepos

Readme

worktree-env-sync

A CLI tool for syncing environment files across git worktrees. It generates .env files by combining a shared template with worktree-specific input variables, and creates symlinks to distribute the env file to multiple locations within each worktree.

Installation

npm install -g worktree-cli

Usage

# Using default config file (worktree-env-sync.json)
worktree-env-sync

# Using a custom config file
worktree-env-sync my-config.json

Config File

The config file is a JSON file with the following structure:

{
  "template": ".env.template",
  "inputFilesToFolders": {
    ".env.worktree1": "../worktree1",
    ".env.worktree2": "../worktree2",
    ".env.worktree3": "../worktree3"
  },
  "outputFile": ".env.local",
  "symlinksToOuputFile": [
    "apps/web/.env.local",
    "apps/docs/.env.local",
    "packages/db/.env.local"
  ]
}

| Field | Description | |-------|-------------| | template | Path to the template env file containing shared variables and interpolation references | | inputFilesToFolders | Map of input env files to their target worktree folders | | outputFile | Output filename for the generated env file (relative to each target folder) | | symlinksToOuputFile | Paths where symlinks to the generated env file should be created (relative to each target folder) |

How It Works

1. Input Files

Create an input env file for each worktree containing worktree-specific variables:

# .env.worktree1
DATABASE_URL=postgres://localhost/worktree1_db
API_KEY=dev-key-123
# .env.worktree2
DATABASE_URL=postgres://localhost/worktree2_db
API_KEY=dev-key-456

2. Template File

Create a template file with shared variables. Use ${VAR_NAME} syntax to reference variables from the input files:

# .env.template
APP_NAME=myapp
APP_URL=http://localhost:3000
DATABASE_CONNECTION=${DATABASE_URL}?pool=5
API_KEY=${API_KEY}

Note: All ${VAR} references in the template must exist in the input files or the tool will fail, since missing variables would result in broken output. If input files contain variables not referenced in the template, a warning will be displayed but processing will continue, since the output is still valid.

3. Generated Output

Running worktree-env-sync generates an env file in each target folder with interpolated values:

# ../worktree1/.env.local
API_KEY="dev-key-123"
APP_NAME="myapp"
APP_URL="http://localhost:3000"
DATABASE_CONNECTION="postgres://localhost/worktree1_db?pool=5"

Note: Output values are quoted and variables are sorted alphabetically.

4. Symlinks

Symlinks are created at each path specified in symlinks, pointing to the generated env file. This allows monorepo packages to share the same env file:

worktree1/
├── .env.local                      # Generated env file
├── apps/
│   ├── web/.env.local              # Symlink → ../../.env.local
│   └── docs/.env.local             # Symlink → ../../.env.local
└── packages/
    └── db/.env.local               # Symlink → ../../.env.local

Validation

The tool validates that:

  • All input files have the same set of keys
  • Template and input files don't have conflicting keys
  • All ${VAR} references in the template exist in the input files (fails if missing)
  • Input variables not used in the template trigger a warning (but processing continues)