LSP Servers
OpenCode integrates with your LSP servers.
OpenCode can integrate with Language Server Protocol (LSP) servers to use diagnostics as feedback for the agent.
Built-in
OpenCode comes with several built-in LSP servers for popular languages:
LSP is disabled by default. When enabled, servers start when one of the above file extensions is detected and the requirements are met.
How It Works
When LSP is enabled and opencode opens a file, it:
- Checks the file extension against all enabled LSP servers.
- Starts the appropriate LSP server if not already running.
Best Practices
LSP can help the agent find and fix issues by providing diagnostics from language servers. This is useful in some projects, but it is not always a net positive.
Language servers can get out of sync, use significant memory, vary by version or project, and slow down agent workflows. In many projects it is better to have the agent run lint, typecheck, or other diagnostic CLI tools directly, so errors are fed back into the agent loop without those tradeoffs. Document those commands in instruction files such as AGENTS.md or skills so the agent knows what to run. Enable LSP when your project benefits from additional language-server feedback.
Configure
You can enable and customize LSP servers through the lsp section in your opencode config.
To enable all built-in LSP servers, set lsp to true.
{ "$schema": "https://opencode.ai/config.json", "lsp": true}Use an object to keep built-ins enabled while configuring overrides or custom servers.
{ "$schema": "https://opencode.ai/config.json", "lsp": {}}Each configured LSP server entry supports the following:
Server entries need command unless they only disable a server.
Let’s look at some examples.
Environment variables
Use the env property to set environment variables when starting the LSP server:
{ "$schema": "https://opencode.ai/config.json", "lsp": { "rust": { "command": ["rust-analyzer"], "env": { "RUST_LOG": "debug" } } }}Initialization options
Use the initialization property to pass initialization options to the LSP server. These are server-specific settings sent during the LSP initialize request:
{ "$schema": "https://opencode.ai/config.json", "lsp": { "custom-lsp": { "command": ["custom-lsp-server", "--stdio"], "extensions": [".custom"], "initialization": { "preferences": { "importModuleSpecifierPreference": "relative" } } } }}Disabling LSP servers
If lsp is omitted, all LSP servers are disabled. To disable all LSP servers after another config enabled them, set lsp to false:
{ "$schema": "https://opencode.ai/config.json", "lsp": false}To disable a specific LSP server, set disabled to true:
{ "$schema": "https://opencode.ai/config.json", "lsp": { "typescript": { "disabled": true } }}Custom LSP servers
You can add custom LSP servers by specifying the command and file extensions:
{ "$schema": "https://opencode.ai/config.json", "lsp": { "custom-lsp": { "command": ["custom-lsp-server", "--stdio"], "extensions": [".custom"] } }}Additional Information
PHP Intelephense
PHP Intelephense offers premium features through a license key. You can provide a license key by placing (only) the key in a text file at:
- On macOS/Linux:
$HOME/intelephense/license.txt - On Windows:
%USERPROFILE%/intelephense/license.txt
The file should contain only the license key with no additional content.
