AI agent with LSP installed: results from 66 runs, zero difference, and a 0.5-second timing gap
The pre-registered 66-run experiment: all three groups answered correctly, and enabling the plugin did not make the agent cheaper. Telling it to use LSP actually cost 12–34% more tokens (not statistically significant). Digging further showed that Claude Code always sent its queries before Pyright had finished indexing, and all 13 queries returned only the definition itself.
The previous post covered how the experiment was designed. This one reports the results, written in the style of a paper: abstract first, followed by a summary of methods, results, mechanism analysis, and limitations. Every number can be traced back to the raw record of a single run.
Abstract
Question: With the Python language server plugin (pyright-lsp) enabled in Claude Code, can the AI agent be more accurate on coding tasks, or cheaper at the same accuracy?
Method: three-way comparison: plugin off (B), plugin on (L), and plugin on with an instruction to use LSP (N). There are 5 tasks in total: 3 small package tasks, plus 2 large tasks deliberately designed so that text search would be ambiguous (14 classes each have a method of the same name, and only 36 of the 120 calls are the target). Each group ran 5 times on the large tasks and 4 times on the small ones, 66 runs in total. The primary tests were pre-registered and committed to git before the runs started: on the large tasks, the total token count of N versus B, using an exact Mann-Whitney U test, with the two p-values adjusted by Holm correction.
Results:
- All 66 runs got the correct answer.
- Neither primary test is significant. On H1, group N used 1.12 times the tokens of group B (p = 0.42); on H2 it was 1.34 times (p = 0.056, 0.11 after correction), in the opposite direction to the hypothesis.
- With the plugin on but no instruction, the agent used LSP in 0 of 22 runs.
Mechanism: the 13 queries made under the LSP instruction each returned only the definition itself (1 result). After intercepting the messages between Claude Code and Pyright, I found that Claude Code did send the project root correctly, but sent its query in the same millisecond it opened the file. At that point Pyright had not finished indexing the project, and it returned 1 result after 0.53 seconds. About 26 seconds later, the same query returned 37 results, which is the correct answer.
Conclusion: in this version and environment, the value of the LSP tool was offset by a cold-start timing gap. The agent paid extra cost for these ineffective queries, and in the end still fell back to text search.
1. Method summary
The full design is in the previous post; here I list only what is needed to read the results.
| Item | Setting |
|---|---|
| Environment | Windows 11; Claude Code 2.1.323 (headless mode); Opus, effort medium; Pyright 1.1.414; pyright-lsp 1.0.0 |
| Groups | B: plugin off. L: plugin on, prompt identical to B word for word. N: plugin on, prompt with an extra passage “prefer LSP for finding definitions and references” |
| Tasks | T1 find call sites, T2 rename, T3 type propagation (small, about 150 lines); H1 find call sites, H2 rename (large, 1,111 lines, ambiguous) |
| Runs | H tasks n=5 per group; T tasks n=4 per group; 66 runs in total, 0 excluded |
| Correctness | T1, H1: identical to the reference set. T2, T3: hidden tests passed. H2: 0 Pyright errors, without getting around them with type: ignore or similar. The reference answers for the H tasks were also verified independently with Pyright |
| Cost metrics | Total tokens (from the result event Claude Code reports itself), cost (reference values converted from official pricing), conversation turns, wall-clock time |
| Primary test | Total tokens, N vs B, on H1 and H2; exact two-sided Mann-Whitney U; Holm correction; α = 0.05 |
| Run order | Within each repetition, the order of the three groups rotated, to reduce the effect of time drift |
2. Results
2.1 Correctness
All 66 runs passed. The three groups showed no difference across the five tasks.
I had expected that group B on the large tasks would miss some calls because of the ambiguity, but it did not. The run logs show that group B’s agent first listed all .load( calls, then read the type annotations one by one, or wrote a small script of its own to work out the types, and in this way found all 36 sites. Every call in the tasks has a type annotation, which made it feasible to infer types without LSP. This point is also discussed in the limitations in Section 4.
2.2 Cost
Table 1. Total tokens: median [Q1–Q3] (range)
| Task | B (off) | L (on) | N (on + instruction) |
|---|---|---|---|
| H1 | 508k [499k–566k] (455k–631k) | 465k [461k–498k] (380k–515k) | 567k [532k–663k] (450k–735k) |
| H2 | 632k [619k–703k] (615k–882k) | 669k [660k–721k] (629k–848k) | 844k [814k–893k] (803k–955k) |
| T1 | 270k [269k–271k] | 270k [270k–271k] | 270k [269k–306k] |
| T2 | 570k [569k–570k] | 571k [570k–571k] | 613k [579k–648k] |
| T3 | 350k [328k–370k] | 277k [276k–312k] | 433k [329k–577k] |
k = thousand tokens.
Table 2. Cost (USD), conversation turns, and wall-clock time: median (range)
| Task | Group | Cost | Turns | Wall-clock (s) |
|---|---|---|---|---|
| H1 | B | 0.535 (0.523–0.557) | 8 (6–9) | 60.4 (56.1–74.9) |
| H1 | L | 0.537 (0.512–0.598) | 7 (5–7) | 50.6 (48.2–70.2) |
| H1 | N | 0.578 (0.543–0.640) | 9 (6–11) | 69.4 (54.3–79.0) |
| H2 | B | 0.629 (0.618–0.670) | 11 (10–14) | 71.8 (65.5–110.0) |
| H2 | L | 0.620 (0.589–0.685) | 10 (9–12) | 72.8 (62.9–112.8) |
| H2 | N | 0.694 (0.674–0.737) | 13 (13–16) | 88.2 (81.4–99.0) |
| T1 | B/L/N | 0.393/0.395/0.394 | 4/4/4 | 34.1/43.1/46.2 |
| T2 | B/L/N | 0.544/0.552/0.572 | 17/17/20 | 64.8/69.2/63.3 |
| T3 | B/L/N | 0.477/0.440/0.546 | 6/4/14 | 65.8/60.0/77.2 |
2.3 Primary tests (pre-registered)
Table 3. Total tokens, group N vs group B
| Task | N median | B median | N/B | U | Exact p | Holm-adjusted p | Cliff’s δ |
|---|---|---|---|---|---|---|---|
| H1 | 567k | 508k | 1.12 | 17 | 0.421 | 0.421 | +0.36 |
| H2 | 844k | 632k | 1.34 | 22 | 0.056 | 0.111 | +0.76 |
Cliff’s δ ranges from −1 to +1; a positive value means the first group (N) tends to have larger values. Neither primary test is significant. The pre-registered hypothesis was that group N would be cheaper, while the observed direction was the opposite. On H2, group N was higher than group B in 22 of the 25 pairs.
Exploratory results (uncorrected, for reference only): on H2, group N had 18% more conversation turns than group B (p = 0.032) and 30% more than group L (p = 0.008).
2.4 How the agent actually used LSP
Table 4. LSP use (de-duplicated counts from each run’s event stream stream.jsonl)
| Task | L: runs that used LSP | N: runs that used LSP | Results per N query |
|---|---|---|---|
| H1 | 0/5 | 4/5 | 1, 1, 1, 1 |
| H2 | 0/5 | 5/5 | 1, 1, 1, 1, 1 |
| T1 | 0/4 | 0/4 | — |
| T2 | 0/4 | 4/4 | 1, 1, 1, 1 |
| T3 | 0/4 | 0/4 | — |
Three observations:
- Without an instruction, the agent does not use it: group L, 22 runs, 0 uses. The LSP tool is lazy-loaded and has to be loaded first with the search tool, which the agent does not do on its own.
- With an instruction, it queries once per run: 13 runs in group N used LSP, and each of them queried only once.
- All 13 queries returned only 1 result, the definition itself: the correct answer is 37 results (36 call sites plus the definition). After getting 1 result, the agent switched back to text search plus reading files, without retrying.
So the extra cost of group N comes from loading the tool, one ineffective query, falling back to the original approach, and then verifying the result again.
2.5 A caveat when reading the token numbers
Table 5. Token composition (median per cell)
| Task | Group | Cache write | Cache read | Output | Cache read share |
|---|---|---|---|---|---|
| H1 | B | 48k | 454k | 2.5k | 90% |
| H1 | N | 52k | 515k | 2.9k | 91% |
| H2 | B | 57k | 571k | 2.8k | 90% |
| H2 | N | 61k | 784k | 2.8k | 93% |
Between 83% and 93% of total tokens are cache reads: in every turn of the conversation, the model re-reads the whole preceding content, which is read from cache and therefore cheaper. So “total tokens” mainly reflects the number of turns times the length of the conversation. Most of the extra tokens in group N come from the extra turns, not from LSP returning long content; in fact each LSP return was under 80 characters.
This is also why the cost gap (H2: 0.694 vs 0.629 USD, about 1.10 times) is smaller than the total-token gap (1.34 times): under official pricing, cache reads cost less per token. If you care about the bill, cost is the more accurate measure.
3. Mechanism: why all 13 queries returned only 1 result
3.1 Pyright itself is fine
I wrote a minimal LSP client that bypassed Claude Code and talked directly to pyright-langserver over stdio. For the same large task, I queried all references to Ledger.load:
Table 6. Results of querying Pyright directly
| Client setup | Results returned |
|---|---|
| Project root set, only the target file opened, queried after waiting 3 seconds | 37 |
| Project root set, all files opened, queried after waiting 3 seconds | 37 |
| No project root set | 1 |
So Pyright itself can give the correct answer. The problem lies between Claude Code and Pyright.
3.2 Intercepting the messages Claude Code actually sent
Someone in the community reported that when Claude Code initializes LSP on Windows, the rootUri it sends is null, which would neatly explain the third row of Table 6. To check this, I built a “relay proxy” plugin: it pretended to be a language server, logged every message Claude Code sent, and forwarded it to the real Pyright. Then I ran one diagnostic run on a large task, in which the agent queried twice with a 20-second wait in between.
Table 7. Message log of the diagnostic run (time measured from the first didOpen as 0)
| Time | Direction | Message | Content |
|---|---|---|---|
| At startup | Claude Code → Pyright | initialize |
rootUri is the project root, and workspaceFolders is also set; both are correct |
| 0.000 s | Claude Code → Pyright | textDocument/didOpen |
Only the queried file was opened |
| 0.000 s | Claude Code → Pyright | textDocument/references |
Same millisecond as the file open |
| 0.532 s | Pyright → Claude Code | Response | 1 result |
| 26.3 s | Claude Code → Pyright | textDocument/references |
Same position, second query |
| 26.4 s | Pyright → Claude Code | Response | 37 results |
3.3 Interpretation
- The claim that
rootUriis null does not hold on 2.1.323. The root directory Claude Code sent was correct. - The real cause is the timing gap. After receiving the root directory, Pyright builds an index of the whole project in the background. Claude Code queried immediately after opening the file, so Pyright could only answer with what it knew at that moment, namely the one file that had been opened, and so it returned only the definition itself. Once indexing finished, the same query returned the full result. Others in the community have reported the same symptom on macOS: the first query returned only the declaration, and later queries were complete. Some have since reproduced it on Linux and Windows 11.
- The agent had no reason to doubt the result. LSP reported that it had found one reference, not that it was still indexing. From the agent’s point of view, this was an answer that looked reasonable but was in fact wrong.
The third row of Table 6 (no project root set, 1 result) only happened to produce the same number; it was not the cause of the experimental runs. I was misled by this coincidence at first, until intercepting the messages confirmed it.
3.4 My original wrong explanation
During trial runs, querying references in my own working session also returned only the definition. At the time I attributed it to “that session not having been opened from the project root”. The root in that session was indeed wrong, since Pyright reported import resolution failures; but the formal experimental runs all started from the project root and still got only 1 result. Without the intercepted messages, I would very likely have finished this post with the wrong explanation.
4. Limitations and threats to validity
| Threat | Description | Direction of effect |
|---|---|---|
| Tasks were designed by hand | Exact standard answers, but every call has type annotations, so grep plus reading files can still infer the types | May underestimate the value of LSP on real projects where types are incomplete |
| Only one model and one effort level | Opus, effort medium | Other models may use LSP more or less often |
| Only one machine and one version | Windows 11, Claude Code 2.1.323 | Cold-start behavior may change with version or platform |
| Small sample | 4-5 runs per cell | Only large differences can be detected; not significant does not mean no difference |
| The N groups had different prompts | An extra instruction was added | The effect of the N groups is the sum of “plugin plus instruction” |
| Cost is a reference value | Costs converted from list prices, not actual bills | Does not affect comparisons between groups |
| Counting flaw | The pre-registered analysis script counted LSP calls from transcripts, which included duplicates, so it overestimates; Table 4 instead de-duplicates using the event stream | Does not affect the main test, which uses the token counts self-reported by Claude Code |
5. Conclusions of this post
- On the current Claude Code (2.1.323, Windows), enabling the pyright-lsp plugin brings no measurable benefit to the agent’s correctness or cost.
- The group told to use LSP cost more (1.12 times on H1, 1.34 times on H2), but this is not statistically significant and should not be taken as a confirmed effect; the direction is consistent with the first query almost always hitting a cold start.
- LSP itself is not useless. Once indexing is complete, Pyright’s answers are fully correct; the problem lies in when the query is made.
What happens if the agent waits for indexing to finish before querying? The next post covers that in a post-hoc exploratory experiment.
Sources
- LSP tool returns silently incomplete results (cold-index race + stale file state) (community report, GitHub issue) (Same symptom on macOS, also reproduced on Linux and Windows 11)
- LSP tool passes rootUri: null during initialization on Windows (community report, GitHub issue) (Not reproduced on 2.1.323, the version used in this experiment)
- Pricing (Claude official documentation) (Cache reads are priced below regular input)
- Language Server Protocol Specification 3.17 (The initialize rootUri (marked deprecated) and workspaceFolders; Find References request)
← Previous:How to fairly test whether “an AI agent with LSP installed is better”: experiment design
Email subscriptions will open later. For now, you can follow new articles and work with RSS.