lsp-integration
LSP Integration for Claude Code Plugins
Overview
Language Server Protocol (LSP) servers provide code intelligence features like go-to-definition, find references, and hover information. Claude Code plugins can bundle or configure LSP servers to enhance Claude's understanding of code.
Key capabilities:
- Enable go-to-definition for code navigation
- Find all references to symbols
- Get hover information and documentation
- Support language-specific features (completions, diagnostics)
LSP Server Configuration
Plugins can provide LSP servers in the plugin manifest:
Basic Configuration
{
"name": "my-plugin",
"lspServers": {
"python": {
"command": "pyright-langserver",
"args": ["--stdio"],
"extensionToLanguage": {
".py": "python",
".pyi": "python"
}
}
}
}
Separate File Configuration
LSP servers can also be configured in a separate .lsp.json file at the plugin root:
{
"go": {
"command": "gopls",
"args": ["serve"],
"extensionToLanguage": {
".go": "go"
}
}
}
Reference this file in plugin.json:
{
"name": "my-plugin",
"lspServers": "./.lsp.json"
}
Configuration Fields
command (required): The LSP server executable
args (optional): Command-line arguments for the server
extensionToLanguage (required): Maps file extensions to language IDs
{
"extensionToLanguage": {
".py": "python",
".pyi": "python",
".pyw": "python"
}
}
env (optional): Environment variables for the server process
{
"env": {
"PYTHONPATH": "${CLAUDE_PLUGIN_ROOT}/lib"
}
}
transport (optional): Communication transport - stdio (default) or socket
{
"lspServers": {
"dart": {
"transport": "socket",
"command": "dart",
"args": ["language-server", "--port", "8123"],
"extensionToLanguage": { ".dart": "dart" }
}
}
}
Socket transport connects to the server via TCP port instead of stdin/stdout.
initializationOptions (optional): Options passed to the server during LSP initialization
{
"initializationOptions": {
"typescript": {
"tsdk": "./node_modules/typescript/lib"
},
"diagnostics": true,
"formatting": { "tabSize": 2 }
}
}
settings (optional): Settings passed via workspace/didChangeConfiguration
workspaceFolder (optional): Workspace folder path for the server
startupTimeout (optional): Maximum time to wait for server startup in milliseconds
shutdownTimeout (optional): Maximum time to wait for graceful shutdown in milliseconds
restartOnCrash (optional): Whether to automatically restart the server if it crashes
maxRestarts (optional): Maximum number of restart attempts before giving up
What Claude Gains from LSP
When an LSP plugin is installed and its language server binary is available, Claude gains two key capabilities:
Automatic Diagnostics
After every file edit Claude makes, the language server analyzes the changes and reports errors and warnings back automatically. Claude sees type errors, missing imports, and syntax issues without needing to run a compiler or linter. If Claude introduces an error, it notices and fixes the issue in the same turn.
Code Navigation
Claude can use the language server to:
- Jump to definitions
- Find all references to a symbol
- Get type information on hover
- List symbols in a file
- Find implementations of interfaces
- Trace call hierarchies
These operations give Claude more precise navigation than grep-based search.
Pre-built LSP Plugins
Claude Code provides official LSP plugins for common languages. Install from the marketplace:
| Language | Plugin | Binary Required |
|---|---|---|
| C/C++ | clangd-lsp |
clangd |
| C# | csharp-lsp |
csharp-ls |
| Go | gopls-lsp |
gopls |
| Java | jdtls-lsp |
jdtls |
| Kotlin | kotlin-lsp |
kotlin-language-server |
| Lua | lua-lsp |
lua-language-server |
| PHP | php-lsp |
intelephense |
| Python | pyright-lsp |
pyright-langserver |
| Rust | rust-analyzer-lsp |
rust-analyzer |
| Swift | swift-lsp |
sourcekit-lsp |
| TypeScript | typescript-lsp |
typescript-language-server |
Install the language server binary first, then install the plugin:
# Example: Python
pip install pyright # or: npm install -g pyright
claude /install-plugin pyright-lsp
Troubleshooting: If you see Executable not found in $PATH in the /plugin Errors tab, install the required binary from the table above.
Creating Custom LSP Integration
Step 1: Choose or Build LSP Server
Options:
- Use existing LSP server - Most languages have official or community servers
- Bundle with plugin - Include server binary in plugin
- Require user installation - Document server installation in README
Step 2: Configure in plugin.json
{
"name": "go-lsp",
"version": "1.0.0",
"description": "Go language server integration",
"lspServers": {
"go": {
"command": "gopls",
"args": ["serve"],
"extensionToLanguage": {
".go": "go",
".mod": "go.mod"
}
}
}
}
Step 3: Bundle Server (Optional)
For self-contained plugins, bundle the server:
my-lsp-plugin/
├── .claude-plugin/
│ └── plugin.json
└── servers/
└── my-lsp-server
Use ${CLAUDE_PLUGIN_ROOT} for the command path:
{
"lspServers": {
"mylang": {
"command": "${CLAUDE_PLUGIN_ROOT}/servers/my-lsp-server",
"args": ["--stdio"]
}
}
}
Step 4: Document Requirements
In your plugin README:
- List required external dependencies
- Provide installation instructions
- Note supported language versions
- Describe available features
Extension to Language Mapping
The extensionToLanguage field maps file extensions to LSP language identifiers:
Common Mappings
{
"extensionToLanguage": {
".py": "python",
".js": "javascript",
".ts": "typescript",
".jsx": "javascriptreact",
".tsx": "typescriptreact",
".rs": "rust",
".go": "go",
".java": "java",
".rb": "ruby",
".php": "php",
".c": "c",
".cpp": "cpp",
".h": "c",
".hpp": "cpp",
".cs": "csharp"
}
}
Multiple Extensions
A single language can have multiple extensions:
{
"extensionToLanguage": {
".ts": "typescript",
".mts": "typescript",
".cts": "typescript",
".d.ts": "typescript"
}
}
LSP Server Lifecycle
Startup
LSP servers start automatically when:
- Claude Code session begins
- Plugin with LSP server is enabled
- User opens a file matching configured extensions
Communication
- Uses stdio for client-server communication
- Follows LSP specification for messages
- Claude Code manages the connection
Shutdown
Servers terminate when:
- Claude Code session ends
- Plugin is disabled
- Server crashes (auto-restart may occur)
Best Practices
Performance
- Lazy initialization - Servers start when needed, not at session start
- Minimal configuration - Only enable features you need
- Resource limits - Consider memory/CPU impact of servers
Compatibility
- Check LSP version - Ensure server supports required protocol version
- Test cross-platform - Verify on macOS, Linux, Windows
- Handle missing servers - Gracefully degrade if server not installed
Documentation
- List prerequisites - External tools, versions required
- Provide setup guide - Step-by-step installation
- Document features - Which LSP capabilities are supported
Troubleshooting
Server Not Starting
Check:
- Command path is correct
- Server is installed and executable
- Required dependencies are available
${CLAUDE_PLUGIN_ROOT}is used for bundled servers
No Code Intelligence
Check:
- File extension matches
extensionToLanguagemapping - Language ID is correct for the server
- Server supports the requested feature
Debug Mode
Enable debug logging:
claude --debug
Look for:
- LSP server startup messages
- Communication logs
- Error responses
Quick Reference
Minimal LSP Configuration
{
"lspServers": {
"language": {
"command": "server-command",
"extensionToLanguage": {
".ext": "language-id"
}
}
}
}
Full LSP Configuration
{
"lspServers": {
"language": {
"command": "${CLAUDE_PLUGIN_ROOT}/servers/lsp-server",
"args": ["--stdio", "--log-level", "warn"],
"extensionToLanguage": {
".ext1": "language",
".ext2": "language"
},
"env": {
"CONFIG_PATH": "${CLAUDE_PLUGIN_ROOT}/config"
},
"transport": "stdio",
"initializationOptions": {},
"settings": {},
"workspaceFolder": ".",
"startupTimeout": 10000,
"shutdownTimeout": 5000,
"restartOnCrash": true,
"maxRestarts": 3
}
}
}
Best Practices Summary
DO:
- Use
${CLAUDE_PLUGIN_ROOT}for bundled server paths - Map all relevant file extensions
- Document external dependencies
- Test on multiple platforms
- Handle server unavailability gracefully
DON'T:
- Hardcode absolute paths
- Assume servers are pre-installed
- Bundle large binaries without consideration
- Ignore server startup errors
Additional Resources
Reference Files
For detailed information, consult:
references/popular-lsp-servers.md- Curated list of LSP servers by language with installation commandsreferences/lsp-capabilities.md- LSP protocol capabilities and what they enable
Examples
examples/minimal-lsp-plugin/- Complete directory structure for a minimal LSP pluginexamples/lsp-json-configs.md- Various.lsp.jsonconfiguration patterns
External Resources
- LSP Specification: https://microsoft.github.io/language-server-protocol/
- Claude Code Plugins Reference: https://docs.anthropic.com/en/docs/claude-code/plugins-reference
- Language Server List: https://langserver.org/
More from sjnims/plugin-dev
plugin-dev-guide
This skill should be used when the user asks about "Claude Code plugins", "plugin development", "how to build a plugin", "what plugin components exist", "plugin architecture", "extending Claude Code", or needs an overview of plugin development capabilities. Acts as a guide to the 9 specialized plugin-dev skills, explaining when to activate each one. Load this skill first when the user is new to plugin development or unsure which specific skill they need.
12skill-development
This skill should be used when the user asks to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill content", "SKILL.md format", "skill frontmatter", "skill triggers", "trigger phrases for skills", "progressive disclosure", "skill references folder", "skill examples folder", "validate skill", "skill model field", "skill hooks", "scoped hooks in skill", "visibility budget", "context budget", "SLASH_COMMAND_TOOL_CHAR_BUDGET", "skill permissions", "Skill() syntax", "visual output", or needs guidance on skill structure, file organization, writing style, or skill development best practices for Claude Code plugins.
12agent-development
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", "disallowedTools", "block tools", "agent denylist", "maxTurns", "agent memory", "mcpServers in agent", "agent hooks", "background agent", "resume agent", "agent teams", "permission rules", "permission mode", "delegate mode", "agent team", "team lead", "teammate", "multi-agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
12mcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context Protocol", "connect external service", mentions "${CLAUDE_PLUGIN_ROOT} with MCP", discusses MCP server types (SSE, stdio, HTTP, WebSocket), or asks to "find MCP server", "discover MCP servers", "what MCP servers exist", "recommend MCP server for [service]", "MCP prompts", "MCP prompts as commands", "tool search", "tool search threshold", "claude mcp serve", "allowedMcpServers", "deniedMcpServers", "managed MCP". Provides comprehensive guidance for integrating Model Context Protocol servers into Claude Code plugins for external tool and service integration.
11plugin-structure
This skill should be used when the user asks to "create a plugin", "scaffold a plugin", "understand plugin structure", "organize plugin components", "set up plugin.json", "use ${CLAUDE_PLUGIN_ROOT}", "add commands/agents/skills/hooks", "add lspServers", "configure auto-discovery", "headless mode", "CI mode", "plugin in CI", "github actions", "plugin caching", "plugin CLI", "install plugin", "installation scope", "auto-update", "validate plugin", "plugin validate", "debug plugin", "output styles", "outputStyles", "custom output format", "response formatting", "--verbose", or needs guidance on plugin directory layout, manifest configuration, component organization, file naming conventions, or Claude Code plugin architecture best practices.
11hook-development
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", "scoped hooks", "frontmatter hooks", "hook in skill", "hook in agent", "agent hook type", "async hooks", "once handler", "statusMessage", "hook decision control", "TeammateIdle hook", "TaskCompleted hook", or mentions hook events (PreToolUse, PermissionRequest, PostToolUse, PostToolUseFailure, Stop, SubagentStop, SubagentStart, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification, TeammateIdle, TaskCompleted). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.
11