published · 3 min read

An Editable Install in a Symlinked .venv Follows the Last uv run

My plugin climb used to link .venv into a temporary worktree, where one uv run could leave the main checkout importing from a folder about to be deleted.

Two folders, proj/ and base/, share one .venv through a symlink; the .venv's demo.pth now holds /tmp/t/base/src, and an import run in proj/ prints /tmp/t/base/src/demo/__init__.py.
One .venv, two folders: after a uv run in the worktree, the main checkout imports from it.

An AI agent drafted this from my projects, agents ran the measurements, and another agent checked the draft claim by claim against the code and the run records or briefs that were kept. The projects and opinions are mine.

Run uv run in a git worktree whose .venv is a symlink to your main checkout's, and a packaged project's editable install moves to that worktree. With a src/ layout your main checkout then imports your package from there. Here is a run on macOS, with a toy src/demo package, committed to git, that has a uv_build [build-system] table and was installed the default editable way:

uv sync -q --python 3.12
.venv/bin/python -c 'import demo; print(demo.__file__)'
git worktree add -q ../base HEAD
ln -s "$PWD/.venv" ../base/.venv
(cd ../base && uv run -q python -c 'import demo; print(demo.__file__)')
.venv/bin/python -c 'import demo; print(demo.__file__)'
git worktree remove --force ../base
.venv/bin/python -c 'import demo; print(demo.__file__)' 2>&1 | tail -1
/tmp/t/proj/src/demo/__init__.py
/tmp/t/base/src/demo/__init__.py
/tmp/t/base/src/demo/__init__.py
ModuleNotFoundError: No module named 'demo'

An agent reproduced this for me. Those paths have a shortened temp folder. uv 0.7.17 printed these four lines, and so did 0.13.7, the latest release on 7 November 2026.

Four steps of the run: proj/ imports from /tmp/t/proj/src; a uv run in base/ rewrites demo.pth to /tmp/t/base/src; proj/ now imports from base; after the worktree is removed, the import fails with ModuleNotFoundError.
The run above, step by step, with the paths it printed.

What changes is a small .pth file in site-packages, which the build backend generates and uv installs: demo.pth with uv_build here, _editable_impl_demo.pth with hatchling. It held /tmp/t/proj/src before the worktree run and /tmp/t/base/src after. That fits what uv documents. A project gets "installed in editable mode" by default, and with run, "uv will ensure that the project environment is up-to-date before running the given command." From inside a worktree, your project is the worktree's copy, and a symlinked .venv carries that update back to your main environment. uv run --no-sync skips that check and leaves the path alone, though the worktree then imports from whichever checkout the environment last pointed at, not necessarily its own.

uv is doing what it documents, on an environment two folders share. The cause is the sharing. The worktree isn't needed, and the symlink is only one way to share: a plain clone and a copied folder with the main .venv linked in did the same in the toy project, and so did an absolute UV_PROJECT_ENVIRONMENT with no symlink at all. For that last setup there is a warning in uv's docs, that the environment "will be overwritten by invocations in each project". The pydevtools handbook's How to Run Parallel AI Coding Agents on One Python Project also warns against sharing one .venv across worktrees.

climb, my plugin that does the measuring so a coding agent can't grade its own work, compares old code with new code in pairs, and for that it checks out an old commit in a temporary worktree and links in untracked and ignored paths, which until 29 October included .venv. In a toy run of that case, with iniconfig pinned differently in the two commits, uv run in the old commit's worktree also moved the main environment from 2.1.0 down to 2.0.0.

Commit 711255c, under my name, came out of an independent review. It files this under HIGH and says "uv run in the base worktree re-pointed the real .venv at the temporary tree." All the runs in this post are toy runs: nothing in the repo shows this hit a real project.

Now some folders stay unlinked:

export const ENVS = /(^|\/)(\.venv|venv|\.tox|\.nox|\.direnv)(\/|$)/;

ENVS only knows names, though, so a virtualenv folder called env or .venv-3.12 still gets past this filter. A plain uv run ignores those names and builds a fresh .venv, so the problem only returns if something points uv at one, such as UV_PROJECT_ENVIRONMENT or uv's --active flag with that environment activated.

A base worktree now needs a separate environment, which a uv run command builds there by itself, or pairing falls back. In the toy project, uv sync from the main checkout put the .pth path back, and so did the next plain uv run there. Until one of them runs, anything that calls .venv/bin/python directly, including python in an activated shell, imports from the worktree, or fails once the worktree is gone.