/code-intelligence:python-lspfrom code-intelligence
Semantic Python code queries via pyright LSP: go-to-definition, find-references, hover types, diagnostics, symbol outlines, and project-wide symbol search. Use when tree-sitter or ripgrep cannot resolve bindings or infer types.
Ships in code-intelligence. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
A thin, dependency-free Python client that owns the LSP lifecycle against
pyright-langserver --stdio and exposes high-value semantic queries.
Why, over tree-sitter / ripgrep: tree-sitter gives a CST — structural queries, call-site enumeration by name. It cannot do name resolution, type inference, or cross-file binding. ripgrep matches text, so it false-positives on shadowed / same-named symbols. pyright resolves bindings. This client is that semantic overlay.
The client bootstraps pyright on first use. Run the bootstrap explicitly, or
let LSPClient do it via ensure_pyright():
sh /mnt/skills/user/python-lsp/scripts/bootstrap.sh
# or, equivalently, the one-liner it wraps:
command -v pyright-langserver >/dev/null || uv tool install pyright
pyright wheels vendor the langserver JS bundle and run it on system node —
no npm install, no separate fetch when node is present. Measured cold (caches
wiped): uv tool install pyright ~0.7s, first working server ~1.8s total; warm
sub-second.
Node prerequisite. The clean path assumes system node (v18+) is present.
With no node, pyright-python falls back to downloading node from nodejs.org,
which may be blocked in locked-down containers. The bootstrap detects node and
fails loudly (exit 1, clear message) rather than hanging.
LSP=/mnt/skills/user/python-lsp/scripts/lsp_client.py
python3 $LSP bootstrap # ensure pyright installed
python3 $LSP <root> definition <file> <line> <col>
python3 $LSP <root> references <file> <line> <col>
python3 $LSP <root> hover <file> <line> <col>
python3 $LSP <root> diagnostics <file>
python3 $LSP <root> symbols <file> # documentSymbol outline
python3 $LSP <root> wsymbols <query> # workspace/symbol search
Positions are zero-based line/character (LSP spec). <file> is relative to
<root> or absolute.
The scripts/ module lands on the boot .pth, so it is importable directly.
import sys; sys.path.insert(0, "/mnt/skills/user/python-lsp/scripts")
from lsp_client import LSPClient
with LSPClient("/path/to/repo") as c: # context manager reaps the subprocess
c.open_all("pkg/service.py", "pkg/models.py")
c.wait_for_index() # REQUIRED before querying — see below
defs = c.definition("pkg/service.py", 4, 8) # -> [Location], follows imports
refs = c.references("pkg/models.py", 8, 4) # -> [Location], binding-resolved
typ = c.hover("pkg/service.py", 4, 4) # -> "(variable) u: User"
diags = c.diagnostics("pkg/bad.py") # -> [diagnostic dicts]
outln = c.document_symbols("pkg/models.py") # -> [SymbolInfo], file outline
hits = c.workspace_symbols("User") # -> [SymbolInfo], project-wide
Location has .path, .start_line, .start_char, .end_line, .end_char
(all zero-based) and .as_dict(). Convert 1-based UI input with
Position.from_one_based(line, col).
The root you pass is split into two roles. Relative <file> arguments resolve
against it (call that the scope), but pyright is rooted at the enclosing
project root — by default LSPClient climbs out of any package the scope
sits inside (every ancestor with an __init__.py) via find_project_root. This
is what makes a query scoped to a sub-package (scipy/optimize) still resolve
the project's own absolute imports (from scipy.optimize._x import Y); without
it, references silently undercount — same blindness as a text grep, opposite
direction. The promotion is announced on stderr. Pass auto_root=False to pin
pyright at the scope verbatim.
| Method | Returns | Notes |
|---|---|---|
definition(file, line, col) | list[Location] | Go-to-definition across files/imports. |
references(file, line, col) | list[Location] | Binding-resolved — the win over ripgrep. Excludes same-named, unrelated symbols. |
hover(file, line, col) | str | None | Inferred type / signature string. |
diagnostics(file) | list[dict] | pyright type/error diagnostics for the file. |
document_symbols(file) | list[SymbolInfo] | One file's outline (classes/functions/methods); nesting via .container. |
workspace_symbols(query) | list[SymbolInfo] | Project-wide fuzzy symbol search. Empty query = every symbol (expensive). |
SymbolInfo has .name, .kind (int), .kind_name (e.g. "Class"), .location (a Location), .container, and .as_dict().
wait_for_index() blocks on
pyright's $/progress begin/end cycle (with a diagnostics-arrival fallback).
Always call it after did_open / open_all and before any query.workspace.configuration or workspace.workspaceFolders.
If the client claims either capability, pyright defers all analysis until
the corresponding negotiation completes — the server starts its service
instance and then goes silent (no diagnostics, no progress, queries hang).
start() advertises neither, so pyright uses its defaults and analyzes open
files immediately — no didChangeConfiguration nudge needed. Relevant if you
reimplement the lifecycle or add capabilities. (Bisected against the fixture;
workspace.symbol is safe to advertise.)stop()) so
sessions don't leak pyright-langserver processes. stop() sends
shutdown + exit, then waits/terminates/kills as needed.did_open their target file, but
for cross-file references open all relevant files first so pyright has
built their models.LSPClient auto-detects this (climbs out of the
enclosing package; see find_project_root) and prints the promotion to
stderr; auto_root=False opts out. This was a live silent-undercount bug:
--refs ScalarFunction over scipy/optimize returned 3 references rooted at
the sub-package vs 30 rooted at the project root.cd /mnt/skills/user/python-lsp
python3 -m pytest tests/test_lsp_client.py -v
Round-trips against tests/fixture/ (a small multi-file package): definition
follows an import, references excludes an unrelated same-named symbol, hover
returns an inferred type, diagnostics flags an intentional type error, the
indexing-wait is verified deterministic, and subprocess cleanup is checked for
orphans.
CHANGELOG.md (opens in a new tab)scripts/bootstrap.sh (opens in a new tab)scripts/lsp_client.py (opens in a new tab)tests/fixture/bad.py (opens in a new tab)tests/fixture/pkg/__init__.py (opens in a new tab)tests/fixture/pkg/models.py (opens in a new tab)tests/fixture/pkg/other.py (opens in a new tab)tests/fixture/pkg/service.py (opens in a new tab)tests/test_lsp_client.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
14 skills in this plugin
/assessing-impactPre-change blast-radius report for a symbol or file. Walks tree-sitting references, augments with a plain-text scan over non-parsed files (configs, plain docs), and clusters affected sites by feature (`_FEATURES.md`) or top-level package. Use when about to refactor, rename, or delete something in a repo you don't own — "what breaks if I change `validateUser`", "who calls this", "is this safe to remove", "where is this used", "blast radius", "impact analysis". This is the CONVERGENT pre-change risk skill — for "what is this repo?" use exploring-codebases; for "where is X?" use searching-codebases./declaring-invariantsFind tests that enumerate a domain by copying it, and declare the invariants a codebase depends on. Reports where a parametrize list, for-loop, or it.each iterates a hand-written subset of a dict/set/tuple/Enum that exists in the source, and names the members nothing covers. Use when reviewing tests, when a module gains a name-to-thing table, registry, enum, or dispatch map, before trusting a green suite as evidence a domain is covered, or when asked "is this test actually total", "does anything cover X", "what does this repo guarantee", "which invariants do we declare". Also for vacuous tests that pass over an empty collection, for a domain that has silently NARROWED (an enumeration cannot see that), and for recording the refutation that proves a claim can fail./describing-productsBuilds a product description repo for a software product - prose documents that say, feature by feature and event by event, what the user sees, what they can do, and exactly what happens when they do it, including when they stop halfway. Drafted from the code and tests, verified against the running product with hand checklists, and triaged into a bug list. Works for canvas editors, web apps, CLIs, chat products, mobile apps, and libraries or SDKs. Use when asked to "write a product description for X", "describe the user experience of X", "document how X behaves for the user", "make a behavior-spec repo", or for an event-by-event account of an app's behavior rather than API docs. Also resumes or extends an existing product description repo./exploring-codebasesFirst-encounter orientation on a repository nobody here has worked in yet. Runs a fixed five-step workflow — venv setup, tarball fetch, tree-sitting structural scan, featuring synthesis, then reasoning over the two — and yields an account of what the repo contains and how it is arranged, optionally written out as _FEATURES.md. Use for "I just cloned this", "what is this repo", "what does this do", "explore this repo", "give me an orientation", "what are the main features", "review what's new in this repo", or before starting work in a codebase you have not seen. This is the divergent what's-here skill. Route elsewhere for: a named symbol, a file's structure or a line range (tree-sitting); all callers of a Python symbol (searching-codebases); teaching a human the codebase through exercises (orienting-codebases); fetching or cloning a repo without analysing it (accessing-github-repos, cloning-project)./featuringGenerate hierarchical _FEATURES.md files that describe what a codebase DOES from a user/consumer perspective, anchored to source symbols via tree-sitting. Supports large complex codebases through feature-driven decomposition into sub-feature files. Uses a multi-pass synthesis: orientation → detail → overview rewrite. Use when someone says "what does this do", "document features", "feature inventory", "_FEATURES.md", or needs to understand a codebase's purpose before modifying it. Complements tree-sitting (structural) with semantic (why/what-for) layer./hunting-failing-inputsFinds inputs that make a parser, decoder or WGSL compute shader index out of bounds or overflow, using Z3. Use for "can this crash", "find an input that breaks this", or when fuzzing found nothing on code that reads untrusted bytes.npx claudepluginhub oaustegard/claude-skills --plugin code-intelligenceOther plugins' skills for the same job