Table of Contents

OpenCode

OpenCode is an open-source, terminal-native AI coding agent that provides intelligent code generation, refactoring, debugging, and documentation assistance. With over 129,000 GitHub stars and 800+ contributors, it has become one of the most popular open-source alternatives to proprietary coding assistants.

Repository github.com/anomalyco/opencode
License MIT
Language Go, TypeScript
Stars 129K+
Category AI Coding Agent

Key Features

Architecture

OpenCode operates as a modular, provider-agnostic system with several key components:

graph TB subgraph UI["Terminal UI"] TUI[TUI Renderer] Chat[Interactive Chat] Sessions[Session Manager] end subgraph Agent["Agent Core"] Engine[Agent Engine] Plan[Plan Mode] Build[Build Mode] end subgraph Providers["LLM Providers"] Cloud[Cloud APIs - GPT-4 / Claude / Gemini] Local[Local Models - Ollama / LM Studio] end subgraph Tools["Tool Layer"] LSP[LSP Servers] MCP[MCP Servers] Git[Git Integration] FS[Filesystem Tools] end UI --> Agent Agent --> Providers Agent --> Tools LSP --> Engine

Supported Providers

OpenCode is model-agnostic, connecting to providers via Models.dev:

Performance scales with model quality: GPT-4/Claude achieves 80-90% quality vs commercial tools; open models reach 60-70%.

Code Example

# AGENTS.md configuration example for OpenCode
# Place in your project root to provide context to the agent
#
# Project: MyApp
# Tech Stack: Python 3.12, FastAPI, PostgreSQL
# Testing: pytest with coverage
# Conventions: type hints, PEP 8, docstrings required
#
# Usage:
#   pip install opencode
#   opencode                              # launches TUI
#   opencode "refactor to async/await"    # direct command
 
import subprocess
import json
 
def run_opencode_headless(prompt, model="claude-sonnet"):
    result = subprocess.run(
        ["opencode", "--headless", "--model", model, prompt],
        capture_output=True, text=True
    )
    return json.loads(result.stdout)
 
output = run_opencode_headless("Add error handling to api/routes.py")
print(output["changes"])

References

See Also