2025-05-29 04:36:31 +08:00
# ◍OpenCode
2025-03-25 20:04:36 +08:00
2025-05-15 03:50:18 +08:00

2025-06-10 07:58:02 +08:00
> **⚠️ Notice:** We are in progress of a complete overhaul in the `dontlook` branch - should be released mid June. The README below is for the current version
2025-04-07 21:37:47 +08:00
2025-03-28 05:35:48 +08:00
A powerful terminal-based AI assistant for developers, providing intelligent coding assistance directly in your terminal.
2025-03-25 20:04:36 +08:00
2025-03-28 05:35:48 +08:00
## Overview
2025-03-25 20:04:36 +08:00
2025-04-17 02:06:23 +08:00
OpenCode is a Go-based CLI application that brings AI assistance to your terminal. It provides a TUI (Terminal User Interface) for interacting with various AI models to help with coding tasks, debugging, and more.
2025-03-25 20:04:36 +08:00
2025-03-28 05:35:48 +08:00
## Features
- **Interactive TUI**: Built with [Bubble Tea ](https://github.com/charmbracelet/bubbletea ) for a smooth terminal experience
2025-04-29 19:56:49 +08:00
- **Multiple AI Providers**: Support for OpenAI, Anthropic Claude, Google Gemini, AWS Bedrock, Groq, Azure OpenAI, and OpenRouter
2025-03-28 05:35:48 +08:00
- **Session Management**: Save and manage multiple conversation sessions
- **Tool Integration**: AI can execute commands, search files, and modify code
2025-04-19 02:17:38 +08:00
- **Vim-like Editor**: Integrated editor with text input capabilities
2025-03-28 05:35:48 +08:00
- **Persistent Storage**: SQLite database for storing conversations and sessions
2025-04-19 02:17:38 +08:00
- **LSP Integration**: Language Server Protocol support for code intelligence
- **File Change Tracking**: Track and visualize file changes during sessions
2025-04-21 22:22:52 +08:00
- **External Editor Support**: Open your preferred editor for composing messages
2025-05-15 21:52:24 +08:00
- **Named Arguments for Custom Commands**: Create powerful custom commands with multiple named placeholders
2025-03-28 05:35:48 +08:00
## Installation
2025-04-25 04:34:57 +08:00
### Using the Install Script
```bash
# Install the latest version
curl -fsSL https://opencode.ai/install | bash
# Install a specific version
curl -fsSL https://opencode.ai/install | VERSION=0.1.0 bash
```
### Using Homebrew (macOS and Linux)
```bash
2025-05-13 23:02:39 +08:00
brew install sst/tap/opencode
2025-04-25 04:34:57 +08:00
```
### Using AUR (Arch Linux)
```bash
# Using yay
yay -S opencode-bin
# Using paru
paru -S opencode-bin
```
### Using Go
2025-03-28 05:35:48 +08:00
```bash
2025-05-13 23:02:39 +08:00
go install github.com/sst/opencode@latest
2025-03-28 05:35:48 +08:00
```
## Configuration
2025-04-17 02:06:23 +08:00
OpenCode looks for configuration in the following locations:
2025-03-28 05:35:48 +08:00
2025-04-17 02:06:23 +08:00
- `$HOME/.opencode.json`
- `$XDG_CONFIG_HOME/opencode/.opencode.json`
- `./.opencode.json` (local directory)
2025-03-28 05:35:48 +08:00
2025-04-19 02:17:38 +08:00
### Environment Variables
You can configure OpenCode using environment variables:
2025-04-28 21:42:57 +08:00
| Environment Variable | Purpose |
2025-05-01 00:05:59 +08:00
| -------------------------- | ------------------------------------------------------ |
2025-04-28 21:42:57 +08:00
| `ANTHROPIC_API_KEY` | For Claude models |
| `OPENAI_API_KEY` | For OpenAI models |
| `GEMINI_API_KEY` | For Google Gemini models |
2025-05-16 02:25:21 +08:00
| `VERTEXAI_PROJECT` | For Google Cloud VertexAI (Gemini) |
| `VERTEXAI_LOCATION` | For Google Cloud VertexAI (Gemini) |
2025-04-28 21:42:57 +08:00
| `GROQ_API_KEY` | For Groq models |
| `AWS_ACCESS_KEY_ID` | For AWS Bedrock (Claude) |
| `AWS_SECRET_ACCESS_KEY` | For AWS Bedrock (Claude) |
| `AWS_REGION` | For AWS Bedrock (Claude) |
| `AZURE_OPENAI_ENDPOINT` | For Azure OpenAI models |
| `AZURE_OPENAI_API_KEY` | For Azure OpenAI models (optional when using Entra ID) |
| `AZURE_OPENAI_API_VERSION` | For Azure OpenAI models |
2025-06-01 02:41:00 +08:00
2025-04-19 02:17:38 +08:00
### Configuration File Structure
```json
{
"data": {
"directory": ".opencode"
},
"providers": {
"openai": {
"apiKey": "your-api-key",
"disabled": false
},
"anthropic": {
"apiKey": "your-api-key",
"disabled": false
2025-04-25 13:48:48 +08:00
},
"groq": {
2025-04-29 19:56:49 +08:00
"apiKey": "your-api-key",
"disabled": false
},
"openrouter": {
"apiKey": "your-api-key",
"disabled": false
2025-04-19 02:17:38 +08:00
}
},
"agents": {
2025-05-13 03:32:27 +08:00
"primary": {
2025-04-19 02:17:38 +08:00
"model": "claude-3.7-sonnet",
"maxTokens": 5000
},
"task": {
"model": "claude-3.7-sonnet",
"maxTokens": 5000
},
"title": {
"model": "claude-3.7-sonnet",
"maxTokens": 80
}
},
"mcpServers": {
"example": {
"type": "stdio",
"command": "path/to/mcp-server",
"env": [],
"args": []
}
},
"lsp": {
"go": {
"disabled": false,
"command": "gopls"
}
},
2025-05-16 19:27:28 +08:00
"shell": {
"path": "/bin/zsh",
"args": ["-l"]
},
2025-04-19 02:17:38 +08:00
"debug": false,
"debugLSP": false
}
```
2025-03-28 05:35:48 +08:00
2025-04-19 02:17:38 +08:00
## Supported AI Models
2025-04-21 22:22:52 +08:00
OpenCode supports a variety of AI models from different providers:
### OpenAI
2025-04-22 01:48:36 +08:00
2025-04-21 22:22:52 +08:00
- GPT-4.1 family (gpt-4.1, gpt-4.1-mini, gpt-4.1-nano)
- GPT-4.5 Preview
- GPT-4o family (gpt-4o, gpt-4o-mini)
- O1 family (o1, o1-pro, o1-mini)
- O3 family (o3, o3-mini)
- O4 Mini
### Anthropic
2025-04-22 01:48:36 +08:00
2025-04-21 22:22:52 +08:00
- Claude 3.5 Sonnet
- Claude 3.5 Haiku
- Claude 3.7 Sonnet
- Claude 3 Haiku
- Claude 3 Opus
### Google
2025-04-22 01:48:36 +08:00
2025-04-21 22:22:52 +08:00
- Gemini 2.5
- Gemini 2.5 Flash
- Gemini 2.0 Flash
- Gemini 2.0 Flash Lite
### AWS Bedrock
2025-04-22 01:48:36 +08:00
2025-04-21 22:22:52 +08:00
- Claude 3.7 Sonnet
2025-03-28 05:35:48 +08:00
2025-04-25 13:48:48 +08:00
### Groq
2025-04-29 01:25:06 +08:00
- Llama 4 Maverick (17b-128e-instruct)
2025-04-25 13:48:48 +08:00
- Llama 4 Scout (17b-16e-instruct)
- QWEN QWQ-32b
- Deepseek R1 distill Llama 70b
- Llama 3.3 70b Versatile
2025-04-28 21:42:57 +08:00
### Azure OpenAI
- GPT-4.1 family (gpt-4.1, gpt-4.1-mini, gpt-4.1-nano)
- GPT-4.5 Preview
- GPT-4o family (gpt-4o, gpt-4o-mini)
- O1 family (o1, o1-mini)
- O3 family (o3, o3-mini)
- O4 Mini
2025-05-16 02:25:21 +08:00
### Google Cloud VertexAI
- Gemini 2.5
- Gemini 2.5 Flash
2025-05-20 21:23:51 +08:00
## Using Bedrock Models
To use bedrock models with OpenCode you need three things.
1. Valid AWS credentials (the env vars: `AWS_SECRET_KEY_ID` , `AWS_SECRET_ACCESS_KEY` and `AWS_REGION` )
2. Access to the corresponding model in AWS Bedrock in your region.
2025-06-01 02:41:00 +08:00
a. You can request access in the AWS console on the Bedrock -> "Model access" page.
2025-05-20 21:23:51 +08:00
3. A correct configuration file. You don't need the `providers` key. Instead you have to prefix your models per agent with `bedrock.` and then a valid model. For now only Claude 3.7 is supported.
```json
{
"agents": {
"primary": {
"model": "bedrock.claude-3.7-sonnet",
"maxTokens": 5000,
"reasoningEffort": ""
},
"task": {
"model": "bedrock.claude-3.7-sonnet",
"maxTokens": 5000,
"reasoningEffort": ""
},
"title": {
"model": "bedrock.claude-3.7-sonnet",
"maxTokens": 80,
"reasoningEffort": ""
}
2025-06-01 02:41:00 +08:00
}
2025-05-20 21:23:51 +08:00
}
```
2025-06-01 02:41:00 +08:00
2025-05-16 19:06:28 +08:00
## Interactive Mode Usage
2025-03-28 05:35:48 +08:00
```bash
2025-04-17 02:06:23 +08:00
# Start OpenCode
opencode
2025-03-28 05:35:48 +08:00
# Start with debug logging
2025-04-17 02:06:23 +08:00
opencode -d
2025-04-19 02:17:38 +08:00
# Start with a specific working directory
opencode -c /path/to/project
2025-03-28 05:35:48 +08:00
```
2025-05-16 19:06:28 +08:00
## Non-interactive Prompt Mode
2025-05-23 19:54:09 +08:00
You can run OpenCode in non-interactive mode by passing a prompt directly as a command-line argument or by piping text into the command. This is useful for scripting, automation, or when you want a quick answer without launching the full TUI.
2025-05-16 19:06:28 +08:00
```bash
# Run a single prompt and print the AI's response to the terminal
opencode -p "Explain the use of context in Go"
2025-05-23 19:54:09 +08:00
# Pipe input to OpenCode (equivalent to using -p flag)
echo "Explain the use of context in Go" | opencode
2025-05-16 19:06:28 +08:00
# Get response in JSON format
opencode -p "Explain the use of context in Go" -f json
2025-05-23 19:54:09 +08:00
# Or with piped input
echo "Explain the use of context in Go" | opencode -f json
2025-05-16 19:06:28 +08:00
# Run without showing the spinner
opencode -p "Explain the use of context in Go" -q
2025-05-23 19:54:09 +08:00
# Or with piped input
echo "Explain the use of context in Go" | opencode -q
2025-05-17 21:23:13 +08:00
# Enable verbose logging to stderr
opencode -p "Explain the use of context in Go" --verbose
2025-05-23 19:54:09 +08:00
# Or with piped input
echo "Explain the use of context in Go" | opencode --verbose
2025-05-17 21:23:13 +08:00
# Restrict the agent to only use specific tools
opencode -p "Explain the use of context in Go" --allowedTools=view,ls,glob
2025-05-23 19:54:09 +08:00
# Or with piped input
echo "Explain the use of context in Go" | opencode --allowedTools=view,ls,glob
2025-05-17 21:23:13 +08:00
# Prevent the agent from using specific tools
opencode -p "Explain the use of context in Go" --excludedTools=bash,edit
2025-05-23 19:54:09 +08:00
# Or with piped input
echo "Explain the use of context in Go" | opencode --excludedTools=bash,edit
2025-05-16 19:06:28 +08:00
```
In this mode, OpenCode will process your prompt, print the result to standard output, and then exit. All permissions are auto-approved for the session.
2025-05-17 21:23:13 +08:00
### Tool Restrictions
You can control which tools the AI assistant has access to in non-interactive mode:
- `--allowedTools` : Comma-separated list of tools that the agent is allowed to use. Only these tools will be available.
- `--excludedTools` : Comma-separated list of tools that the agent is not allowed to use. All other tools will be available.
These flags are mutually exclusive - you can use either `--allowedTools` or `--excludedTools` , but not both at the same time.
2025-05-16 19:06:28 +08:00
### Output Formats
OpenCode supports the following output formats in non-interactive mode:
2025-06-01 02:41:00 +08:00
| Format | Description |
| ------ | ------------------------------- |
| `text` | Plain text output (default) |
| `json` | Output wrapped in a JSON object |
2025-05-16 19:06:28 +08:00
The output format is implemented as a strongly-typed `OutputFormat` in the codebase, ensuring type safety and validation when processing outputs.
2025-04-19 02:17:38 +08:00
## Command-line Flags
2025-06-01 02:41:00 +08:00
| Flag | Short | Description |
| ----------------- | ----- | --------------------------------------------------- |
| `--help` | `-h` | Display help information |
| `--debug` | `-d` | Enable debug mode |
| `--cwd` | `-c` | Set current working directory |
| `--prompt` | `-p` | Run a single prompt in non-interactive mode |
| `--output-format` | `-f` | Output format for non-interactive mode (text, json) |
| `--quiet` | `-q` | Hide spinner in non-interactive mode |
| `--verbose` | | Display logs to stderr in non-interactive mode |
| `--allowedTools` | | Restrict the agent to only use specified tools |
| `--excludedTools` | | Prevent the agent from using specified tools |
2025-04-19 02:17:38 +08:00
## Keyboard Shortcuts
### Global Shortcuts
2025-04-22 01:48:36 +08:00
| Shortcut | Action |
| -------- | ------------------------------------------------------- |
| `Ctrl+C` | Quit application |
| `Ctrl+?` | Toggle help dialog |
| `?` | Toggle help dialog (when not in editing mode) |
| `Ctrl+L` | View logs |
| `Ctrl+A` | Switch session |
| `Ctrl+K` | Command dialog |
2025-04-29 01:25:06 +08:00
| `Ctrl+O` | Toggle model selection dialog |
2025-04-22 01:48:36 +08:00
| `Esc` | Close current overlay/dialog or return to previous mode |
2025-04-19 02:17:38 +08:00
### Chat Page Shortcuts
| Shortcut | Action |
| -------- | --------------------------------------- |
| `Ctrl+N` | Create new session |
| `Ctrl+X` | Cancel current operation/generation |
| `i` | Focus editor (when not in writing mode) |
| `Esc` | Exit writing mode and focus messages |
### Editor Shortcuts
2025-03-28 05:35:48 +08:00
2025-04-19 02:17:38 +08:00
| Shortcut | Action |
| ------------------- | ----------------------------------------- |
| `Ctrl+S` | Send message (when editor is focused) |
| `Enter` or `Ctrl+S` | Send message (when editor is not focused) |
2025-04-21 22:22:52 +08:00
| `Ctrl+E` | Open external editor |
2025-04-19 02:17:38 +08:00
| `Esc` | Blur editor and focus messages |
2025-04-13 20:37:05 +08:00
2025-04-21 22:22:52 +08:00
### Session Dialog Shortcuts
2025-04-22 01:48:36 +08:00
| Shortcut | Action |
| ---------- | ---------------- |
| `↑` or `k` | Previous session |
| `↓` or `j` | Next session |
| `Enter` | Select session |
| `Esc` | Close dialog |
2025-04-21 22:22:52 +08:00
2025-04-29 01:25:06 +08:00
### Model Dialog Shortcuts
| Shortcut | Action |
| ---------- | ----------------- |
| `↑` or `k` | Move up |
| `↓` or `j` | Move down |
| `←` or `h` | Previous provider |
| `→` or `l` | Next provider |
| `Esc` | Close dialog |
2025-04-21 22:22:52 +08:00
### Permission Dialog Shortcuts
2025-04-22 01:48:36 +08:00
| Shortcut | Action |
| ----------------------- | ---------------------------- |
| `←` or `left` | Switch options left |
| `→` or `right` or `tab` | Switch options right |
| `Enter` or `space` | Confirm selection |
| `a` | Allow permission |
| `A` | Allow permission for session |
| `d` | Deny permission |
2025-04-21 22:22:52 +08:00
2025-04-19 02:17:38 +08:00
### Logs Page Shortcuts
2025-04-04 01:50:31 +08:00
2025-04-22 01:48:36 +08:00
| Shortcut | Action |
| ------------------ | ------------------- |
2025-04-21 22:22:52 +08:00
| `Backspace` or `q` | Return to chat page |
2025-04-13 20:37:05 +08:00
2025-04-19 02:17:38 +08:00
## AI Assistant Tools
2025-04-04 01:50:31 +08:00
2025-04-19 02:17:38 +08:00
OpenCode's AI assistant has access to various tools to help with coding tasks:
2025-04-13 20:37:05 +08:00
2025-04-19 02:17:38 +08:00
### File and Code Tools
2025-04-04 01:50:31 +08:00
2025-04-19 02:17:38 +08:00
| Tool | Description | Parameters |
| ------------- | --------------------------- | ---------------------------------------------------------------------------------------- |
| `glob` | Find files by pattern | `pattern` (required), `path` (optional) |
| `grep` | Search file contents | `pattern` (required), `path` (optional), `include` (optional), `literal_text` (optional) |
| `ls` | List directory contents | `path` (optional), `ignore` (optional array of patterns) |
| `view` | View file contents | `file_path` (required), `offset` (optional), `limit` (optional) |
| `write` | Write to files | `file_path` (required), `content` (required) |
| `edit` | Edit files | Various parameters for file editing |
| `patch` | Apply patches to files | `file_path` (required), `diff` (required) |
| `diagnostics` | Get diagnostics information | `file_path` (optional) |
2025-04-13 20:37:05 +08:00
2025-04-19 02:17:38 +08:00
### Other Tools
2025-05-14 23:42:16 +08:00
| Tool | Description | Parameters |
| ------- | ------------------------------- | ----------------------------------------------------------- |
| `bash` | Execute shell commands | `command` (required), `timeout` (optional) |
| `fetch` | Fetch data from URLs | `url` (required), `format` (required), `timeout` (optional) |
| `agent` | Run sub-tasks with the AI agent | `prompt` (required) |
2025-03-28 05:35:48 +08:00
2025-05-01 00:05:59 +08:00
## Theming
OpenCode supports multiple themes for customizing the appearance of the terminal interface.
### Available Themes
The following predefined themes are available:
- `opencode` (default)
- `catppuccin`
- `dracula`
- `flexoki`
- `gruvbox`
- `monokai`
- `onedark`
- `tokyonight`
- `tron`
- `custom` (user-defined)
### Setting a Theme
You can set a theme in your `.opencode.json` configuration file:
```json
{
"tui": {
"theme": "monokai"
}
}
```
### Custom Themes
You can define your own custom theme by setting the `theme` to `"custom"` and providing color definitions in the `customTheme` map:
```json
{
"tui": {
"theme": "custom",
"customTheme": {
"primary": "#ffcc00",
"secondary": "#00ccff",
"accent": { "dark": "#aa00ff", "light": "#ddccff" },
"error": "#ff0000"
}
}
}
```
#### Color Definition Formats
Custom theme colors support two formats:
1. **Simple Hex String** : A single hex color string (e.g., `"#aabbcc"` ) that will be used for both light and dark terminal backgrounds.
2. **Adaptive Object** : An object with `dark` and `light` keys, each holding a hex color string. This allows for adaptive colors based on the terminal's background.
#### Available Color Keys
You can define any of the following color keys in your `customTheme` :
- Base colors: `primary` , `secondary` , `accent`
- Status colors: `error` , `warning` , `success` , `info`
- Text colors: `text` , `textMuted` , `textEmphasized`
- Background colors: `background` , `backgroundSecondary` , `backgroundDarker`
- Border colors: `borderNormal` , `borderFocused` , `borderDim`
- Diff view colors: `diffAdded` , `diffRemoved` , `diffContext` , etc.
You don't need to define all colors. Any undefined colors will fall back to the default "opencode" theme colors.
2025-05-16 19:27:28 +08:00
### Shell Configuration
OpenCode allows you to configure the shell used by the `bash` tool. By default, it uses:
2025-06-01 02:41:00 +08:00
2025-05-16 19:27:28 +08:00
1. The shell specified in the config file (if provided)
2. The shell from the `$SHELL` environment variable (if available)
3. Falls back to `/bin/bash` if neither of the above is available
To configure a custom shell, add a `shell` section to your `.opencode.json` configuration file:
```json
{
"shell": {
"path": "/bin/zsh",
"args": ["-l"]
}
}
```
You can specify any shell executable and custom arguments:
```json
{
"shell": {
"path": "/usr/bin/fish",
"args": []
}
}
```
2025-03-28 05:35:48 +08:00
## Architecture
2025-04-17 02:06:23 +08:00
OpenCode is built with a modular architecture:
2025-03-28 05:35:48 +08:00
- **cmd**: Command-line interface using Cobra
- **internal/app**: Core application services
- **internal/config**: Configuration management
- **internal/db**: Database operations and migrations
- **internal/llm**: LLM providers and tools integration
- **internal/tui**: Terminal UI components and layouts
- **internal/logging**: Logging infrastructure
- **internal/message**: Message handling
- **internal/session**: Session management
2025-04-19 02:17:38 +08:00
- **internal/lsp**: Language Server Protocol integration
2025-05-09 22:33:35 +08:00
## Custom Commands
OpenCode supports custom commands that can be created by users to quickly send predefined prompts to the AI assistant.
### Creating Custom Commands
Custom commands are predefined prompts stored as Markdown files in one of three locations:
1. **User Commands** (prefixed with `user:` ):
2025-05-13 23:02:39 +08:00
2025-05-09 22:33:35 +08:00
```
$XDG_CONFIG_HOME/opencode/commands/
```
2025-05-13 23:02:39 +08:00
2025-05-09 22:33:35 +08:00
(typically `~/.config/opencode/commands/` on Linux/macOS)
or
```
$HOME/.opencode/commands/
```
2. **Project Commands** (prefixed with `project:` ):
```
< PROJECT DIR > /.opencode/commands/
```
Each `.md` file in these directories becomes a custom command. The file name (without extension) becomes the command ID.
For example, creating a file at `~/.config/opencode/commands/prime-context.md` with content:
```markdown
RUN git ls-files
READ README.md
```
This creates a command called `user:prime-context` .
### Command Arguments
2025-05-15 21:52:24 +08:00
OpenCode supports named arguments in custom commands using placeholders in the format `$NAME` (where NAME consists of uppercase letters, numbers, and underscores, and must start with a letter).
For example:
2025-05-09 22:33:35 +08:00
```markdown
2025-05-15 21:52:24 +08:00
# Fetch Context for Issue $ISSUE_NUMBER
RUN gh issue view $ISSUE_NUMBER --json title,body,comments
RUN git grep --author="$AUTHOR_NAME" -n .
RUN grep -R "$SEARCH_PATTERN" $DIRECTORY
2025-05-09 22:33:35 +08:00
```
2025-05-15 21:52:24 +08:00
When you run a command with arguments, OpenCode will prompt you to enter values for each unique placeholder. Named arguments provide several benefits:
2025-06-01 02:41:00 +08:00
2025-05-15 21:52:24 +08:00
- Clear identification of what each argument represents
- Ability to use the same argument multiple times
- Better organization for commands with multiple inputs
2025-05-09 22:33:35 +08:00
### Organizing Commands
You can organize commands in subdirectories:
```
~/.config/opencode/commands/git/commit.md
```
This creates a command with ID `user:git:commit` .
### Using Custom Commands
1. Press `Ctrl+K` to open the command dialog
2. Select your custom command (prefixed with either `user:` or `project:` )
3. Press Enter to execute the command
The content of the command file will be sent as a message to the AI assistant.
2025-04-19 02:17:38 +08:00
## MCP (Model Context Protocol)
OpenCode implements the Model Context Protocol (MCP) to extend its capabilities through external tools. MCP provides a standardized way for the AI assistant to interact with external services and tools.
### MCP Features
- **External Tool Integration**: Connect to external tools and services via a standardized protocol
- **Tool Discovery**: Automatically discover available tools from MCP servers
- **Multiple Connection Types**:
- **Stdio**: Communicate with tools via standard input/output
- **SSE**: Communicate with tools via Server-Sent Events
- **Security**: Permission system for controlling access to MCP tools
### Configuring MCP Servers
MCP servers are defined in the configuration file under the `mcpServers` section:
```json
{
"mcpServers": {
"example": {
"type": "stdio",
"command": "path/to/mcp-server",
"env": [],
"args": []
},
"web-example": {
"type": "sse",
"url": "https://example.com/mcp",
"headers": {
"Authorization": "Bearer token"
}
}
}
}
```
### MCP Tool Usage
Once configured, MCP tools are automatically available to the AI assistant alongside built-in tools. They follow the same permission model as other tools, requiring user approval before execution.
## LSP (Language Server Protocol)
2025-04-21 22:22:52 +08:00
OpenCode integrates with Language Server Protocol to provide code intelligence features across multiple programming languages.
2025-04-19 02:17:38 +08:00
### LSP Features
- **Multi-language Support**: Connect to language servers for different programming languages
2025-04-21 22:22:52 +08:00
- **Diagnostics**: Receive error checking and linting information
2025-04-19 02:17:38 +08:00
- **File Watching**: Automatically notify language servers of file changes
### Configuring LSP
Language servers are configured in the configuration file under the `lsp` section:
```json
{
"lsp": {
"go": {
"disabled": false,
"command": "gopls"
},
"typescript": {
"disabled": false,
"command": "typescript-language-server",
"args": ["--stdio"]
}
}
}
```
### LSP Integration with AI
The AI assistant can access LSP features through the `diagnostics` tool, allowing it to:
- Check for errors in your code
- Suggest fixes based on diagnostics
2025-04-21 22:22:52 +08:00
While the LSP client implementation supports the full LSP protocol (including completions, hover, definition, etc.), currently only diagnostics are exposed to the AI assistant.
2025-03-28 05:35:48 +08:00
## Development
### Prerequisites
2025-04-21 22:22:52 +08:00
- Go 1.24.0 or higher
2025-03-28 05:35:48 +08:00
### Building from Source
```bash
# Clone the repository
2025-05-13 23:02:39 +08:00
git clone https://github.com/sst/opencode.git
2025-04-17 02:06:23 +08:00
cd opencode
2025-03-28 05:35:48 +08:00
# Build
2025-04-17 02:06:23 +08:00
go build -o opencode
2025-03-28 05:35:48 +08:00
# Run
2025-04-17 02:06:23 +08:00
./opencode
2025-03-28 05:35:48 +08:00
```
2025-04-03 21:20:15 +08:00
## Acknowledgments
2025-04-21 19:33:51 +08:00
OpenCode gratefully acknowledges the contributions and support from these key individuals:
2025-04-03 21:20:15 +08:00
2025-04-21 19:33:51 +08:00
- [@isaacphi ](https://github.com/isaacphi ) - For the [mcp-language-server ](https://github.com/isaacphi/mcp-language-server ) project which provided the foundation for our LSP client implementation
- [@adamdottv ](https://github.com/adamdottv ) - For the design direction and UI/UX architecture
Special thanks to the broader open source community whose tools and libraries have made this project possible.
2025-04-03 21:20:15 +08:00
2025-03-28 05:35:48 +08:00
## License
2025-04-19 02:17:38 +08:00
OpenCode is licensed under the MIT License. See the [LICENSE ](LICENSE ) file for details.
2025-03-28 05:35:48 +08:00
## Contributing
2025-04-19 02:17:38 +08:00
Contributions are welcome! Here's how you can contribute:
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
2025-04-22 01:48:36 +08:00
Please make sure to update tests as appropriate and follow the existing code style.