# What happens when LSP is made to wait before answering: a post-hoc experiment, discussion, and my advice for Claude Code users

> When the agent is told to wait 15 seconds and query again after an incomplete lookup, LSP returns the full answer every time, and the cost of the rename task also falls back below baseline; but the agent still checks the answer again with grep. This post covers the post-hoc experiment, the overall discussion and practical advice, and ends with a method list and a note on the data.

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


[The previous post](https://wizerdbache.com/en/notes/lsp-agents-results/) concluded that on current Claude Code, the first LSP query almost always hits a cold start and returns only the definition itself. This post answers the next question: **if LSP waits for indexing to finish before answering, how much can it really help?**

To be clear, this is a **post-hoc exploration**. It was designed after I had seen the formal results, so its numbers can only answer new questions; they cannot be used to revise the conclusions of the previous post. As before, I committed the design and expectations to git before running anything.

## Summary

- **Design**: Group W = plugin on, plus the instruction “prefer LSP; if findReferences returns only the definition, first `sleep 15` and then query again.” Only the large tasks H1 and H2 were run, 5 runs each, compared with groups B and N from the previous post.
- **LSP did answer**: in the 7 runs that used LSP, the first query returned 1 result every time; after waiting 15 seconds, the retry returned 37 results, which is the correct answer.
- **Rename task (H2) cost fell back below baseline**: group W used 29% fewer tokens than group N (p = 0.008) and cost 7% less than the baseline group (p = 0.032). Neither p value is corrected for multiple comparisons, and group W ran about a day after B and N, so these results are exploratory.
- **No difference on the call-site task (H1)**.
- **The agent does not fully trust LSP**: even with the complete list, it still checked again with grep in 6 of the 7 runs.

## 1. Post-hoc experiment: group W

### 1.1 Did LSP return the complete answer

**Table 1: LSP usage in group W**

| Task | Runs using LSP | Queries | Results returned per query | Still ran text search after getting the full list |
|---|---|---|---|---|
| H1 | 3/5 | 6 | 1 → 37 (× 3 runs) | 3/3 |
| H2 | 4/5 | 8 | 1 → 37 (× 4 runs) | 3/4 |

Retries succeeded in 7 of 7 cases, so the cold-start explanation was confirmed again, seven times over.

But 3 runs did not use LSP at all, even though the prompt explicitly asked for it. Group N in the previous post had the same problem. For the agent, the tool guidance in the prompt is a “suggestion,” not a “requirement.”

### 1.2 Cost

**Table 2: Group W versus groups B and N (median ratios; exact two-sided Mann-Whitney U; uncorrected)**

| Task | Metric | W/B | p | W/N | p |
|---|---|---|---|---|---|
| H1 | Total tokens | 1.05 | 0.548 | 0.94 | 0.841 |
| H1 | Cost | 1.09 | 0.421 | 1.01 | 0.841 |
| H1 | Wall-clock time | 0.90 | 0.548 | 0.78 | 0.452 |
| H2 | Total tokens | 0.95 | 0.310 | 0.71 | 0.008 |
| H2 | Cost | 0.93 | 0.032 | 0.84 | 0.008 |
| H2 | Conversation turns | 0.91 | 0.103 | 0.77 | 0.008 |
| H2 | Wall-clock time | 1.00 | 0.889 | 0.81 | 0.008 |

On H2, **all** 5 W runs used fewer total tokens than all 5 N runs (Cliff's δ = −1.00).

**Waiting 15 seconds did not lengthen the total time.** On H2, the median wall-clock time matched the baseline group (71.8 seconds) and was 19% lower than group N. The extra waiting was offset by the conversation turns that were saved.

### 1.3 Why renaming benefited and call-site search did not

- **Renaming (H2)**: with the complete list of 37 entries, the agent could rename all 36 sites in one pass, so fewer back-and-forth turns were needed (median 10 turns, versus 13 for group N).
- **Finding call sites (H1)**: the task itself is only about producing a list. Even after getting LSP's list, the agent checked it again with grep plus a small script, which amounts to doing the work twice, so there was nothing to save.

## 2. Overall discussion

### 2.1 Gap between expectations and actual results

Before running anything, I listed six possible benefits. The table below shows the outcome of each after everything was checked:

| Benefit type | Expectation before running | Actual (formal experiment + group W) |
|---|---|---|
| Correctness | On large tasks, groups without LSP would miss items | **76/76 correct**, with no difference across the three conditions |
| Token cost | Using LSP would save tokens | When a cold start was hit (group N), **12–34% more** (not significant); when it was avoided (group W), the rename task saved a little and the call-site task did not change |
| Time | Same direction as tokens | Same direction; the extra 15 seconds of waiting in group W was offset |
| Self-verification | With automatic diagnostics, fewer Pyright runs | Little difference; every group ran Pyright itself |
| Adoption rate | If not told to use it, it would not be used | ✔ 0 uses in 22 runs; when asked, about 2 in 10 runs on large tasks still did not use it, and small tasks T1 and T3 never did |
| Downside cost | Larger prefix, more noise | Prefix difference of 0.02%; the main downside is the “fallback after an unhelpful query” |

### 2.2 Why the “LSP saves tokens” claim did not hold

The common claim is that one LSP query can replace reading many files, so it saves tokens. This experiment turned up three reasons it does not hold:

1. **Reading files is not expensive to begin with.** 83–93% of total tokens are cache reads, meaning the earlier conversation is re-read on every turn. What determines cost is “how many turns the conversation ran,” not “how many files were read.”
2. **The agent does not verify less just because LSP is available.** Even with LSP's list, it checked again with grep in 6 of 7 runs. Whether it saves anything depends on whether the agent trusts the tool, not on how accurate the tool is.
3. **Fully typed code lets types be inferred without LSP.** Every call in my tasks carries a type annotation, so the agent can work from the annotations. In real projects without type annotations, or that rely on dynamic dispatch, text search is harder and LSP may be worth more. This experiment did not test that case.

### 2.3 Why the “fewer hallucinations” claim was not confirmed either

Accuracy was 100% under every condition, so there was no room to see whether LSP reduces errors. Looking at it the other way, the “1 result” returned during a cold start is in fact a **plausible-looking wrong answer**. If the agent accepted it at face value, for example by renaming only the definition, the outcome would be worse. In this experiment the agent always re-verified on its own, so nothing went wrong; but this also shows that LSP cannot be treated as a source of truth that needs no verification.

### 2.4 Methods worth taking away from this experiment

- **Run a pilot first.** The pilot showed the agent would not use LSP unprompted, and that is what led me to add group N.
- **Write down expectations and the analysis method before running.** This let me catch, before the runs, the error of “n=4 with multiple-comparison correction can never be significant,” and it made it possible to report honestly that “the results went against expectations.”
- **When results fall short of expectations, look for the mechanism before concluding.** Looking only at the numbers, the conclusion would have been “LSP does not help”; only after intercepting the messages did it become clear that “LSP's answer arrives too early.”
- **The grader has to be able to prove itself.** Every task was calibrated against a “did nothing” version and a “done correctly” version, and the answer keys for the H tasks were also independently verified with Pyright.

## 3. Advice for Claude Code users

The advice below applies only to conditions close to this experiment: Windows, Claude Code 2.1.323, Python, and fully type-annotated code.

1. **You do not need to install an LSP plugin specifically to save tokens or improve accuracy.** Under these conditions, neither benefit could be measured.
2. **If it is already installed, you can keep it for automatic diagnostics.** After the editing tool changes a file, it automatically reports type errors; during the pilot it caught a call site that had been missed. But keep in mind:
   - Changes made by script do not trigger it.
   - Partway through a change, temporary false positives may appear.
3. **If you ask the agent to use LSP to find references, always include a retry instruction**, for example “if it returns only the definition, wait 15 seconds and query again.” Without one, cost tended to be higher in this experiment (not significant).
4. **Start Claude Code from the project root directory.** Otherwise, Pyright cannot resolve the project's own imports.
5. **Do not treat LSP's output as the final answer.** During a cold start, it can return a result that looks reasonable but is incomplete.

This advice will change with Claude Code versions. If the cold-start problem is later fixed (for example, by waiting for indexing to finish before responding), item 3 will no longer be needed.

## 4. Appendix: Methods and data overview

### 4.1 Experiment scale and cost

| Stage | Runs | Cost (USD, reference values) |
|---|---|---|
| Pilot (n=1, small task) | 6 + 2 probes | 3.56 |
| Main experiment (pre-registered) | 66 | 35.51 |
| Mechanism diagnosis (intercepted messages) | 1 | 0.40 |
| Group W (post-hoc exploration, pre-registered appendix) | 10 | 5.79 |
| **Total** | **85** | **45.26** |

### 4.2 Method list

| Item | Approach |
|---|---|
| Group switching | Each run passes a settings file via `--settings`, switching only the plugin on/off setting; global settings are not changed |
| Prompt | Passed via standard input; the SHA-256 of each run's prompt is recorded; groups N and W each append a fixed block of text |
| Prefix interference check | Each of two groups replied “OK,” and the opening tokens were compared: 65,747 vs. 65,762 |
| Tasks | Generator with a fixed random seed; the generator marks the standard answers, and the H tasks were additionally verified independently with Pyright (changing only the answer line → 0 errors; changing only the definition → 36 errors) |
| Grader calibration | Each task was calibrated in both directions using a “did nothing” version and a “done correctly” version, and the values the judgment relied on were recorded |
| Pre-registration | The main experiment and group W were each committed to git before running, and not modified afterward |
| Primary test | Exact two-sided Mann-Whitney U (enumerating all group assignments); Holm correction; α = 0.05 |
| Effect size | Median ratio, Cliff's δ |
| Exclusion rules | Non-zero CLI exit code, `is_error` reported, or hitting the budget cap (0 runs were excluded in practice) |
| Token source | The `usage` field in each Claude Code run's result event, not calculated from transcripts |
| Mechanism diagnosis | A minimal self-written LSP client queried Pyright directly; an intermediary proxy plugin intercepted every message Claude Code sent |

### 4.3 Known measurement flaws

The pre-registered analysis script counted LSP calls from the transcripts. Transcripts record the same tool call more than once, so the count was overstated. Following the principle of “not modifying the analysis script after results are published,” I did not go back and change it. Instead, I recalculated using the deduplicated event stream, and the LSP counts in this post are the deduplicated numbers. The token counts used in the primary test are not affected.

### 4.4 Data and code

The raw event streams for all runs, the grading results, the task generator, the grader, the analysis scripts, and the pre-registration documents are kept in my local experiment folder (under git version control), and are not public at this time.

## Sources

- [Code intelligence plugins (Claude Code official documentation)](https://code.claude.com/docs/en/plugins/code-intelligence) (How Claude Code's LSP plugin is installed and works)
