LSP: 'non-added document' error - missing textDocument/didOpen notification

Resolved 💬 3 comments Opened Jan 30, 2026 by DmitryFarberov Closed Feb 3, 2026

Bug Description

When using the LSP tool with clangd, operations fail with an error indicating the document hasn't been opened/added to the language server session.

Error Message

non-added document

Root Cause Analysis

The LSP tool is sending requests (like textDocument/definition, textDocument/references, etc.) without first sending a textDocument/didOpen notification to the language server.

Per the LSP specification, before any text document operations can be performed, the client must notify the server that the document is open via textDocument/didOpen. This notification:

  1. Informs the server the document is now managed by the client
  2. Provides the document's initial content
  3. Enables the server to start tracking the document

Without this notification, clangd (and likely other LSP servers) will reject requests for that document.

Expected Behavior

Before performing any LSP operation on a file, Claude Code should:

  1. Send textDocument/didOpen with the file URI and content
  2. Then proceed with the requested operation (goToDefinition, findReferences, etc.)

Environment

  • OS: Windows 11
  • LSP Server: clangd 21.1.8
  • Claude Code: Latest version

Steps to Reproduce

  1. Configure clangd as an LSP server in Claude Code settings
  2. Use the LSP tool to perform any operation (e.g., goToDefinition) on a C/C++ file
  3. Observe the "non-added document" error

Suggested Fix

In the LSP client implementation, before sending any textDocument/* request:

  1. Check if the document has been opened in the current session
  2. If not, read the file content and send textDocument/didOpen
  3. Track opened documents to avoid redundant notifications
  4. Optionally send textDocument/didClose when appropriate

LSP Specification Reference

See textDocument/didOpen in the LSP 3.17 specification.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗