This document explains how Amplifier handles virtual environments across git worktrees to avoid conflicts.
When using git worktrees for parallel development, all worktrees inherit the VIRTUAL_ENV environment variable from your shell, which points to the main repository's .venv. This causes issues with uv (the package manager), which expects each project to use its own local .venv.
The error looks like:
warning: `VIRTUAL_ENV=/Users/you/src/amplifier/.venv` does not match the project
environment path `.venv` and will be ignored
We've implemented a three-part solution:
When you create a worktree with make worktree <branch-name>, it now:
- Creates the worktree as before
- Copies the
.datadirectory - Automatically creates a local
.venvusinguv - Installs all dependencies
The make check target now:
- Detects when
VIRTUAL_ENVpoints to a different directory - Unsets
VIRTUAL_ENVto letuvuse the local.venv - Runs all checks using the correct environment
The Claude Code hook (.claude/tools/make-check.sh) now:
- Detects when running in a worktree
- Unsets mismatched
VIRTUAL_ENVvariables - Uses the worktree's local
.venv
# Create worktree with automatic venv setup
make worktree my-feature
# The output will show:
# 🐍 Setting up virtual environment for worktree...
# ✅ Virtual environment created and dependencies installed!
# Navigate to the worktree
cd ../amplifier-my-feature
# The venv is already set up and ready to use!If automatic setup fails (e.g., uv not available), you can set it up manually:
cd ../amplifier-my-feature
make install # This creates .venv and installs dependenciesJust run make check as normal - it handles the environment automatically:
make check
# Output: Detected virtual environment mismatch - using local .venv
# Then runs all checks normally-
tools/create_worktree.py:- Added
setup_worktree_venv()function - Runs
uv venvanduv sync --group devafter creating worktree
- Added
-
Makefile:checktarget unsets mismatchedVIRTUAL_ENV- Uses
VIRTUAL_ENV=prefix onuv runcommands
-
.claude/tools/make-check.sh:- Added
setup_worktree_env()function - Unsets
VIRTUAL_ENVwhen mismatch detected
- Added
-
pyproject.toml:- Added exclude patterns to pyright config
- Prevents type-checking errors from optional dependencies
- No manual venv activation needed - Each worktree has its own
.venv - No more VIRTUAL_ENV warnings - Conflicts are handled automatically
- Seamless workflow - Just
make worktreeand start coding - Claude Code hooks work - No more make check failures
Install uv first:
curl -LsSf https://astral.sh/uv/install.sh | shMake sure you're using the updated Makefile. The fix requires:
- Updated
tools/create_worktree.py - Updated
Makefilewith VIRTUAL_ENV handling - Updated
.claude/tools/make-check.sh
These are from optional dependencies. The fix excludes these directories from pyright checking.
Potential enhancements:
- Auto-activate venv when entering worktree directory
- Share package cache between worktrees to save disk space
- Option to use symlinks for large dependencies