Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

OpenCode

OpenCode is a terminal-based AI coding agent. It integrates with LSP servers to give the AI access to diagnostics, go-to-definition, references, hover, and more.

For the full settings schema, see Setup Overview.

LSP tool (experimental)

OpenCode has an experimental lsp tool that gives the AI direct access to LSP methods. Enable it with:

OPENCODE_EXPERIMENTAL_LSP_TOOL=true opencode

Or set it in your environment permanently:

export OPENCODE_EXPERIMENTAL_LSP_TOOL=true

With the LSP tool enabled, the AI agent can call:

OperationLSP MethodDescription
hovertextDocument/hoverType info, NatSpec docs, selectors
goToDefinitiontextDocument/definitionJump to symbol definition
findReferencestextDocument/referencesFind all references to a symbol
goToImplementationtextDocument/implementationFind implementations
documentSymboltextDocument/documentSymbolBrowse file structure
workspaceSymbolworkspace/symbolSearch symbols across project
prepareCallHierarchycallHierarchy/prepareTrace call graphs
incomingCallscallHierarchy/incomingCallsWho calls this function
outgoingCallscallHierarchy/outgoingCallsWhat this function calls

Example: hover

OPENCODE_EXPERIMENTAL_LSP_TOOL=true opencode run "use the lsp tool to hover on src/Pool.sol at line 102 col 15"

The AI will invoke the LSP hover method and get back type signatures, NatSpec documentation, and function selectors from the Solidity language server.

Example: find references

OPENCODE_EXPERIMENTAL_LSP_TOOL=true opencode run "use the lsp tool to find all references to the initialize function in src/PoolManager.sol"

Configure

Add to your global config (~/.config/opencode/opencode.json) or project-level opencode.json. The solidity-language-server binary must be in your $PATH (installed via cargo install solidity-language-server).

Default
{
  "$schema": "https://opencode.ai/config.json",
  "lsp": {
    "solidity": {
      "command": ["solidity-language-server", "--stdio"],
      "extensions": [".sol"],
      "initialization": {
        "solidity-language-server": {
          "inlayHints": {
            "parameters": true
          },
          "lint": {
            "enabled": true
          },
          "fileOperations": {
            "templateOnCreate": true,
            "updateImportsOnRename": true,
            "updateImportsOnDelete": true
          },
          "projectIndex": {
            "fullProjectScan": true
          }
        }
      }
    }
  }
}

How it works

When OpenCode encounters a .sol file, it automatically:

  1. Starts the Solidity language server
  2. Sends textDocument/didOpen to index the file
  3. Collects diagnostics (errors, warnings, lint) and feeds them to the AI agent
  4. The AI uses diagnostics to detect and fix issues in code it writes

Lint options reference

Lint options (severity, rule IDs, only, exclude) are documented in Setup Overview - Lint values.