OpenCode: AI-Assisted Coding with Free and Local LLMs


Bicycle

Most AI coding assistants are tightly coupled to a single provider. Switching often means changing tools, reconfiguring workflows, or losing context. OpenCode takes a different approach: it's an open-source, terminal-based AI coding agent that treats models as interchangeable. You pick the provider, you pick the model, and you can switch mid-session - including free and local options.

We evaluated several CLI-based coding agents and found OpenCode worth writing about specifically because of how it handles provider flexibility. This post covers what it offers and how we use it with free and local LLMs.

We already covered how OpenCode compares to Claude Code in a previous post. This one goes deeper into OpenCode itself: what it offers, how to use it with free and local LLMs, and why it matters for teams that want flexibility.

What is OpenCode?

OpenCode is an open-source CLI coding agent written in Go. It runs in your terminal and provides a beautiful TUI (Terminal User Interface).

What makes OpenCode a true agent instead of just a chat interface? For one, it understands your codebase and can autonomously navigate through files. Beyond that, it independently runs commands -- from tests and builds to linters and git operations. It proposes changes and applies them with your approval, while maintaining context throughout the entire session. An integrated tool system further enables file operations, code search, and bash execution, with LSP integration providing code intelligence across 30+ languages like TypeScript, Python, Rust, and Go.

Installation

Two simple installation options include:

1# Via curl
2curl -fsSL https://opencode.ai/install | bash
3
4# Via Homebrew
5brew install anomalyco/tap/opencode

Then you can run opencode in any project directory to start a session.

The Provider Landscape: 75+ Options

OpenCode supports a wide range of AI providers through a unified configuration system. Here's a broad overview of some of the options:

ProviderModelsCost
AnthropicClaude Sonnet/Opus/HaikuPay-per-use
OpenAIGPT-4.1, GPT-5, O3/O4Pay-per-use
GoogleGemini 2.5/3 Pro/FlashPay-per-use
GitHub CopilotGPT, Claude, Gemini modelsIncluded with Copilot subscription
GroqLlama 3Pay-per-use
OllamaAny local modelFree (your hardware)
AWS BedrockClaude, LlamaPay-per-use
Azure OpenAIGPT modelsPay-per-use
OpenRouter100+ modelsPay-per-use

The important thing: switching providers doesn't change how you work. The same commands, the same workflow, the same interface - only the "brain" behind it changes.

Free LLM Options

You don't need a paid API key to use OpenCode productively. Here are the genuinely free options:

1. GitHub Copilot (if you already have it)

Since January 2026, OpenCode supports GitHub Copilot integration. If you have a Copilot subscription (included in many GitHub plans, including the free tier for individual developers), you can use it as a backend for OpenCode.

Fair warning though: the free tier's token budget doesn't go very far. About 30 minutes to 1 hour of actual coding and it's gone for the month.

2. Ollama (free, private)

This is the option we focus on in this post and the one that ties into our company-internal LLM endpoint setup.

Ollama itself is free - but keep in mind that running models locally isn't truly "free": you're paying with hardware, electricity, and whatever it takes to run and maintain the setup. Also worth noting: always check the license of the model you're running (that's a topic of its own, and out of scope here).

OpenCode + Ollama: Local AI Coding

Ollama provides an OpenAI-compatible API for running open-source models locally. OpenCode connects to it natively.

Configuration

To use OpenCode with Ollama, we create or edit the file ~/.config/opencode/opencode.json:

 1{
 2  "$schema": "https://opencode.ai/config.json",
 3  "provider": {
 4    "ollama": {
 5      "npm": "@ai-sdk/openai-compatible",
 6      "name": "Ollama",
 7      "options": {
 8        "baseURL": "http://localhost:11434/v1"
 9      },
10      "models": {
11        "qwen2.5-coder:7b": {
12          "name": "Qwen 2.5 Coder 7B"
13        },
14        "mistral:latest": {
15          "name": "Mistral 7B"
16        },
17        "gemma3:latest": {
18          "name": "Gemma 3"
19        },
20        "qwen2.5-coder:1.5b": {
21          "name": "Qwen 2.5 Coder 1.5B (fast)"
22        }
23      }
24    }
25  }
26}

The baseURL points to your Ollama instance. You use localhost for local, or a reachable central IP for a shared team endpoint.

This configuration can also be done via ollama launch opencode --config to launch the models directly through Ollama.

Model Switching: The Power Move

One of OpenCode's strongest features is the ability to switch models mid-session. This enables a practical workflow:

  1. Plan with a strong reasoning model (e.g., Claude or GPT-4o via API)
  2. Execute with a fast, cheap model (e.g., local Qwen 2.5 Coder or Llama)
  3. Review complex decisions with the reasoning model again

In OpenCode, you can switch models with the /models command during a session. Your conversation context is preserved.

This is particularly useful in a hybrid setup: use your company's internal Ollama endpoint for 80% of tasks, and switch to a cloud API only when you hit a problem that needs frontier-model reasoning.

Key Features Worth Knowing

LSP Integration

OpenCode connects to Language Server Protocol servers to understand code beyond simple text analysis. LSP servers are automatically installed and managed by OpenCode - you don't need to host them yourself. This means:

  • Accurate symbol resolution across files
  • Diagnostics and error information
  • Automatic notification on file changes
  • Support for 30+ languages including TypeScript, Python, Rust, Go, Swift, Java, C/C++, PHP, and Terraform

MCP (Model Context Protocol) Support

OpenCode supports MCP - Anthropic's protocol for connecting AI models to external tools and data sources. This means you can:

  • Connect to STDIO-based MCP servers (local processes)
  • Connect to HTTP/SSE-based MCP servers (remote services)

Session Management

Conversations are stored locally. You can resume sessions, review past interactions, and track file changes across sessions.

Privacy

OpenCode stores zero code or context data on external servers. Your project data only goes where you tell it to - to the LLM provider you configure. With Ollama, that means nowhere outside your machine. The optional /share feature for sharing conversations is in manual mode by default and can be completely disabled for sensitive projects.

A Practical Example

Here's what using OpenCode with a local Ollama model looks like in practice:

 1$ opencode
 2> /models ollama/qwen2.5-coder:7b
 3
 4> The tests in auth_test.go are failing after the refactor.
 5  Fix them and make sure they pass.
 6
 7OpenCode will:
 81. Read auth_test.go and related source files
 92. Run `go test ./auth/...` to see the failures
103. Analyze the error output
114. Propose fixes to the test file
125. Apply the changes (with your approval)
136. Re-run the tests to verify
14
15> /models anthropic/claude-sonnet   # Switch to cloud for a harder task
16> Now review the auth module architecture.
17  Are there any security concerns with the current approach?

The key insight: routine tasks (fix tests, refactor, generate boilerplate) work well with local models. Complex reasoning (architecture review, security analysis) benefits from frontier models. OpenCode lets you use both in the same session.

Conclusion

OpenCode gives you something rare in the AI coding tool space: genuine provider freedom. Use the best model for each task, switch mid-session, and keep your options open as the model landscape evolves.

Combined with free options like Ollama, it's possible to build a productive AI-assisted coding workflow without committing to a single provider. Whether that setup fits depends on your specific context - model quality requirements, data privacy constraints, and how much you value the flexibility of switching.

Go Back explore our courses

We are here for you

You are interested in our courses or you simply have a question that needs answering? You can contact us at anytime! We will do our best to answer all your questions.

Contact us