Overview
OpenCode is a fully open-source AI coding agent built with TypeScript and AI SDK, offering terminal TUI, IDE integration, and desktop applications. The project has 94.9k+ stars on GitHub with an active community. By configuring API易 service, you can get:🖥️ Multi-Platform Support
Terminal TUI, VS Code extension, and desktop apps
🔌 75+ Model Support
Supports 75+ LLM providers via Models.dev
🛠️ Built-in LSP
Language Server Protocol support for intelligent code understanding
🔄 Multi-Session Parallel
Parallel session processing and session sharing
Project Info: OpenCode is an actively maintained open-source project. Website:
opencode.ai, Repository: github.com/anomalyco/opencode.Prerequisites
Install OpenCode
- Quick Install (Recommended)
- npm
- Homebrew (macOS/Linux)
- Windows
- Arch Linux
- Desktop App
Quick Configuration
OpenCode uses JSON configuration files with multiple config locations (priority from low to high):- Remote config (
.well-known/opencode) - Global config:
~/.config/opencode/opencode.json - Custom config: path specified by
OPENCODE_CONFIGenvironment variable - Project config:
opencode.jsonin project root .opencodedirectory config- Inline config:
OPENCODE_CONFIG_CONTENTenvironment variable
Method 1: Custom Provider (Recommended)
Create or edit the config file~/.config/opencode/opencode.json:
- macOS/Linux
- Windows
Method 2: /connect Command Authentication
OpenCode provides the/connect command to quickly connect new providers:
- After starting OpenCode, type
/connect - Select “Other”
- Enter provider ID (e.g.,
apiyi) - Enter API key
Method 3: Override Existing Provider
For quick setup, override the built-in OpenAI provider’s baseURL:Method 4: Project-Level Configuration
Createopencode.json in your project root for project-specific settings:
Agent System
OpenCode has three built-in agents, each with specific purposes:| Agent | Description | Usage |
|---|---|---|
| build | Default agent with full access, handles code generation and modification | Direct conversation |
| plan | Read-only agent for code analysis and planning, won’t modify files | /plan command |
| general | Complex search sub-agent for multi-step information retrieval | @general invocation |
Agent Model Configuration
Configure different models for different agents:Recommended Models
OpenCode supports 200+ AI models through API易. Choose the right model for different tasks.View Programming Model Recommendations
Check the latest programming model recommendations, performance comparisons, and usage suggestions. Includes top-tier models, cost-effective options, and reasoning-enhanced models.
Scenario-Based Model Recommendations
| Agent | Purpose | Recommended Model |
|---|---|---|
| build | Code generation and modification | Claude Sonnet 4, GPT-4.1 |
| plan | Task planning and analysis | DeepSeek V3, Gemini 2.5 Pro |
| general | Quick search and Q&A | GPT-4.1 Mini (low cost) |
Core Features
Terminal Interactive Interface
Start OpenCode to enter the interactive TUI:File Operations
OpenCode can read, search, and modify project files:Command Execution
Execute commands in the terminal and view results:Session Management
- Multi-session parallel: Run multiple sessions simultaneously
- Session sharing: Export and share sessions
- Auto-save: All sessions are automatically persisted
- Context retention: Maintain complete conversation context during sessions
Usage Tips
1. Keyboard Shortcuts
| Shortcut | Function |
|---|---|
Ctrl+C | Interrupt current operation |
Ctrl+D | Exit OpenCode |
Tab | Auto-complete |
↑/↓ | Browse command history |
2. Common Commands
| Command | Function |
|---|---|
/connect | Connect new Provider |
/model | Switch current model |
/plan | Use plan agent for analysis |
/clear | Clear current session |
/help | View help information |
3. Invoke Sub-Agent
Use@general to invoke the search sub-agent for complex queries:
4. Incremental Development
Troubleshooting
Failed to connect to API易
Failed to connect to API易
- Check if environment variable is set correctly:
- Verify baseURL in configuration file:
- Test API connectivity:
Model not found error
Model not found error
Verify the model ID is correct. Check the API易 console for supported models.Common model IDs:
claude-sonnet-4-20250514gpt-4.1deepseek-chatgemini-2.5-pro-preview-05-06
Configuration file not taking effect
Configuration file not taking effect
Configuration file loading priority (from low to high):
- Remote config (
.well-known/opencode) - Global config:
~/.config/opencode/opencode.json OPENCODE_CONFIGenvironment variable- Project config:
opencode.json .opencodedirectory configOPENCODE_CONFIG_CONTENTenvironment variable
Slow response
Slow response
- Try using a lighter model (e.g., GPT-4.1 Mini)
- Reduce context length, start a new session
- Check network connection stability
Best Practices
1. Model Selection Strategy
| Task Type | Recommended Model | Reason |
|---|---|---|
| Complex code generation | Claude Sonnet 4 | Strong coding ability, good context understanding |
| Code review | GPT-4.1 | Strong analytical ability, good attention to detail |
| Quick Q&A | DeepSeek V3 | Fast response, cost-effective |
| Long document analysis | Gemini 2.5 Pro | Supports ultra-long context |
2. Effective Prompts
3. Security Considerations
- Don’t hardcode API keys in code
- Use environment variables to manage sensitive information
- Review AI-generated code, especially security-related parts
- Be careful not to let AI execute dangerous system commands
4. Cost Control
- Configure different models for different agents (strong models for build, lightweight for general)
- Use lightweight models for simple tasks
- Regularly check API易 console to monitor usage
Alternatives
If OpenCode doesn’t meet your needs, consider these tools:Claude Code
Anthropic’s official terminal programming assistant
Codex CLI
OpenAI’s official command-line tool
Gemini CLI
Google’s official terminal programming assistant
Roo Code
VS Code AI programming extension