Foreword: Why Have 165k+ Developers Chosen OpenCode?

In 2026, AI coding tools have evolved from "assisting with code completion" to "autonomously finishing development tasks." In this space, OpenCode (github.com/sst/opencode) has risen at a stunning pace — surpassing 165,000 GitHub Stars to become the most popular open-source terminal AI coding agent today.

Unlike closed-source tools like Claude Code or Cursor, OpenCode's core philosophy is: decouple models from the tool. You can freely choose GPT-4o, Claude, Qwen, DeepSeek, or even local Ollama models — all within a single terminal tool.

Today's article will take you from zero to proficient with OpenCode — from installation and configuration to advanced techniques, all in one piece.

1. What Is OpenCode?

OpenCode is an open-source CLI coding agent developed by the SST team. Its core architecture has two layers:

  • Harness (tool layer): handles file reads/writes, shell command execution, test result collection, and other environment operations
  • Model (model layer): connects to any large language model via an OpenAI-compatible API

This decoupled design means: you don't need to be locked into any vendor. Use Claude today, switch to GPT tomorrow, or cut to local Qwen the day after — all seamless within the same tool.

Core Features at a Glance

Feature Description
🧠 Multi-model support Claude, GPT-4o, Gemini, Qwen, DeepSeek, Ollama local models
🖥️ Terminal-first Pure CLI tool, no IDE plugin needed
📦 Zero-config start Install and go, with sensible defaults built in
🔌 MCP integration Supports MCP protocol for extensible toolchains
📋 Planning mode Built-in agent planning with autonomous task decomposition
🔓 Fully open-source Apache 2.0 license

OpenCode vs. Other Tools

Tool Open Source Multi-Model Terminal-First GitHub Stars
OpenCode 165k+
OpenAI Codex CLI ⚠️ OpenAI-biased 30k+
OpenHands ❌ GUI-leaning 40k+
Claude Code ❌ Claude only N/A
Aider 40k+

OpenCode's core advantage lies in the perfect combination of model flexibility and terminal experience.

2. Quick Installation

OpenCode offers multiple installation options. Pick the one that suits you best:

npm install -g opencode-ai

Option 2: Homebrew (macOS/Linux)

brew install opencode

Option 3: One-click install script

curl -fsSL https://opencode.ai/install | bash

Verify Installation

opencode --version

3. Getting Started: Your First Run

3.1 Configure Your API Key

OpenCode needs at least one AI model's API key configured. The simplest way is to set an environment variable:

# Using OpenAI
export OPENAI_API_KEY="sk-your-key-here"

# Or using Anthropic Claude
export ANTHROPIC_API_KEY="sk-ant-your-key-here"

💡 Tip: You can also write config to ~/.opencode/config.json so you don't have to set environment variables every time you open a terminal.

3.2 Launch OpenCode in Your Project

# Navigate to your project directory
cd ~/projects/my-app

# Start OpenCode
opencode

OpenCode automatically detects your project structure, loads context, and then you're ready to chat:

$ opencode

🤖 OpenCode v1.x - AI Coding Agent

> Help me review the login logic in src/auth.py for any security issues

3.3 Your First Task Example

Try asking OpenCode to complete a concrete task:

> Create a Python FastAPI project with the following structure:
> - main.py (app entry point)
> - routers/users.py (user routes)
> - models/user.py (user model)
> - requirements.txt (dependencies)

OpenCode will work step by step: read the project structure, create files, write code, and confirm each operation with you along the way.

4. Advanced Configuration: Switching Between Models

4.1 Config File

Create ~/.opencode/config.json:

{
  "providers": {
    "openai": {
      "type": "openai",
      "apiKey": "sk-your-openai-key",
      "model": "gpt-4o"
    },
    "anthropic": {
      "type": "anthropic",
      "apiKey": "sk-ant-your-key",
      "model": "claude-sonnet-4-20250514"
    },
    "ollama": {
      "type": "openai",
      "baseUrl": "http://localhost:11434/v1",
      "model": "qwen2.5-coder:32b"
    }
  },
  "defaultProvider": "anthropic"
}

4.2 Switch Models at Runtime

During an OpenCode session, you can switch models on the fly:

> /model openai
Switched to OpenAI GPT-4o

> /model ollama
Switched to local Ollama model

For developers in China, DeepSeek is an excellent cost-performance choice:

{
  "providers": {
    "deepseek": {
      "type": "openai",
      "baseUrl": "https://api.deepseek.com/v1",
      "apiKey": "your-deepseek-key",
      "model": "deepseek-coder"
    }
  }
}

Or use relay platforms like SiliconFlow:

{
  "providers": {
    "siliconflow": {
      "type": "openai",
      "baseUrl": "https://api.siliconflow.cn/v1",
      "apiKey": "your-siliconflow-key",
      "model": "Qwen/Qwen2.5-Coder-32B-Instruct"
    }
  }
}

5. Real-World Scenarios

5.1 Scenario 1: Refactoring Legacy Code

# Enter an old project
cd ~/projects/legacy-app

# Launch OpenCode
opencode
> Rewrite all callback functions in src/utils.js to async/await style
> Keep existing functionality intact while adding proper error handling

OpenCode will: 1. Read the src/utils.js file 2. Analyze all callback structures 3. Convert them one by one to async/await 4. Add try/catch error handling 5. Show the diff and wait for your confirmation

5.2 Scenario 2: Writing Unit Tests

> Write Jest unit tests for src/auth/login.ts
> Cover these scenarios:
> 1. Successful login
> 2. Wrong password
> 3. User doesn't exist
> 4. Token expired
> 5. Concurrent login requests

OpenCode generates a complete test file with mock data and assertions.

5.3 Scenario 3: Debugging

> My app runs out of memory when processing large JSON datasets
> Project structure is under src/
> Please analyze potential causes and provide a fix

OpenCode scans the code, identifies potential memory leak points (such as unreleased references, infinitely growing arrays, etc.), and gives concrete fix suggestions.

5.4 Scenario 4: Local Model Development (Privacy-First)

If you're working with sensitive code and don't want to upload it to the cloud:

# 1. Install Ollama
brew install ollama

# 2. Pull a coding-focused model
ollama pull qwen2.5-coder:32b

# 3. Launch OpenCode and switch to local model
opencode
> /model ollama

Now all inference runs locally — your code never leaves your machine.

6. MCP Integration: Extending Your Toolchain

OpenCode supports MCP (Model Context Protocol), enabling connections to external tools and services.

Configuring MCP Servers

{
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/projects"]
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"]
    }
  }
}

Once configured, OpenCode can operate GitHub directly (create PRs, check issues, etc.), significantly expanding its capabilities.

7. FAQ

Q1: What's the difference between OpenCode and Aider?

  • OpenCode focuses more on terminal interaction experience and multi-model flexibility
  • Aider is more focused on git integration and pair programming
  • Both have their strengths — try both and find what fits your workflow best

Q2: Are free models good enough?

For daily development, free models (like locally deployed Qwen2.5-Coder-32B or DeepSeek's free tier) are more than sufficient. For large-scale project refactoring, consider Claude or GPT-4o for better code quality.

Q3: Does it support Windows?

OpenCode officially supports Linux and macOS. Windows users can run it through WSL2.

Q4: How do I control token usage?

{
  "chat": {
    "maxTokens": 4000,
    "temperature": 0.3
  }
}

Lowering maxTokens and temperature reduces per-session token consumption, but may impact code quality.

Summary

OpenCode represents an important trend in 2026 AI coding tools: open-source, model-agnostic, terminal-first. It's not a closed ecosystem owned by any single vendor — it's an open toolchain where you can freely choose the best model, the lowest cost, and the best development experience.

If you only use one AI coding tool in 2026, I'd recommend OpenCode. Its community momentum, feature maturity, and model flexibility are hard for any single competitor to fully match.

🔗 Related Links: - GitHub: github.com/sst/opencode - Docs: opencode.ai - Similar tools: Aider, OpenHands