name: env-bootstrap description: Create a mandatory isolated environment for a project so package/module versions never collide with the system or other projects. uv-first for Python (falls back to python -m venv), local node_modules for Node. Idempotent; never installs anything globally. TRIGGER when starting work in a new repo, when the user says "set up the environment", "create a venv", "isolate dependencies", or before any package install. model: sonnet
When to use
Run once per project before installing any dependency. Also run when block-global-pip blocks a global pip install — it means no isolated env is active yet.
Rule (mandatory)
Never install packages globally. Every project gets its own isolated environment. For Python that means a project-local .venv; for Node the local node_modules (never npm -g).
Steps
Detect the language from files in the project root:
- Python:
pyproject.toml,requirements.txt,setup.py,setup.cfg,Pipfile, or any*.py. - Node:
package.json. - Both can be true — handle each.
- Python:
Python — create
.venv(idempotent):if [ -d .venv ]; then echo ".venv exists"; else if command -v uv >/dev/null 2>&1; then uv venv # fast; creates .venv else python3 -m venv .venv # stdlib fallback fi fiThen install deps into the venv only, preferring uv:
# with uv (no activation needed): [ -f pyproject.toml ] && uv sync 2>/dev/null || true [ -f requirements.txt ] && uv pip install -r requirements.txt # without uv: activate first, then pip # source .venv/bin/activate && pip install -r requirements.txtTell the user how to activate:
source .venv/bin/activate(or just prefix commands withuv run).Node — keep installs local (never global):
[ -f package-lock.json ] && npm ci || npm install # writes ./node_modulesNever
npm install -g. Global Node tools belong in the user's own shell, not a project setup.Add to
.gitignoreif missing:.venv/,node_modules/.Confirm isolation: print the interpreter path (
.venv/bin/pythonorwhich pythonafter activation) so the user can see they are inside the env, not the system Python.
Anti-patterns
- Do not
pip installwithout an active venv oruv— that pollutes the system Python and causes the exact version conflicts this skill prevents. (Theblock-global-piphook enforces this.) - Do not use
sudo pip,pip install --user, orconda installintobase. - Do not recreate
.venvif it already exists unless the user asks (it is expensive and discards installed deps). - Do not commit
.venv/ornode_modules/.