pyright-lsp plugin: `venvPath`/`venv` in `[tool.pyright]` not honored, producing `reportMissingImports` false positives

Resolved 💬 2 comments Opened May 12, 2026 by tfriedel Closed Jun 28, 2026

Preflight Checklist

  • [x] I have searched existing issues — closest is #26634 (same plugin, different symptom: hint-severity tags). This is a separate code path: real error-severity reportMissingImports.
  • [x] This is a single bug report.
  • [x] Using current Claude Code.

What's Wrong?

The pyright-lsp@claude-plugins-official plugin runs pyright-langserver --stdio and injects its diagnostics into the conversation as <new-diagnostics> reminders. For projects whose dependencies live in a non-default venv path (e.g. .venv/), the LSP server does not honor venvPath / venv from [tool.pyright] in pyproject.toml, so it falls back to a system Python and reports reportMissingImports errors for packages that are actually installed.

The pyright CLI, run against the same file with the same pyproject.toml, returns 0 errors. Same pyright version (1.1.409). Different working-directory / config discovery in the LSP launch.

Reproduction

  1. Project layout:

``
pyproject.toml
.venv/lib/python3.13/site-packages/sphinx/...
requirements/conf.py
``

  1. pyproject.toml contains:

``toml
[tool.pyright]
venvPath = "."
venv = ".venv"
exclude = ["data", "benchmarks", ".venv"]
``

  1. requirements/conf.py has from sphinx.util import logging (sphinx is in a docs dependency group, only installed under .venv/, not the system Python).
  2. Edit the file in Claude Code.

Expected (matches the CLI):

$ uvx pyright requirements/conf.py
0 errors, 0 warnings, 0 informations

Actual (harness LSP injection):

<new-diagnostics>The following new diagnostic issues were detected:

conf.py:
  ✘ [Line 5:6] Import "sphinx.util" could not be resolved [reportMissingImports] (Pyright)
  ✘ [Line 8:10] Import "sphinx.application" could not be resolved [reportMissingImports] (Pyright)
  ✘ [Line 125:10] Import "sphinx_needs.data" could not be resolved [reportMissingImports] (Pyright)
</new-diagnostics>

These fire on every Edit/Write/Read of the file.

Why this matters

  • Context waste: a few hundred tokens per touch on an affected file, adding up over a refactoring session.
  • Wasted turns and bad diffs: the model sees real error-severity diagnostics and reasonably attempts to "fix" them — adding # noqa, refactoring imports under TYPE_CHECKING, or proposing dependency edits. None of these are real fixes; the imports already work and the project's actual checker (ty, plus sphinx-build -W) is green.
  • Distinct from #26634: that issue is about hint-severity DiagnosticTag.Unnecessary being promoted. Filtering by severity doesn't help here — these are honest-to-goodness pyright errors from the LSP, just based on a wrong Python env.

Root cause hypothesis

The LSP server is launched without the project root cwd (or without being told to load [tool.pyright] from pyproject.toml), so venvPath / venv are never applied and pyright resolves imports against whatever Python the language server process happens to find.

Verification:

  • CLI: cd <project> && uvx pyright requirements/conf.py0 errors. (venvPath/venv honored.)
  • LSP via plugin: 3 reportMissingImports. Same pyright binary version, same pyproject.toml.
  • Both invocations target the same file; the only variable is launch context.

Suggested fix

Either of:

  1. Launch pyright-langserver with the project root as cwd (or pass --project <path> / initializationOptions.pythonPath if applicable) so pyproject.toml's [tool.pyright] is loaded the same way as the CLI.
  2. Pre-resolve the project's Python interpreter (e.g. .venv/bin/python when a .venv is detected) and pass it to the LSP server via python.pythonPath / python.venvPath initialization options.

Workaround

Disable the plugin in .claude/settings.local.json per project:

{
  "enabledPlugins": {
    "pyright-lsp@claude-plugins-official": false
  }
}

This works but loses pyright feedback entirely, which is otherwise useful — so it's not a fix, just a mute button.

Environment

  • Claude Code: 2.1.139
  • Pyright (CLI tested): 1.1.409
  • OS: Ubuntu 6.8.0-111-generic
  • Python: project venv 3.13 (created via uv)
  • Project uses a uv dependency-groups.docs for sphinx + sphinx-needs; standard uv sync --group docs to populate .venv.

References

  • #26634 — related plugin, different symptom (hint-tag promotion vs. wrong-env import resolution).

View original on GitHub ↗

This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗