git-worktree-env (wte)
Automatically prepare an isolated, runnable local development environment for every Git worktree. Lightweight, minimal, no magic.
The problem
Git worktrees are widely used for parallel development and task isolation. However, a new worktree usually contains only code, not a development environment that is ready to run:
- The frontend, backend, database, and debugger still use the same fixed ports, preventing multiple worktrees from running at the same time.
.envfiles, private keys, and other local secrets must be copied repeatedly and can easily be committed by mistake.- URLs and port settings shared by services within a project must be kept in sync manually.
Common solutions often require adding extra scripts to the project, changing how it
is started, modifying AGENTS.md or CLAUDE.md, or creating skills.
These approaches are intrusive to some degree: they must either be adopted across
the team or affect how other team members work.
wte uses a Git post-checkout hook to assign stable, conflict-free ports to a
project's worktrees, link environment variables, and generate local configuration.
The hook is not committed to the repository. It is available globally on the local
machine and does not modify any project code.
Comparison with existing tools
- Portless: Requires applications to be
started through
portless, introducing a reverse proxy, a local CA, and a background service. - devports: Wraps worktree creation and
removal in
devportscommands; worktrees created directly by an agent or IDE are not handled automatically. - Worktrunk: Replaces the native Git workflow with
wt, does not participate in environment setup, and does not automatically handle worktrees created directly by an agent or IDE. - workz: Uses
.workz.toml,workz sync/workz start, or separately configured hooks for Cursor, Claude Code, and Worktrunk. - Hyve: Adopts a
hyve create/hyve runworkflow and depends on Docker, database containers, and service orchestration.
wte does not take over how worktrees are created or how a project is started.
Instead, it automatically projects a complete local development environment after a
worktree is created. It requires no changes to project code, start commands, or agent
prompts; no scripts need to be added to the project, and no traffic proxy or resident
process is required. Worktrees created by Git, an IDE, or a coding agent can all be
handled automatically.
All rules are declared explicitly in profiles stored outside the repository. For each
worktree, wte assigns stable ports, mounts secrets, generates local configuration,
and can initialize dependencies in the background, making the worktree ready
immediately after creation.
Features
- Allocates contiguous port blocks from a machine-wide shared pool and keeps them stable for the lifetime of the worktree path.
- Mounts secrets stored outside the repository into the worktree as symlinks, preserving a single source of truth and avoiding copy and paste.
- Organizes configuration by repository rather than by service. Supports monorepos and multiple port requests.
- Optionally monitors host directories to discover newly added linked worktrees, including those created within coding agent sandboxes.
- Preserves the project's own Git hooks. After the
post-checkouthook forwtefinishes, it invokes the project's own executable Git hook. - Zero intrusion: no wrapper, no skill, and no changes to coding agent prompts or project start commands.
Requirements
- macOS or Linux
- Python 3.9+
- Git
- Bash
Installation
uv tool install git-worktree-env
Upgrading
uv tool upgrade git-worktree-env
Getting started
wte init
This command:
- Initializes the personal configuration directory at
~/.config/wte/. - Runs
git config --global core.hooksPath ~/.config/wte/hooksto install the global Git hook dispatcher.
If the global
core.hooksPathalready points somewhere else,wtedisplays the current value and refuses to change it. Confirm its purpose and migrate or remove it as appropriate before retryingwte init.
~/.config/wte/
Personal profiles, hooks, and runtime state are stored together in:
~/.config/wte/
├── config.yaml # Machine-wide port pool
├── project_a.yaml # Project A profile
├── project_b.yaml # Project B profile
├── hooks/ # Global Git hook dispatcher
└── state/ # Managed by wte; do not edit manually.
├── ports.json # Port registry
├── ports.lock # Concurrency lock
├── hooks-state.json # Hook installation state
└── reconciler.log # Monitor log (present only when the optional Monitor is enabled; see the Monitor section)
Every root-level *.yaml file except config.yaml is loaded as a project profile.
Set WTE_CONFIG_HOME to change this directory. When it is not set,
XDG_CONFIG_HOME is respected.
Configuration examples
Port range
The machine-wide port range is configured in ~/.config/wte/config.yaml:
port_range:
start: 20000
end: 29999
The default range is 20000-29999. You can change it manually; new worktrees will
be allocated from the new range, while existing allocations remain unchanged.
Project profile
Copy the configuration template:
cp ~/.config/wte/project.example.yaml.template \
~/.config/wte/example-project.yaml
The following profile describes a project with separate frontend and backend services:
name: example-project
match:
# Points to the project's main worktree directory.
main_worktree: $HOME/code/example-app
ports:
# Names of the ports to request. Add as many as the project needs;
# each id must be unique within the profile.
- id: frontend_port
- id: backend_port
secrets:
# Environment files shared through symlinks.
# source points to the original environment file, while target is a path
# relative to the worktree root.
- source: $HOME/path/to/your/frontend.env
target: frontend-dir/.env
- source: $HOME/path/to/your/backend.env
target: backend-dir/.env
writes:
# Frontend configuration:
- path: frontend-dir/.env.development
body: |
VITE_PORT=${frontend_port}
SERVER_URL=http://127.0.0.1:${backend_port}
# Backend configuration:
- path: backend-dir/.env.development
body: |
PORT=${backend_port}
This example applies when both the frontend and backend can load
.env.{env name}files. Adjust it to match how your project loads environment variables.After a worktree directory is deleted, its ports are reclaimed the next time
wteis triggered.
Monitor
Some coding agents create worktrees inside a sandbox, which can prevent the wte hook from running.
To support these tools, enable the Monitor:
wte monitor enable
It watches the .git/worktrees/ metadata directory associated with each configured
main worktree:
- macOS uses a LaunchAgent with
WatchPaths. - Linux uses a systemd user path unit.
When the directory changes, the operating system starts a short-lived Reconciler. It is not a resident daemon and does not poll on a timer, so its resource usage is minimal.
The Reconciler:
- Runs
git worktree list --porcelainto retrieve the actual list of worktrees. - Compares it with
ports.json, then assigns ports, mounts secrets, and generates files for unregistered worktrees.
After adding a profile or changing a main_worktree path, run this command again:
wte monitor enable
To disable the Monitor, run:
wte monitor disable
Afterward, filesystem changes will no longer be monitored.
Asynchronous initialization
wte can automatically run commands after a worktree is created, allowing the
environment to be initialized in the background:
init:
- command: npm install
cwd: frontend-dir # Use "." to run from the worktree root.
skip_if: node_modules # Skip this command if the file or directory exists.
- command: uv sync
cwd: backend-dir # Use "." to run from the worktree root.
skip_if: .venv # Skip this command if the file or directory exists.
A typical timeline looks like this:
Create a worktree
→ wte projects the environment and starts npm install in the background
→ The user describes the task; the AI reads, analyzes, and modifies the code
→ By the time the user or AI starts the project, dependencies are usually ready
Asynchronous initialization is started only by the normal post-checkout hook.
Neither wte sync nor the Monitor Reconciler runs these commands, preventing manual
synchronization or background reconciliation from repeatedly starting expensive
tasks.
Commands supported by wte
wte init Create personal configuration and templates, and install core Git hooks
wte sync Synchronize ports, secrets, and generated files for the current worktree
wte list List port allocations for worktrees that still exist
wte doctor Diagnose configuration, profiles, registry, secrets, hooks, and Monitor
wte monitor enable Install or refresh optional host monitoring
wte monitor disable Remove host monitoring only, preserving Git hooks
wte uninstall Remove hooks and the Monitor, preserving configuration and runtime state
Run wte sync from inside the target worktree. It reuses existing ports, recreates
secret symlinks, and regenerates configuration files.
You may need it when a worktree is created through an unconventional method.
License
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file git_worktree_env-0.1.4.tar.gz.
File metadata
- Download URL: git_worktree_env-0.1.4.tar.gz
- Upload date:
- Size: 44.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d43744c45fc0fbc76579df267b525771f1e4cf876f24b5cb16379cecd54be8d7
|
|
| MD5 |
1f6b2f1a51cab3ba595ff493a913748d
|
|
| BLAKE2b-256 |
fb5106c85ece5a11e802b9c7731057bd0f49446c42d85ed2d156b2310c8b7b26
|
File details
Details for the file git_worktree_env-0.1.4-py3-none-any.whl.
File metadata
- Download URL: git_worktree_env-0.1.4-py3-none-any.whl
- Upload date:
- Size: 26.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0a1d302055516391bbe21cf8fbec097fc06f08f4aa033a84badbf6102de97ec
|
|
| MD5 |
b5ef92c42c6f247cbbd831a623d90877
|
|
| BLAKE2b-256 |
becdae462cc9df5868a90e622d32cc4a504cb7b55f2f6f206b46e208d97684ad
|