Skip to content

Commit 42003b4

Browse files
dougborgclaude
andcommitted
docs(claude): document cross-worktree LSP bleed + workaround
During the session that landed #696 / #700 / #698, the pyright LSP daemon repeatedly surfaced ``<new-diagnostics>`` reminders complaining about fields and params that existed on a sub-agent's branch but not on this worktree's branch — and vice versa. ``uv run pyright`` from the worktree was clean throughout. Cost roughly an hour of context cycles spent verifying that the warnings were phantom. Root cause is well-documented upstream: - pyright-lsp can't accept a per-call ``projectRoot`` (anthropics/claude-code#32230, closed as not planned) - LSP plugins don't receive ``rootUri`` during init (#27220) - Subagents resolve to main repo root rather than their worktree (#31546) - Session worktrees go inside the repo root by default (#49986) All four upstream issues are closed without a fix path. The local ``pyrightconfig.json`` already excludes ``.claude/worktrees`` from indexing — that prevents the LSP from reaching INTO sibling worktrees but doesn't help when the daemon is rooted at the wrong worktree to begin with. Add a new entry under "Stale-LSP common triggers" in CLAUDE.md explaining the symptom, the workaround (trust pyright CLI; don't try to fix phantom diagnostics), and links to the upstream issues so the next contributor doesn't waste cycles re-deriving the trail. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8a1cd56 commit 42003b4

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

CLAUDE.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,45 @@ The protocol when a `<new-diagnostics>` block appears:
254254
1. **Check pyright CLI on the affected file**`uv run pyright <path>`. Pyright CLI is
255255
the source of truth; the LSP can be stale (especially after generator regen,
256256
stash/pop, or rebase).
257+
257258
1. **If pyright CLI agrees**, fix it. Don't push code with pending pyright errors — CI
258259
will fail.
260+
259261
1. **If pyright CLI disagrees**, the LSP is stale. **Note it explicitly in your reply to
260262
the user** ("LSP shows X but pyright CLI is clean — likely stale after regen") so
261263
they know whether their editor needs a restart. Do NOT silently move on without
262264
verifying.
265+
263266
1. **Stale-LSP common triggers** — running `uv run poe generate-pydantic`, rebasing onto
264267
main, or stashing & popping. Pyright re-indexes lazily; the system reminder may show
265268
pre-edit state until the next save.
266269

270+
1. **Cross-worktree LSP bleed** — when a sub-agent is operating in a sibling git
271+
worktree (e.g., the repo root `/Users/dougborg/Projects/katana-openapi-client/` while
272+
your session lives in `.claude/worktrees/<name>/`), the pyright LSP daemon stays
273+
rooted at the session's *original* primary cwd and never switches when other agents
274+
enter sibling worktrees. The daemon's snapshot reflects one branch's files; your
275+
edits target another branch's files. `<new-diagnostics>` reminders then surface
276+
phantom errors that complain about fields / params that exist on one branch but not
277+
the other. Symptom: `uv run pyright <path>` from your worktree is clean while LSP
278+
keeps flagging mismatches across a wide swath of files you didn't touch.
279+
280+
**Workaround:** trust `uv run pyright <path>` from your worktree as ground truth;
281+
ignore the LSP diagnostics until the sub-agent's PR lands and you rebase. Don't try
282+
to "fix" the phantom diagnostics — the code is correct on your branch.
283+
284+
**Why this isn't fixable here:** the pyright-lsp plugin can't accept a per-call
285+
`projectRoot` (Anthropic
286+
[claude-code#32230](https://github.com/anthropics/claude-code/issues/32230), closed
287+
as not planned). The LSP plugin layer doesn't even receive a workspace `rootUri`
288+
during init for per-project config discovery
289+
([#27220](https://github.com/anthropics/claude-code/issues/27220)). Subagents resolve
290+
to the main repo root rather than their worktree
291+
([#31546](https://github.com/anthropics/claude-code/issues/31546)); session worktrees
292+
go inside the repo root by default
293+
([#49986](https://github.com/anthropics/claude-code/issues/49986)). All four upstream
294+
issues are closed without fix as of this writing.
295+
267296
The repo's house rule (no `# type: ignore` / `# noqa`) means **a real diagnostic is
268297
always a fix, never a suppression**. If the diagnostic is wrong (third-party stub gap),
269298
document the rationale and use a config-level rule override in `pyrightconfig.json`

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)