OpenCode CLI

OpenCode CLI

The Open-Source Claude Code Alternative

TL;DR

What is OpenCode CLI Guide?

OpenCode is an open-source terminal-based AI coding agent that supports 75+ LLM providers, including local models via Ollama, GitHub Copilot subscriptions, and ChatGPT Plus. It provides full agentic capabilities - bash execution, file operations, code search - without vendor lock-in.

What is OpenCode CLI?

OpenCode is an open-source terminal-based AI coding agent that supports 75+ LLM providers, including local models via Ollama, GitHub Copilot subscription, and ChatGPT Plus - making it the most flexible Claude Code alternative available today.

Here's the thing - as developers, we've been locked into proprietary AI coding tools. Claude Code is powerful, but it ties us to Anthropic's ecosystem. OpenCode breaks that pattern by letting us choose our provider, run models locally for complete privacy, or even use existing subscriptions we're already paying for.

Key Features

  • Provider Freedom - Switch between OpenAI, Anthropic, Ollama, Google, AWS Bedrock, and 75+ more
  • Local Model Support - Full agentic workflows with Ollama (Qwen3, Llama, DeepSeek)
  • GitHub Copilot Integration - Use existing Copilot subscription (announced January 16, 2026)
  • ChatGPT Plus Support - Connect with existing OpenAI subscription
  • Full Tooling - Bash execution, file operations, code search, LSP integration
  • Beautiful TUI - Terminal UI built with Bubble Tea, Vim-like editor
  • Session Management - Persistent SQLite storage for conversation history

Why OpenCode Over Claude Code?

The fundamental difference: Claude Code locks us to Anthropic's ecosystem, while OpenCode lets us swap providers, run local models, or bring API keys we're already paying for. When testing the same underlying model, multiple developers report they "can't tell the difference" in code quality.

January 2026 Update: GitHub officially partnered with OpenCode, allowing all Copilot subscribers (Pro, Pro+, Business, Enterprise) to authenticate directly - no additional AI license needed.

OpenCode vs Claude Code: The Real Trade-offs

OpenCode and Claude Code represent two philosophies: open flexibility versus integrated excellence. In my view, understanding the trade-offs helps us choose the right tool for our specific situation.

Vendor Lock-in

This is where OpenCode shines. Claude Code ties us strictly to Anthropic's ecosystem. If Claude changes pricing, faces outages, or restricts access, our entire AI workflow breaks. OpenCode supports 75+ providers, so we can switch models or providers anytime without changing our workflow.

Claude Code:
• Single provider (Anthropic)
• No local model option
• Per-token API billing
• Anthropic ToS applies
OpenCode:
• 75+ providers supported
• Full local model support
• Use existing subscriptions
• Your terms, your data

Privacy & Security

Two scenarios drive local model usage: compliance requirements (code can't leave the building) and privacy preferences (opt out of cloud AI entirely). OpenCode handles both beautifully - spin up Ollama, point the config at localhost, and we're running completely offline.

For teams operating under strict privacy policies - especially those requiring GDPR compliance or preventing source code from being used for model training - OpenCode paired with European LLM routers like Cortecs lets us route AI requests to compliant endpoints.

Cost Analysis

  • Claude Code: Per-token billing on Anthropic API, no subscription option
  • OpenCode + GitHub Copilot: Use existing $10-19/month subscription
  • OpenCode + ChatGPT Plus: Use existing $20/month subscription
  • OpenCode + Ollama: Free (hardware costs only)

Feature Comparison

Let's break this down honestly:

  • Code Quality: Claude Code has an 80.9% SWE-bench score - impressive for complex projects. OpenCode matches quality when using Claude models, depends on provider otherwise.
  • Context Management: Claude Code excels at large codebases. OpenCode is catching up.
  • Tooling: Both offer bash execution, file operations, code search. OpenCode adds MCP support.
  • Safety: Claude Code has mature guardrails. OpenCode's roadmap includes Docker/cloud sandboxes.

Bottom Line

Choose OpenCode if: We need model flexibility, have budget constraints, require privacy-first design, prefer terminal workflows, or value open-source philosophy.

Choose Claude Code if: We need proven top-tier performance on complex projects, work on massive codebases, want thinking mode and subagents, or have enterprise Anthropic subscriptions.

Step-by-Step Installation Guide

OpenCode installation takes about 5 minutes and can run with local models, GitHub Copilot, or ChatGPT Plus. Let's walk through all three setups.

Prerequisites

  • Node.js 20+ (or Bun)
  • Terminal/Command line
  • Git (optional, for cloning)

Step 1: Install OpenCode

# Using npm
npm install -g opencode

# Or using Bun (recommended)
bun install -g opencode

# Verify installation
opencode --version

Step 2: Choose Your Provider

Option A: GitHub Copilot (Recommended for existing subscribers)

# Launch OpenCode
opencode

# Inside OpenCode, run:
/connect

# Select "GitHub Copilot" from the list
# Complete GitHub device login flow
# Done! All Copilot models available

Option B: ChatGPT Plus/Pro

# Launch OpenCode
opencode

# Inside OpenCode, run:
/connect

# Select "OpenAI" → "ChatGPT Plus/Pro"
# Authenticate in browser
# All OpenAI models now available via /models

Option C: Local Models with Ollama (Privacy-first)

# 1. Install Ollama
# macOS/Linux:
curl -fsSL https://ollama.com/install.sh | sh
# Windows: Download from ollama.com/download

# 2. Pull a coding model
ollama pull qwen3:8b

# 3. CRITICAL: Increase context window for tool support
ollama run qwen3:8b
>>> /set parameter num_ctx 16384
>>> /save qwen3:8b-16k
>>> /bye

# 4. Start Ollama server
ollama serve

Step 3: Configure OpenCode for Ollama

Create the config file at ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "ollama": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Ollama (local)",
      "options": {
        "baseURL": "http://localhost:11434/v1"
      },
      "models": {
        "qwen3:8b-16k": {
          "name": "Qwen3 8B (16K context)"
        },
        "deepseek-coder:6.7b": {
          "name": "DeepSeek Coder 6.7B"
        }
      }
    }
  }
}

Step 4: Launch and Verify

# Start OpenCode
opencode

# List available models
/models

# Select your model and start coding!

Troubleshooting

  • Tool calls not working? - Increase num_ctx to 16K-32K in Ollama
  • Model stuck in loops? - Avoid models smaller than 7B for agentic tasks
  • Connection refused? - Ensure ollama serve is running
  • GitHub login failed? - Make sure we have active Copilot subscription
Pro Tip: For best local coding experience, use qwen3:8b or deepseek-coder:6.7b with 16K+ context. These models handle tool calls reliably.

Comparing Open-Source Coding Tools

Four major open-source tools compete for our attention: OpenCode, Llama Coder, Bolt.new (bolt.diy), and Qwen CLI-based tools. Each serves a different purpose and workflow. Let's break down when to use each one.

OpenCode CLI

OpenCode is a Go-based terminal application providing agentic AI coding assistance with multi-provider support.

  • Type: Terminal-based agentic coding assistant
  • Best for: Full agentic workflows, multi-file changes, complex refactoring
  • Unique: 75+ providers, GitHub Copilot/ChatGPT subscription support, MCP integration
  • Local models: Full support via Ollama with tool calling
  • Learning curve: Medium - terminal familiarity helps

Llama Coder (VS Code Extension)

Llama Coder is a VS Code extension providing self-hosted Copilot-style autocomplete using local models via Ollama.

  • Type: VS Code extension for inline completions
  • Best for: Code autocomplete, staying in VS Code workflow
  • Unique: Drop-in Copilot replacement, works with Ollama backend
  • Local models: Native support - the entire point
  • Learning curve: Easy - just install and configure endpoint

llama.vscode (by ggml-org)

Built by the llama.cpp team, this extension offers code completion, chat, and even an agent mode with file operations.

  • Type: VS Code extension with completion + chat + agent
  • Best for: Local-first developers wanting full IDE integration
  • Unique: Agent mode with 9 built-in tools (read/write files, grep, npm, tests)
  • Local models: Native - built specifically for llama.cpp
  • Learning curve: Easy to medium

Bolt.new / bolt.diy

Bolt.new is a browser-based AI development environment by StackBlitz that scaffolds full-stack apps from prompts.

  • Type: Browser-based app generator with live preview
  • Best for: Prototyping web apps quickly, non-developers
  • Unique: Live preview, hot reload, instant deployment
  • Local models: bolt.diy (open-source fork) supports local via Ollama
  • Learning curve: Very easy - just describe what we want

Qwen-based CLI Tools

Qwen3-Coder and Qwen2.5-Coder models can be accessed through various CLI wrappers or directly via Ollama.

  • Type: Model family + various CLI interfaces
  • Best for: Multi-language coding, agentic workflows, 256K+ context
  • Unique: 100+ programming languages, Apache 2.0 license
  • Local models: Models themselves run locally; CLI tools vary
  • Learning curve: Depends on the CLI wrapper chosen

Comparison Table

For Agentic Coding:
• OpenCode (best overall)
• llama.vscode agent mode

For Autocomplete:
• Llama Coder
• llama.vscode
For Web App Prototyping:
• Bolt.new / bolt.diy

For Maximum Context:
• Qwen3-Coder (256K tokens)

For Privacy:
• All support local models!

My Recommendation

In my view, the best setup for most developers is:

  1. Primary: OpenCode CLI for complex multi-file tasks
  2. Secondary: Llama Coder or llama.vscode for inline completions
  3. Prototyping: bolt.diy when we need to quickly scaffold web apps
  4. Model choice: Qwen3-Coder 8B or DeepSeek Coder for local use
Key Insight: These tools aren't mutually exclusive. We can run Llama Coder for autocomplete while using OpenCode for complex refactoring - both hitting the same local Ollama server.

Best Local Models for Coding in 2026

Qwen3-Coder and DeepSeek Coder lead the local coding model space, with Llama and Code Llama remaining solid options. Here's what works best for agentic coding workflows.

Top Picks for OpenCode/Ollama

1. Qwen3-Coder (8B/32B)

  • Context: 256K+ tokens - massive for complex projects
  • Languages: 100+ programming languages
  • Agentic: Excellent tool calling support
  • License: Apache 2.0 (free for commercial use)
  • RAM needed: 8B needs ~6GB, 32B needs ~20GB
ollama pull qwen3:8b
# For larger projects:
ollama pull qwen2.5-coder:32b

2. DeepSeek Coder (6.7B/33B)

  • Strength: Code generation and understanding
  • Benchmarks: Competitive with GPT-4 on Aider benchmark
  • Languages: 92+ programming languages
  • Best for: Code review, debugging, generation
ollama pull deepseek-coder:6.7b
# High-end option:
ollama pull deepseek-coder:33b

3. Code Llama (7B/13B/34B)

  • Provider: Meta
  • Strength: Solid all-rounder, well-tested
  • Languages: Python, C++, Java, PHP, TypeScript, C#, Bash
  • Best for: Those already familiar with Llama ecosystem
ollama pull codellama:7b
ollama pull codellama:13b

RAM and GPU Guidelines

8GB RAM (CPU):
• Qwen3 8B (Q4)
• DeepSeek Coder 6.7B (Q4)
• Code Llama 7B
Speed: 5-10 tokens/sec
16GB+ RAM or GPU:
• Qwen2.5-Coder 32B (Q4)
• DeepSeek Coder 33B (Q4)
• Code Llama 34B
Speed: 20-100 tokens/sec

Critical: Context Window Configuration

This is where many developers fail. Ollama defaults to 4K context even if the model supports more. For agentic workflows with tool calling, we need at least 16K:

# Set up Qwen3 with proper context
ollama run qwen3:8b
>>> /set parameter num_ctx 32768
>>> /save qwen3:8b-32k
>>> /bye

# Now use qwen3:8b-32k in OpenCode config

Model Quality Comparison

  • Code Generation: DeepSeek Coder ≈ Qwen3-Coder > Code Llama
  • Code Understanding: Qwen3-Coder > DeepSeek Coder > Code Llama
  • Tool Calling: Qwen3-Coder > DeepSeek Coder > Code Llama
  • Context Length: Qwen3-Coder (256K) > others (typically 32K-128K)
My Setup: I run Qwen3:8b-32k for day-to-day coding and switch to DeepSeek Coder when I need intensive code review. Both work great with OpenCode's agentic workflows.

Advanced OpenCode Workflows

OpenCode's power comes from combining local models with agentic capabilities - bash execution, file operations, code search, and LSP integration. Here are workflows that maximize our productivity.

Workflow 1: Private Code Review

Review sensitive code without sending it to the cloud:

# Start OpenCode with local model
opencode

# In OpenCode:
/model qwen3:8b-32k

# Ask for review:
> Review the authentication module in src/auth/ for security vulnerabilities.
> Focus on JWT handling, password hashing, and session management.

Workflow 2: Multi-File Refactoring

OpenCode can modify multiple files atomically:

> Refactor the payment processing system:
> 1. Extract the validation logic into a separate PaymentValidator class
> 2. Add proper error handling with custom PaymentError types
> 3. Update all callers to use the new structure
> 4. Add unit tests for the new validator

Workflow 3: Codebase Understanding

> Explain the architecture of this project:
> - How is routing handled?
> - Where is state management?
> - What's the database access pattern?
> - Map the key dependencies between modules

Workflow 4: Test Generation

> Generate comprehensive tests for src/utils/validation.ts:
> - Cover all edge cases
> - Include both unit tests and integration tests
> - Follow the existing test patterns in tests/

Workflow 5: Hybrid Cloud/Local

Use local for sensitive code, cloud for general tasks:

# For proprietary code:
/model qwen3:8b-32k
> Review our payment processing logic...

# For general questions:
/model claude-3-sonnet
> Explain the best practices for rate limiting in Node.js...

Session Management

OpenCode persists sessions - we can continue where we left off:

# List sessions
/sessions

# Resume a session
/session abc123

# Clear current session
/clear

MCP Integration

Connect external tools via Model Context Protocol:

// In opencode.json
{
  "mcp": {
    "servers": {
      "filesystem": {
        "command": "npx",
        "args": ["@modelcontextprotocol/server-filesystem", "/path/to/project"]
      }
    }
  }
}
Power User Tip: Combine OpenCode with git hooks. We can have it auto-review commits, generate changelogs, or validate code before push - all using local models for complete privacy.

Recommended Tools

OpenCode

Open-source terminal-based AI coding agent

Primary

Ollama

Run local LLMs with OpenAI-compatible API

Primary

Llama Coder

VS Code extension for local autocomplete

VS Code

llama.vscode

VS Code extension with agent mode by ggml-org

VS Code

bolt.diy

Open-source Bolt.new fork with local model support

Web IDE

Qwen3-Coder

Alibaba's coding model with 256K context

Models

DeepSeek Coder

High-performance open coding model

Models

Frequently Asked Questions

Yes! As of January 16, 2026, GitHub officially supports OpenCode authentication. Run /connect in OpenCode, select GitHub Copilot, and complete the device login. All Copilot Pro, Pro+, Business, and Enterprise subscriptions work.
When using the same underlying model (like Claude via API), multiple developers report identical code quality. The difference is flexibility: OpenCode supports 75+ providers including local models, while Claude Code is Anthropic-only.
Qwen3-Coder 8B offers the best balance of quality, speed, and context length (256K tokens). For more power, use Qwen2.5-Coder 32B or DeepSeek Coder 33B. Always configure at least 16K context in Ollama for agentic workflows.
Most likely your context window is too small. Ollama defaults to 4K even for models that support more. Run: ollama run model >>> /set parameter num_ctx 16384 >>> /save model-16k. Then use the new model name in OpenCode.
Yes. When using local models via Ollama, your code never leaves your machine. OpenCode is open source (auditable), and the models are just mathematical weights with no network capabilities. This is the most private option available.
Different tools for different jobs. Llama Coder is a VS Code extension for inline autocomplete. OpenCode is a terminal-based agentic assistant for complex multi-file operations. They complement each other - both can use the same Ollama backend.

Related Articles

Comments