Skip to main content
Git worktrees are common in AI-assisted development workflows. typemux-cc solves the problem of creating .venv after opening files in a new worktree — no Claude Code restart required.

The Problem

With Claude Code’s official pyright plugin:
  1. Create a worktree: git worktree add ../my-project-worktree feat/new-feature
  2. Open files in the worktree (no .venv exists yet)
  3. Create .venv: cd ../my-project-worktree && uv sync
  4. LSP doesn’t work — pyright still thinks there’s no venv
  5. Must restart Claude Code to pick up the new .venv
With typemux-cc, step 5 is eliminated.

Typical Worktree Workflow

Here’s the real-world scenario from the README:
1

Create worktree

At this point, my-project-worktree/ has no .venv.
2

Open files in Claude Code

Open my-project-worktree/src/main.py in Claude Code.What happens:
  • typemux-cc searches for .venv in parent directories
  • Finds none (stops at git toplevel)
  • Caches venv=None for this document
  • LSP requests return errors (strict venv mode)
3

Create .venv

Now .venv exists:
4

Reopen the file

Close and reopen my-project-worktree/src/main.py.What happens:
  • textDocument/didOpen triggers a fresh .venv search
  • typemux-cc finds my-project-worktree/.venv
  • Spawns a new backend with VIRTUAL_ENV=my-project-worktree/.venv
  • Restores the document to the new backend
  • LSP features now work
No Claude Code restart required. The backend pool dynamically adds the new worktree’s backend.

Detection Logic

Git Toplevel as Search Boundary

typemux-cc caches the git repository root at startup:
The git toplevel is used as a boundary when searching for .venv:

Why use git toplevel?

Prevents searching outside the project. Without a boundary, typemux-cc might find .venv from a parent project (e.g., system-wide venv), which would be incorrect.

Worktree-Specific Behavior

Each worktree is a separate git working directory with its own .venv:
When you run git rev-parse --show-toplevel in a worktree, it returns the worktree’s root (not the main repo root). This ensures .venv search is scoped correctly.

Late .venv Creation Scenario

Why the Cache Limitation Exists

The venv field is set once when the document is opened. Subsequent LSP requests reuse this cached value without re-searching the filesystem. Rationale: Filesystem I/O (checking for .venv/pyvenv.cfg) on every hover/completion request would be prohibitively expensive.

Workaround: Reopen Files

Closing and reopening a file clears its cache entry:
Next didOpen triggers a fresh search:
If you create .venv after opening files, you must reopen those files for LSP to work. This is the one manual step required.

Real Workflow Example

Here’s a complete workflow from a real AI-assisted development session:
Expected log output:

Multiple Worktrees

You can have multiple worktrees open simultaneously, each with its own .venv and backend:
What happens:
  1. Open file from my-project/ → backend spawned (session 1)
  2. Open file from my-project-feat-a/ → new backend spawned (session 2)
  3. Open file from my-project-feat-b/ → new backend spawned (session 3)
  4. Return to my-project/ → session 1 still in pool, no restart
All three backends coexist in the pool (up to TYPEMUX_CC_MAX_BACKENDS, default 8).

Troubleshooting

.venv not detected after creation

1

Verify pyvenv.cfg exists

If missing, your venv creation failed or used an unsupported tool (poetry/conda).
2

Check git toplevel

Should return the worktree root, not the main repo root.
3

Reopen files

Close all Python files in the worktree and reopen them. This clears cached venv=None.
4

Check logs

Still getting “venv not found” errors after reopening

Possible causes:
  1. Symlink .venv: typemux-cc may not follow symlinks. Use an actual directory.
  2. Wrong .venv name: Only .venv is supported (not venv, .env, etc.).
  3. Missing pyvenv.cfg: Some tools (conda) don’t create this file.

Worktree uses wrong venv (parent project’s venv)

This happens if git toplevel detection fails. Check:
Should return my-project-worktree, not my-project. If returning the wrong path, your worktree setup is broken:

Summary

Worktree workflow checklist

  1. ✅ Create worktree: git worktree add ../my-project-feat feat/new
  2. ✅ Open files in Claude Code (LSP won’t work yet)
  3. ✅ Create venv: cd ../my-project-feat && uv sync
  4. ✅ Verify pyvenv.cfg: cat .venv/pyvenv.cfg
  5. Close and reopen files in Claude Code
  6. ✅ LSP features now work — no restart needed
Best practice: Create .venv before opening files in Claude Code. This avoids the reopen step entirely.