LSP servers lost during reinitializeLspServerManager (generation 2 loads 0 servers)
LSP servers lost during reinitializeLspServerManager (generation 2 loads 0 servers)
Bug Description
LSP tools (goToDefinition, findReferences, hover, etc.) become unavailable immediately after session startup. The LSP manager successfully initializes 3 servers in generation 1, but reinitializeLspServerManager() fires ~330ms later and overwrites the working state with 0 servers.
Reproduction
- Enable LSP plugins (
typescript-lsp,pyright-lsp,gopls-lsp) viaenabledPluginsin settings.json - Set
ENABLE_LSP_TOOL=1in settings env - Start a session with
claude --debug-file /tmp/claude-lsp.log - Attempt to use the LSP tool — it shows as disconnected in ToolSearch
Happens consistently across sessions and projects. The LSP tool appears in the deferred tools list at session start but becomes unavailable before the first prompt completes.
Debug Log Evidence
Generation 1 — succeeds (T+0.936s):
[LSP MANAGER] initializeLspServerManager() called
[LSP MANAGER] Created manager instance, state=pending
[LSP MANAGER] Starting async initialization (generation 1)
Loaded 1 LSP server(s) from plugin: typescript-lsp
Loaded 1 LSP server(s) from plugin: pyright-lsp
Loaded 1 LSP server(s) from plugin: gopls-lsp
Total LSP servers loaded: 3
LSP manager initialized with 3 servers
LSP server manager initialized successfully
Registered diagnostics handler for plugin:typescript-lsp:typescript
Registered diagnostics handler for plugin:pyright-lsp:pyright
Registered diagnostics handler for plugin:gopls-lsp:gopls
LSP notification handlers registered successfully for all 3 server(s)
Generation 2 — destroys working state (T+1.267s, ~330ms later):
[LSP MANAGER] reinitializeLspServerManager() called
[LSP MANAGER] initializeLspServerManager() called
[LSP MANAGER] Created manager instance, state=pending
[LSP MANAGER] Starting async initialization (generation 2)
Total LSP servers loaded: 0 <-- BUG: second pass finds no servers
[LSP SERVER MANAGER] getAllLspServers returned 0 server(s)
LSP manager initialized with 0 servers
LSP server manager initialized successfully
LSP notification handlers registered successfully for all 0 server(s)
Result — LSP tool filtered out:
[WARN] Filtering out tool_reference for unavailable tool: LSP
Root Cause Hypothesis
The plugin system performs two initialization passes:
- First pass loads plugins and initializes LSP servers correctly
- Second pass (
reinitializeLspServerManager) runs after full plugin resolution ("Loaded plugins - Enabled: 22, Disabled: 1") but the LSP server discovery in this second pass returns 0 servers — likely because the plugin list hasn't been passed through correctly or the LSP server configs aren't available at that point in the lifecycle.
The second pass unconditionally replaces the working manager instance rather than preserving the existing one if the new discovery finds fewer servers.
Environment
- Claude Code version: 2.1.91
- Platform: macOS (Darwin 25.5.0, Apple Silicon)
- Node: v22.18.0
- typescript-language-server: 5.1.3 (globally installed)
- Enabled LSP plugins:
typescript-lsp@claude-plugins-official,pyright-lsp@claude-plugins-official,gopls-lsp@claude-plugins-official - Total enabled plugins: 22 (many knowledge-work, marketplace plugins)
Suggested Fix
Either:
- Don't reinitialize if generation 1 already succeeded with >0 servers
- Guard the reinitialization: if generation N+1 discovers 0 servers but generation N had >0, preserve the existing manager
- Fix the server discovery in the second pass to correctly find the LSP plugin configs
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗