pyright-lsp plugin: `venvPath`/`venv` in `[tool.pyright]` not honored, producing `reportMissingImports` false positives
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-severityreportMissingImports. - [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
- Project layout:
````
pyproject.toml
.venv/lib/python3.13/site-packages/sphinx/...
requirements/conf.py
pyproject.tomlcontains:
``toml``
[tool.pyright]
venvPath = "."
venv = ".venv"
exclude = ["data", "benchmarks", ".venv"]
requirements/conf.pyhasfrom sphinx.util import logging(sphinx is in adocsdependency group, only installed under.venv/, not the system Python).- 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 underTYPE_CHECKING, or proposing dependency edits. None of these are real fixes; the imports already work and the project's actual checker (ty, plussphinx-build -W) is green. - Distinct from #26634: that issue is about hint-severity
DiagnosticTag.Unnecessarybeing promoted. Filtering by severity doesn't help here — these are honest-to-goodness pyrighterrors 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.py→0 errors. (venvPath/venvhonored.) - 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:
- Launch
pyright-langserverwith the project root as cwd (or pass--project <path>/initializationOptions.pythonPathif applicable) so pyproject.toml's[tool.pyright]is loaded the same way as the CLI. - Pre-resolve the project's Python interpreter (e.g.
.venv/bin/pythonwhen a.venvis detected) and pass it to the LSP server viapython.pythonPath/python.venvPathinitialization 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.docsfor sphinx + sphinx-needs; standarduv sync --group docsto populate.venv.
References
- #26634 — related plugin, different symptom (hint-tag promotion vs. wrong-env import resolution).
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗