claude-code - 💡(How to fix) Fix pyright-lsp plugin: `venvPath`/`venv` in `[tool.pyright]` not honored, producing `reportMissingImports` false positives

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

  • 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.
  • 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

  • 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.

Fix Action

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.

Code Example

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

---

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

---

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

---

<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>

---

{
  "enabledPlugins": {
    "pyright-lsp@claude-plugins-official": false
  }
}
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • 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.
  • This is a single bug report.
  • 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
  2. pyproject.toml contains:
    [tool.pyright]
    venvPath = "."
    venv = ".venv"
    exclude = ["data", "benchmarks", ".venv"]
  3. requirements/conf.py has from sphinx.util import logging (sphinx is in a docs dependency group, only installed under .venv/, not the system Python).
  4. 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).

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING