# How to fairly test whether “an AI agent with LSP installed is better”: experiment design

> Installing a plugin does not mean it gets used. This note records how I designed the experiment (three groups that each differ by one thing, two task sets with deliberate traps, a scorer validated first, and predictions and reading rules written before the runs), and it also caught a design error that made the main test impossible to reach significance.

Published 2026-11-17 · Updated 2026-11-17 · URL https://wizerdbache.com/en/notes/lsp-agents-experiment-design/


The previous post covered what LSP is. This one covers how I tested it.

The question sounds simple: “If Claude Code has the LSP plugin turned on, is writing Python any better?” But if you just run a few comparisons, the results almost always get mixed up with other factors: the tasks are too easy, the prompts differ, and each run takes a different path to begin with. So most of this post is about **how to rule out these confounds**.

The numbers below were measured on my own Windows PC on November 14 to 15, 2026.

## Conclusion first

- **A trial run first showed the agent never used it**: across 3 turns with the plugin on, the agent never once called an LSP tool on its own. That led me to add a third group: one explicitly told to use it.
- **The three groups each differ by only one thing**: baseline, plugin only, and plugin plus a prompt nudge.
- **Tasks should make text search go wrong**: small tasks are fine with grep and do not show the value of LSP, so I also built a large set of tasks with deliberate ambiguity.
- **The scorer proves itself first**: for each task, I confirmed that “did nothing” fails and “did it correctly” passes, before running anything.
- **Expectations written before the runs**: I wrote down which benefits to measure, what I expected to see, and what recommendation each outcome would map to, then committed to git and did not change them after seeing results. This step also caught a statistical design error.

## 1. Environment

| Item | Version |
|---|---|
| Operating system | Windows 11 |
| Claude Code | 2.1.323 (command line, headless mode `-p`) |
| Model | Opus, effort medium |
| Language server | Pyright 1.1.414 |
| Plugin | Official pyright-lsp 1.0.0 |

## 2. Installation: three steps, two pitfalls

1. First install Pyright itself. The plugin only says it “needs to start `pyright-langserver --stdio`” and does not include Pyright:

   ```powershell
   npm install -g pyright
   ```

2. Install the plugin:

   ```powershell
   claude plugin install pyright-lsp@claude-plugins-official
   ```

3. Restart Claude Code. A `LSP` tool will appear in the tool list.

Two pitfalls:

- **The LSP tool is lazily loaded.** It does not appear directly in the agent's tool list; the agent has to load it with the search tool before it can be used. As the next sections show, this matters a lot for the results.
- **Open Claude Code from the project root.** In a session I had opened from a different folder, I edited that project's files, and Pyright reported that every import within the project itself failed to resolve. The experiment runs all started from the project root, so this did not come up. (When I searched for references that time, I found only the definition itself, and I thought the root directory was the problem; the next post shows the same thing happens from the correct root, and the cause is cold start.)

## 3. Trial run: the agent did not use it

I first ran a small set of tasks, once with the plugin and once without, for 6 turns in total. The results:

- **Both groups got every task right**, because the tasks were too easy.
- **In the group with the plugin, the agent never once called an LSP tool on its own.** It finished everything with grep and file reads.
- **What actually made a difference was “automatic reporting after edits”**: in the rename task, after the agent edited one file with the edit tool, Pyright automatically reported that “`Store` has no `load` attribute,” flagging a call site it had not updated yet.
- **But if the agent rewrote all the files at once with a script, it got no reports**: automatic diagnostics fire only when files are changed with the edit tool.

So what “plugin on” actually tested was mainly automatic diagnostics. To find out whether the LSP tool itself is valuable, I would need a separate group where it is actually used.

## 4. Three groups: each differs by one thing

| Group | Plugin | Prompt | What it measures |
|---|---|---|---|
| B (baseline) | Off | Original task wording | Control group |
| L | On | Identical to B, word for word | Effect of “just having it installed” |
| N | On | Original wording plus one added line: “Prefer the LSP tool for finding definitions and references” | Effect of “actually using it” |

A few deliberate choices:

- **B and L differ by only one settings file.** The plugin switch is toggled through the settings file passed with `--settings`; global settings are left untouched.
- **Both groups have Pyright installed.** If the agent in group B wants to, it can run `pyright` itself in the terminal to check. So what is measured is the effect of the “plugin,” not the effect of “having Pyright.”
- **Checking that the prefix was unchanged.** I first had each group reply “OK,” then compared the token count at the start of the conversation: 65,747 vs. 65,762, nearly identical. This matters because in my earlier experiments I found that merely removing a few tools with a parameter cut the opening tokens by about 10,000 (about 23% relative to the group with no tools removed), which could easily be misread as “this group is cheaper.”
- **The prompt is passed in via standard input (stdin), and a hash is recorded for each turn.** When Windows PowerShell 5.1 passes arguments containing quotes, it can silently truncate the content.

## 5. Tasks: making text search go wrong

### Small tasks (T1–T3)

A small package of about 150 lines, with three tasks:

- **T1 Find call sites**: list every line that calls a given function. Traps include aliased imports, a different function with the same name, and the same name appearing in strings and comments.
- **T2 Rename**: rename `Store.load` to `Store.fetch`, but two other classes also have `load`, and those must not be touched.
- **T3 Type propagation**: change one function's return type to `Decimal`, then fix every affected call site.

The trial run already showed that grep is enough for this set. It stays in as a control for the “simple case.”

### Large tasks (H1, H2)

Using a generator with a fixed random seed, I built a package of 41 files and 1,111 lines:

- **All 14 classes have a `load` method.** The target is only `Ledger.load`, plus its subclass `AuditLedger`, which inherits it.
- **The service layer has 120 `.load(` calls, of which only 36 are to the target.**
- **Variable names do not reveal types**: they are names like `h`, `obj`, and `item`, never something obvious like `ledger.load`.
- **Another 64 places contain the string “ledger.load” in comments and strings**, as distractors.
- Calls take four forms: parameters with type annotations, objects created inside a function, return values from factory functions, and attributes on a shared `Context` object (the attribute names also do not reveal types).

Two tasks:

- **H1**: list every call line to `Ledger.load`.
- **H2**: rename `Ledger.load` to `Ledger.fetch`, without touching `load` in other classes, and without getting around it with things like `type: ignore`.

### Verifying the reference answers independently with Pyright

Every call in the H tasks has type annotations, so Pyright itself serves as an independent judge:

- Renaming only the 36 lines in the reference answer, plus the definition: Pyright reports **0 errors**, meaning the answer neither adds nor misses any lines.
- Changing only the definition, with no call sites touched: Pyright reports **36 errors**, exactly matching the 36 lines in the answer.

This means I do not have to rely only on my own generator.

## 6. The scorer proves it works first

Before running any experiment, for each task I prepared a “did nothing” version and a “done correctly” reference solution, confirmed that the scorer can tell them apart, and recorded the actual values the judgment was based on, not just “pass / fail”:

| Task | Did nothing | Done correctly |
|---|---|---|
| T1 | Recall 0.0 | Precision and recall both 1.0 |
| T2 | 1 hidden test fails | All 8 pass |
| T3 | 3 fail | All 8 pass, Pyright 0 errors |
| H1 (list all `.load(` with grep) | Recall 1.0, but precision 0.3 (84 false positives) | 1.0 / 1.0 |
| H2 (change definition only) | Pyright 36 errors | 0 errors |

For the “did nothing” version of H1, I deliberately used the most naive grep strategy and listed every `.load(`. It found all of them, but seven out of ten were wrong. This is where LSP should, in theory, win.

## 7. Writing down expectations before running

I split the benefits I wanted to measure into six categories. For each, I wrote down the expected result, committed to git, and only then started the runs:

| Benefit type | How it is measured | My expectation |
|---|---|---|
| Correctness | Pass rate, precision, recall | Small tasks all correct; the baseline group may miss some on large tasks |
| Token cost | Total tokens reported by Claude Code itself | **Main hypothesis**: on large tasks, the group told to use LSP is cheaper |
| Time and turns | Wall-clock time, conversation turns | Same direction as tokens |
| Self-verification cost | Number of times the agent runs Pyright itself | Groups with automatic diagnostics will run it less |
| Adoption rate | Number of LSP calls per turn | Without being told to use it, it will almost never be used |
| Negative costs | Prefix differences, diagnostic noise, tool failures | Prefix difference under 1%; if LSP output is too verbose, it could cost more |

I also wrote down in advance the recommendation for each of the four outcomes:

- **Only the “told to use it” group is better**: add a line to the instruction file: “For finding references in Python, prefer LSP.”
- **The “just installed” group is already better**: keep the current setup.
- **All three groups are about the same**: keep only automatic diagnostics, or turn it off.
- **Using LSP is actually worse**: turn it off, or enable it only in large projects.

### An error caught before the runs

The original design had each group run 4 times. There were two main tests, one per task, using the exact Mann-Whitney U test, with the two p-values then adjusted for multiple comparisons using the Holm method.

While writing the analysis code, I first tested it on inputs with known answers, and it turned out that: **with 4 runs against 4 runs, the smallest possible p-value is 0.0286; multiplied by the Holm adjustment factor of 2, that gives 0.057, which can never fall below 0.05.** In other words, no matter how large the difference, the main tests could never be significant.

So the large tasks were changed to 5 runs per group, giving a smallest p-value of 0.0079 and 0.016 after adjustment. The reason for this change is also recorded in the pre-registered document.

If I had not written the analysis method down before running, this error would likely only have been discovered after finishing 60 turns and spending the money.

## 8. Scale and limitations

The formal experiment has 66 runs in total:

- Large tasks: 2 tasks × 3 groups × 5 runs = 30 runs.
- Small tasks: 3 tasks × 3 groups × 4 runs = 36 runs.

The trial runs are not counted in the formal results, because the design was changed after looking at the trial runs.

What this experiment can show is limited:

- **The tasks were designed by hand**: they have exact standard answers, but they are not real projects.
- **Only one model, one effort level and one computer were tested.**
- **Token counts come from Claude Code's own reports.** Costs are reference values converted at official prices, not actual bills.
- **The N groups had an extra prompt**: its effect is the sum of “plugin plus instruction,” and the two cannot be separated.

The next post covers the results.

## Sources

- [Code intelligence plugins (Claude Code official documentation)](https://code.claude.com/docs/en/plugins/code-intelligence) (Plugin requires a separate language server install; reports diagnostics after edits)
- [Pyright (npm package page)](https://www.npmjs.com/package/pyright) (Version used in the experiment: 1.1.414)
