Skip to main content

Search Algorithm

typemux-cc searches for .venv by traversing parent directories upward from the opened file, stopping at the git repository root.

Search Flow

Implementation Details

Code reference: src/venv.rs:34-96

Search Rules

1

Starting point

Parent directory of opened file (not the file itself)
2

Verification

Check existence of .venv/pyvenv.cfg (not just .venv directory)
3

Boundary

Git repository root (obtained at startup via git rev-parse --show-toplevel)
4

Direction

Traverse upward through parent directories until boundary or .venv found

Example Traversal

Search path for project-a/src/main.py:
  1. Check project-a/src/.venv/pyvenv.cfg → ❌
  2. Check project-a/.venv/pyvenv.cfg → ❌
  3. Check monorepo/.venv/pyvenv.cfg → ✅ Found

Git Toplevel Boundary

Why Git Toplevel?

The git repository root provides a natural boundary for venv search:
  • Prevents escaping workspace: Stops search from going into parent directories outside the project
  • Performance: Limits search depth in deeply nested directory structures
  • Semantic boundary: Git repo typically == project boundary

Fallback When Not in Git Repo

If git rev-parse --show-toplevel fails (not in a git repo), search continues up to filesystem root (/ on Unix, drive root on Windows). Code reference: src/venv.rs:9-32
Without a git boundary, venv search may traverse very deep directory structures (e.g., from /home/user/workspace/project/subproject/src/file.py up to /home/user/.venv). Always run typemux-cc inside a git repository for best performance.

Fallback .venv Search Order

At startup (before any files are opened), typemux-cc attempts to pre-spawn a backend with a fallback venv.

Search Order

1

1. Git toplevel

Check .venv at $(git rev-parse --show-toplevel)/.venv
2

2. Current working directory

Check .venv at $PWD/.venv
3

3. No fallback

Start without pre-spawned backend (backends created on-demand)
Code reference: src/venv.rs:98-155

Fallback Behavior Examples

Logs:

Cache Behavior and Limitations

Document Cache

When a file is opened via textDocument/didOpen, typemux-cc caches:
  • URI: file:///path/to/file.py
  • Language ID: python
  • Version: LSP document version number
  • Text: Full file contents
  • Venv: Resolved .venv path (or None if not found)
Code reference: src/state.rs:30-37

When Venv is Re-searched

Always Re-search

  • textDocument/didOpen (explicit file open)
  • Cache miss on URI-bearing request (file not in cache)

Never Re-search

  • textDocument/didChange (uses cached venv)
  • textDocument/hover on cached file (uses cached venv)
  • Any request for a file already in cache

Cache Limitations

Critical limitation: Creating .venv after opening a file will not take effect until the file is reopened.

Example Problem Scenario

1

User opens file without .venv

Cache state:
2

User creates .venv

3

Cached venv still None

Why? textDocument/hover on a cached file does not trigger venv re-search.
4

Workaround: Reopen file

New cache state:

Workarounds for Stale Cache

Cleanest solution — clears all cached state.
Pros: Guaranteed to work
Cons: Loses all open tabs, window state, etc.
Lightweight — only clears cache for specific file.In Claude Code:
  1. Close the file tab
  2. Reopen the file from file explorer
Triggers:
  • textDocument/didClose → cache entry removed
  • textDocument/didOpen → fresh venv search
Pros: No need to restart editor
Cons: Must repeat for each open file
Best practice — avoids the problem entirely.
Pros: No cache staleness
Cons: Requires discipline

Debugging Venv Detection

Enable Detailed Logging

Useful Log Queries

Manual Verification

To manually check if typemux-cc will find your .venv:

Why pyvenv.cfg?

typemux-cc checks for .venv/pyvenv.cfg (not just .venv directory) because:
  1. Standard marker: All virtualenvs created by python -m venv, virtualenv, or uv venv contain pyvenv.cfg
  2. Avoids false positives: Prevents detecting unrelated .venv directories (e.g., manually created folders)
  3. Contains metadata: pyvenv.cfg includes home path to base Python interpreter
If your virtual environment doesn’t have pyvenv.cfg, it’s likely not a standard virtualenv. typemux-cc only supports standard .venv environments (see Architecture: Non-Goals).

Performance Characteristics

  • Search time: O(depth) — typically 1-5 directory checks
  • Cache lookup: O(1) — hash map lookup by URI
  • Git toplevel: Cached on first call (single git subprocess at startup)
Venv search is not a performance bottleneck. The search happens only on file open (once per file) and is fast (< 1ms for typical depths).