Kritsana.prs

ChangelogContactResume

© Copyright 2026 Kritsana.Dev. All rights reserved.

Back to Blog
AIFeatured

Getting Started with OpenCode: The Open-Source Alternative to Claude Code

A complete guide to installing and using OpenCode — the open-source, terminal-native AI coding assistant that supports 75+ LLM providers as a powerful alternative to Claude Code.

April 6, 2026
·
6 min read
Getting Started with OpenCode: The Open-Source Alternative to Claude Code

If you have been using Claude Code and love the terminal-based AI coding experience but wish you had more flexibility — different models, open-source transparency, and no vendor lock-in — OpenCode is worth your attention.

Built by the SST team, OpenCode is an open-source, terminal-native AI coding assistant that supports 75+ LLM providers including Anthropic, OpenAI, Google, and local models via Ollama. This guide walks you through installation, configuration, and daily usage.

What is OpenCode?

OpenCode is a CLI/TUI (Terminal User Interface) tool that brings agentic AI coding to your terminal. Key differences from Claude Code:

| Feature | Claude Code | OpenCode | | ---------------- | ------------------ | ---------------------------- | | Source | Proprietary | MIT open-source | | Models | Claude only | 75+ providers + Ollama | | Pricing | $20-200/mo or API | Free tool, pay your provider | | Architecture | CLI tool | Client/server + HTTP API | | Local Models | No | Yes (Ollama native) | | Desktop App | Research preview | Beta available | | IDE Support | VS Code, JetBrains | VS Code |

The biggest advantage is provider independence. You can use Claude, GPT, Gemini, Llama, or any other model — and switch between them freely.

Installation

Method 1: curl (Recommended)

The fastest way to install OpenCode:

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

This downloads the latest binary and adds it to your PATH.

Method 2: Homebrew (macOS)

brew install sst/tap/opencode

Method 3: Go Install

If you have Go installed:

go install github.com/sst/opencode@latest

Method 4: Build from Source

git clone https://github.com/sst/opencode.git
cd opencode
go build -o opencode .
mv opencode /usr/local/bin/

Verify Installation

opencode --version

Initial Configuration

When you first run OpenCode in a project directory, it will guide you through setup:

cd your-project
opencode

Choose Your Provider

OpenCode supports multiple authentication methods:

Anthropic (Claude)

# Set your API key
export ANTHROPIC_API_KEY=sk-ant-your-key-here

# Or use OAuth (if available)
opencode auth login anthropic

OpenAI (GPT)

export OPENAI_API_KEY=sk-your-key-here

Google (Gemini)

export GOOGLE_API_KEY=your-key-here

Local Models (Ollama)

Run models entirely on your machine with zero API costs:

# Install Ollama
curl -fsSL https://ollama.com/install.sh | sh

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

# Configure OpenCode to use it
opencode --provider ollama --model qwen2.5-coder:32b

Configuration File

OpenCode stores configuration in opencode.json at your project root:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": "anthropic",
  "model": "claude-4-5-sonnet-20260101",
  "mcpServers": {
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "."]
    }
  }
}

Using OpenCode

Basic Commands

Once inside the TUI, you interact with OpenCode conversationally:

> Fix the TypeScript error in src/utils/auth.ts

> Write unit tests for the UserService class

> Refactor the database queries to use connection pooling

> Explain what this function does and suggest improvements

Key Keyboard Shortcuts

| Shortcut | Action | | -------- | ------------------------ | | Enter | Send message | | Ctrl+C | Cancel current operation | | Ctrl+L | Clear conversation | | Ctrl+O | Open file picker | | Tab | Autocomplete file paths | | Esc | Exit OpenCode |

File Operations

OpenCode can read, write, and edit files directly:

> Read the file src/app/page.tsx and explain the routing logic

> Create a new API endpoint at src/app/api/users/route.ts
  that handles GET and POST requests

> Update the README.md with installation instructions

Running Commands

OpenCode can execute terminal commands on your behalf:

> Run the test suite and fix any failures

> Install the zod package and add schema validation
  to the API routes

> Start the dev server and check for compilation errors

MCP (Model Context Protocol) Integration

One of OpenCode's powerful features is MCP support. You can connect external tools and data sources:

{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_TOKEN": "ghp_your_token"
      }
    },
    "postgres": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-postgres"],
      "env": {
        "DATABASE_URL": "postgresql://user:pass@localhost:5432/db"
      }
    }
  }
}

OpenCode uses per-agent glob patterns for MCP, meaning you can control which tools are available to which conversations — giving you more granular control than Claude Code's approach.

Tips for Power Users

1. Use Multiple Providers Strategically

Switch models based on the task:

# Complex architecture decisions — use the strongest model
opencode --model claude-4-5-sonnet-20260101

# Quick fixes and simple tasks — use a faster/cheaper model
opencode --model claude-4-5-haiku-20260101

# Privacy-sensitive code — use a local model
opencode --provider ollama --model qwen2.5-coder:32b

2. Custom System Prompts

Tailor OpenCode's behavior per project by adding instructions to your config:

{
  "instructions": "This is a Next.js 16 project using TypeScript, Tailwind CSS, and Payload CMS. Always use server components by default. Follow the existing code style."
}

3. Session Persistence

OpenCode's client/server architecture means sessions can persist even when you close the terminal. The SST team is building toward Workspaces that survive across sessions — a feature Claude Code's simpler CLI cannot support.

4. Cost Tracking

Since you bring your own API keys, monitor usage:

# Check token usage for the current session
# OpenCode shows token count in the TUI footer

OpenCode vs Claude Code: When to Use Which

Choose Claude Code if:

  • You want a polished, official Anthropic experience
  • You are on a Claude Pro/Max subscription
  • Your team requires a recognized vendor
  • Claude models handle 100% of your needs

Choose OpenCode if:

  • You prefer open-source software you can audit and modify
  • You need provider flexibility (switch models to save costs)
  • You want local model support for privacy
  • You need granular MCP control and session persistence
  • You enjoy customizing your development environment

Wrapping Up

OpenCode brings the power of agentic AI coding to your terminal without locking you into a single provider. Its open-source nature, 75+ model support, and client/server architecture make it a compelling choice for developers who value flexibility and control.

Install it, point it at your preferred LLM provider, and start coding. The learning curve is minimal if you have used Claude Code before — the core experience is familiar, just with more options.

  • GitHub: github.com/sst/opencode
  • Website: opencode.ai
  • Documentation: docs.opencode.ai

More in AI

Building Sub-Agents: How to Design Multi-Agent AI Systems

Building Sub-Agents: How to Design Multi-Agent AI Systems

Learn how to architect and build sub-agent systems — breaking complex AI tasks into specialized agents that collaborate, delegate, and deliver better results.

Read article
AI in Web Development

AI in Web Development

Explore how artificial intelligence is transforming web development and what it means for developers.

Read article
View all in AI