OpenCode: The Open-Source AI Coding Agent That Overtook Claude Code in 2026 — A Complete Setup & Workflow Guide
OpenCode hit 160K+ GitHub stars in 2026, surpassing Claude Code as the most popular open-source AI coding agent. This guide covers installation, multi-model routing, LSP integration, and real-world workflows for professional developers.
- ⭐ 162000
- MIT
- Updated 2026-05-19
{</* resource-info */>}
TL;DR: OpenCode is a free, MIT-licensed terminal AI coding agent with 160K+ GitHub stars. It supports 75+ LLM providers, integrates LSP for ~50ms codebase navigation, and costs $0 in software fees. This guide walks you from installation to production-grade workflows.
Why OpenCode Became the Fastest-Growing AI Dev Tool of 2026 #
The AI coding tool landscape in 2026 is defined by a single tension: convenience versus freedom. Closed-source tools like Claude Code and Cursor offer polished out-of-the-box experiences, but they lock you into proprietary models, fixed pricing tiers, and opaque data handling. OpenCode took the opposite bet—and won.
By May 2026, OpenCode had accumulated over 160,000 GitHub stars, overtaking Claude Code (122K) to become the most-starred open-source coding agent in history. Its growth wasn’t driven by marketing; it was driven by three structural advantages that matter to professional developers:
- Provider Agnosticism: Switch between GPT-5.5, Gemini 3.1 Pro, Claude Sonnet 4.6, DeepSeek-V4, local Ollama models, and 70+ other providers without rewriting your workflow.
- Zero Software Cost: MIT-licensed, no subscription. You pay only for the API tokens you consume—or nothing at all if you run local models.
- Terminal-Native Speed: Built on OpenTUI (TypeScript API + Zig backend) with native LSP integration, delivering symbol navigation in ~50 milliseconds instead of the 45-second text searches common in other agents.
What OpenCode Actually Is (And Isn’t) #
OpenCode is not a code completion plugin like GitHub Copilot. It is an autonomous coding agent that operates inside your terminal, reads your entire codebase, executes shell commands, manages Git operations, and orchestrates external tools via the Model Context Protocol (MCP).
Think of it as a senior engineer who lives in your terminal, understands your project conventions via AGENTS.md, and can implement features end-to-end while keeping you in the approval loop.
Architecture at a Glance #
┌─────────────────────────────────────────┐
│ User Input (Natural Language) │
├─────────────────────────────────────────┤
│ OpenTUI Frontend (Zig + TypeScript) │
├─────────────────────────────────────────┤
│ LSP Integration │ Models.dev Router │
│ (~50ms symbols) │ (75+ providers) │
├─────────────────────────────────────────┤
│ Sandbox Shell │ Git Native │ MCP Bus │
└─────────────────────────────────────────┘
The LSP integration is the architectural differentiator. Most AI coding agents parse code as raw text, which collapses at scale. OpenCode hooks into Language Server Protocol servers, giving it structured understanding of types, imports, and call graphs—critical for refactoring across large monorepos.
Installation: Choose Your Path #
Universal Installer (macOS & Linux) #
curl -fsSL https://opencode.ai/install | bash
This detects your OS, installs dependencies, and sets up the opencode binary globally. Typical install time: under 60 seconds.
Package Managers #
| Platform | Command |
|---|---|
| npm / bun / pnpm | npm install -g opencode-ai |
| Homebrew | brew install anomalyco/tap/opencode |
| Arch Linux | sudo pacman -S opencode |
| Windows (Scoop) | scoop install opencode |
| Windows (Chocolatey) | choco install opencode |
| Docker | docker run -it --rm ghcr.io/anomalyco/opencode |
Windows recommendation: Use WSL2 for the TUI, or install the Desktop App for a native GUI experience.
Connecting Your First AI Provider #
Launch OpenCode with opencode, then type /connect.
Option A: Bring Your Own Key (BYOK) #
Ideal if you already have API subscriptions. Supported providers include:
- Anthropic (Claude Sonnet 4.6, Opus 4.7)
- OpenAI (GPT-5.4, GPT-5.5, o3)
- Google (Gemini 3.1 Pro, Gemini 2.0 Flash)
- AWS Bedrock, Azure OpenAI, Groq
- OpenRouter (aggregates dozens of frontier and open-weight models)
Option B: OpenCode Zen #
A curated model service managed by the OpenCode team. Pre-tested for coding tasks, hosted in the US with zero data retention. Prepaid from $20; zero markup on token pricing.
Option C: Local Models via Ollama #
# Install Ollama, then pull a coding-optimized model
ollama pull gemma4:9b
ollama pull qwen3:14b
In OpenCode, select ollama://gemma4:9b. Zero API cost. Zero data leaving your machine. This is the preferred setup for defense contractors, healthcare orgs under HIPAA, and anyone working with sensitive IP.
Project Initialization: The AGENTS.md Contract #
Before OpenCode can work effectively, it needs to understand your project. The /init command generates an AGENTS.md file at your repository root—a living document that encodes your conventions.
A Strong AGENTS.md Template #
# Project: E-Commerce Microservices Platform
## Stack
- Go 1.24 + Fiber web framework
- PostgreSQL 16 (via sqlc for type-safe queries)
- Redis 7 for caching and sessions
- gRPC for inter-service communication
- Docker Compose for local dev
## Conventions
- All HTTP handlers live in `internal/handlers/{domain}/`
- Database migrations are in `db/migrations/`, never edit manually
- Use `slog` for structured logging; no `fmt.Println` in production code
- Errors wrap with `github.com/pkg/errors` to preserve stack traces
- Tests must achieve >80% coverage; use `testify` assertions
Commit this file to Git. When a teammate clones the repo and runs OpenCode, they inherit the same context—making AI assistance consistent across your team.
The Plan/Build Workflow: Safety Without Friction #
OpenCode uses a bistable mode system toggled with the Tab key:
Plan Mode (Read-Only) #
Describe what you want. OpenCode analyzes the codebase, proposes a detailed execution plan—files to modify, reasoning for each change, risk assessment—and waits for your approval. No files are touched.
Example prompt:
“Refactor the payment service to use idempotency keys for all Stripe webhook handlers. Identify race conditions in the current implementation.”
Plan mode outputs:
- Affected files and line ranges
- Proposed idempotency key schema
- Database migration requirements
- Test cases that need updating
- A rollback strategy
Review, iterate, then proceed.
Build Mode (Execution) #
OpenCode writes code, runs tests, fixes failures iteratively, and commits changes. Experimental background subagents allow parallel task execution—e.g., one agent refactoring while another writes tests and a third updates API documentation.
Real-World Workflow: Building a Feature End-to-End #
Scenario: Add OAuth 2.0 login with Google and GitHub to an existing Express + Prisma application.
Step 1: Initialize and select model
cd my-app
opencode
/init
/connect # Select Gemini 3.1 Pro for 1M-token context window
Step 2: Plan mode prompt
> Add Google and GitHub OAuth 2.0 login. Use Passport.js with JWT session
> strategy. Update Prisma schema with User and Account models following
> NextAuth conventions. Add protected route middleware. Write integration
> tests with supertest.
OpenCode identifies:
src/auth/directory needs creationprisma/schema.prismaneeds User/Account/Session models.env.exampleneeds GOOGLE_CLIENT_ID, GITHUB_CLIENT_IDsrc/middleware/requireAuth.tsfor route protectiontests/auth/oauth.test.tsfor coverage
Step 3: Switch to Build mode and execute
OpenCode creates the files, runs prisma migrate dev, executes npm test, and fixes a missing passport.serializeUser configuration it detected during test failures.
Step 4: Review and share
> /share
Generates a read-only link. Send it to your team for async review of the AI’s reasoning before merging.
Multi-Model Strategy: Optimize Cost and Quality #
The killer feature of OpenCode is task-appropriate model selection. A monolithic approach—using Claude Opus for everything—is economically irrational.
| Task Type | Recommended Model | Estimated Cost |
|---|---|---|
| Linting, formatting, simple refactors | Gemma 4 (local/Ollama) | $0 |
| Standard feature implementation | DeepSeek-V4 API or GPT-5.4 | ~$0.50-2.00/task |
| Complex architectural design | Gemini 3.1 Pro (1M context) | ~$2.00-5.00/task |
| Security audit, vulnerability analysis | Claude Sonnet 4.6 | ~$1.00-3.00/task |
| Legacy code migration (COBOL→Go) | Claude Opus 4.7 (xhigh effort) | ~$5.00-10.00/task |
Teams report 60-80% cost reductions compared to single-model subscriptions by routing each task to the cheapest capable model.
Extending OpenCode with MCP Servers #
The Model Context Protocol (MCP) transforms OpenCode from a coding agent into a general-purpose automation engine.
Example: PostgreSQL MCP #
Add to ~/.config/opencode/opencode.json:
{
"mcpServers": {
"db": {
"command": ["npx", "-y", "@modelcontextprotocol/server-postgres"],
"env": { "DATABASE_URL": "postgresql://localhost/devdb" }
}
}
}
Now you can prompt:
“Show me the schema of the orders table and suggest indexes for the slow query in
src/reports/quarterly.ts.”
OpenCode queries the live database, reads the query code, and proposes CREATE INDEX statements with EXPLAIN ANALYZE verification.
Popular MCP Integrations #
| Server | Capability |
|---|---|
@modelcontextprotocol/server-postgres | Schema inspection, query optimization |
@modelcontextprotocol/server-browser | Web scraping, visual regression testing |
@modelcontextprotocol/server-github | Issue creation, PR review, automated releases |
@modelcontextprotocol/server-slack | Notify channels on build status |
Head-to-Head: OpenCode vs. The Competition #
| Capability | OpenCode | Claude Code | Cursor | GitHub Copilot |
|---|---|---|---|---|
| License | MIT (open source) | Proprietary | Proprietary | Proprietary |
| Monthly software fee | $0 | $20-$200 | $20 | $10-$39 |
| Model flexibility | 75+ providers | Anthropic only | Limited | Limited |
| Local/offline mode | ✅ Ollama/vLLM | ❌ | ❌ | ❌ |
| Terminal-native | ✅ | ✅ | ❌ | ❌ |
| IDE extensions | VS Code, Cursor, Zed | ❌ | Built-in IDE | VS Code, JetBrains |
| LSP integration | ✅ ~50ms | ❌ Text search | Via VS Code | Via VS Code |
| MCP support | ✅ | ✅ | ❌ | ❌ |
| Agent Teams | Subagents (experimental) | ✅ Full | ❌ | ❌ |
When to choose what:
- OpenCode: Cost-conscious teams, privacy requirements, model flexibility, custom workflows
- Claude Code: Deep Anthropic integration, enterprise compliance (SOC2), Agent Teams for large orgs
- Cursor: Visual designers, non-terminal users, all-in-one IDE preference
- Copilot: Microsoft ecosystem lock-in, simplest setup for individual developers
Advanced Configuration and Performance Tuning #
Custom Model Routing Rules #
Create ~/.config/opencode/model-routes.json:
{
"routes": [
{ "pattern": "refactor|lint|format", "model": "ollama://gemma4:9b" },
{ "pattern": "security|audit|vulnerability", "model": "anthropic://claude-sonnet-4.6" },
{ "pattern": "architecture|design|microservice", "model": "google://gemini-3.1-pro" }
]
}
OpenCode automatically selects the cheapest appropriate model based on your prompt keywords.
Workspace Persistence #
OpenCode’s experimental Workspaces feature saves full session context—including file states, conversation history, and LSP caches—so you can resume a complex refactoring task days later without losing context.
Troubleshooting Common Issues #
“Context too large” errors
- Disable unused MCP servers in
opencode.json - Use per-agent tool configuration to limit active MCPs
- Switch to Gemini 3.1 Pro for its 1M+ token window
Slow responses on large codebases
- Ensure LSP server is running (
/lsp statusin OpenCode) - Exclude
node_modules/,.git/, and build artifacts from indexing - Use
.opencodeignoresyntax identical to.gitignore
Model provider timeouts
- Increase timeout in provider config (default: 30s)
- For local models, verify Ollama is responsive:
curl http://localhost:11434/api/tags
Recommended Hosting & Infrastructure #
Before deploying these tools into production, you’ll need solid infrastructure. Two options dibi8 actually uses and recommends:
- DigitalOcean — $200 free credit for 60 days across 14+ global regions. The default option for indie devs running open-source AI tools.
- HTStack — Hong Kong VPS with low-latency access from mainland China. This is the same IDC that hosts dibi8.com — battle-tested in production.
Affiliate links — they don’t cost you extra and they help keep dibi8.com running.
Conclusion: The Modular Future of AI Coding #
The 2025-2026 AI coding tool wars reveal a clear pattern: as frontier models converge in capability (GPT-5.5, Claude Sonnet 4.6, Gemini 3.1 Pro now score within 5% of each other on SWE-bench), the differentiation shifts to the orchestration layer. OpenCode’s bet is that developers want to own this layer—to mix, match, and migrate models as the market evolves.
160,000 stars later, that bet appears to be paying off. OpenCode won’t replace senior engineers, but it eliminates the boilerplate tax that consumes 30-40% of a developer’s week. The remaining time is for architecture, for taste, for the decisions that only humans can make.
Install it today. Your terminal is already open.
curl -fsSL https://opencode.ai/install | bash
References
- GitHub Repository: https://github.com/anomalyco/opencode
- Documentation: https://opencode.ai/docs
- MCP Specification: https://modelcontextprotocol.io
- Models.dev Directory: https://models.dev
Last updated: 2026-05-19. The AI tooling landscape evolves rapidly; verify details against official documentation.
💬 Discussion