Skip to main content
OpenCode is an open-source AI coding agent designed for developers, featuring a “terminal-native” experience: it uses TUI/CLI to handle requirement discussions, code generation, refactoring, explanation, and debugging workflows directly in the command line. It emphasizes being “model-agnostic” and can connect to Claude, GPT, Gemini, and other model services, as well as local or OpenAI-compatible APIs, allowing you to freely balance cost, performance, and privacy. OpenCode also provides an extensible plugin/tool mechanism and configuration system that can incorporate project context, command execution, and other capabilities into automated workflows, making it ideal for power terminal users and teams that want to customize their AI coding workflow.

Installation and Integration

Installation

For other installation methods, see the OpenCode official website: https://opencode.ai/docs/#install

Start OpenCode

Connect to Myrouter API

  • Global configuration: ~/.config/opencode/opencode.json
  • Project configuration: opencode.json in the project root directory
(If opencode.json does not exist, you can create it manually.) Configuration as follows:
When configuring third-party providers, make sure to select the correct npm package: Note: Codex models (e.g., gpt-5.1-codex) require @ai-sdk/openai (Response API), while other models use @ai-sdk/openai-compatible (Chat Completion API).

Configure the KEY

In OpenCode, use /connect to select the provider, then enter your API KEY and press Enter to confirm. opencode_input_api_key

Start Using

After connecting to the provider, use the /models command to select a model. opencode_choose_model

Other Usage

Example: Local MCP Configuration (Calculator MCP Example)

  1. Write a calculator MCP server using Python + MCP SDK and save it to a local path.
  1. Add the local MCP to opencode.json
  1. Use /mcps to check MCP connection status. When in Enabled state, OpenCode can invoke it.
opencode_mcp