OpenCode — Open-Source AI Coding Agent for Terminal
Open-source AI coding agent with 140K+ stars. TUI-first design, LSP integration, works with Claude, OpenAI, Google, or local models. Two built-in agents: build and plan. MIT license.
What it is
OpenCode is an open-source AI coding agent designed for terminal-first workflows. It features a TUI (terminal user interface) for interactive coding sessions, LSP (Language Server Protocol) integration for code intelligence, and support for multiple LLM providers including OpenAI, Anthropic, and local models. The project provides a free alternative to commercial terminal coding agents.
Developers who prefer working in the terminal and want an AI coding assistant that integrates with their existing command-line workflow benefit most. OpenCode brings code understanding, generation, and review capabilities without leaving the terminal.
How it saves time or tokens
OpenCode's LSP integration provides the AI with type information, definitions, and references from your project without sending entire files into context. This targeted context injection reduces token usage while improving code suggestion accuracy. The TUI provides a persistent session with history, so you avoid re-explaining context across separate prompts. Multi-provider support lets you choose the most cost-effective model for each task.
How to use
- Install OpenCode:
# Via Go
go install github.com/opencode-ai/opencode@latest
# Or download binary from releases
curl -sSL https://github.com/opencode-ai/opencode/releases/latest/download/opencode-linux-amd64 -o opencode
chmod +x opencode
- Configure your LLM provider:
export OPENAI_API_KEY='sk-...'
# Or
export ANTHROPIC_API_KEY='sk-ant-...'
- Start an interactive session in your project directory:
cd my-project
opencode
The TUI launches with your project context loaded. Start asking questions or requesting code changes.
Example
# Non-interactive mode for one-shot tasks
opencode 'Add error handling to all HTTP handlers in cmd/api/'
# Review a specific file
opencode 'Review src/auth/jwt.go for security issues'
# Generate tests
opencode 'Write table-driven tests for the ParseConfig function in config.go'
# Interactive TUI session
opencode
> /diff # Show pending changes
> /apply # Apply suggested changes
> /undo # Revert last change
Related on TokRepo
- AI Coding Tools -- Terminal coding agents and developer tools
- Automation Tools -- Workflow automation for developers
Common pitfalls
- OpenCode requires an LLM API key. Without one, the agent cannot function. Local model support (Ollama) is available but requires separate setup.
- LSP integration depends on having the appropriate language server installed (gopls for Go, typescript-language-server for TypeScript, etc.). Without it, OpenCode falls back to file-based context.
- The TUI uses terminal features that may not render correctly in all terminal emulators. Use modern terminals (iTerm2, Alacritty, WezTerm) for the best experience.
Frequently Asked Questions
Yes. OpenCode is open source and free to use. You pay only for the LLM API usage from your chosen provider (OpenAI, Anthropic, etc.). Local model support via Ollama eliminates API costs entirely.
Both are terminal-based AI coding agents. Claude Code is Anthropic's official tool with deep Claude integration. OpenCode is open source and supports multiple providers. Claude Code has more polished workflows; OpenCode offers provider flexibility and community contributions.
Yes. OpenCode supports Ollama and other OpenAI-compatible local model servers. Point the configuration to your local endpoint and use any model available on your machine.
LSP (Language Server Protocol) provides OpenCode with code intelligence -- type information, function signatures, references, and diagnostics. This gives the AI more precise context about your code without sending entire files, reducing token usage and improving suggestions.
Yes. In both interactive and non-interactive modes, OpenCode can read, create, and modify files. It shows diffs before applying changes and supports undo. Changes are applied to your working directory but not committed automatically.
Citations (3)
- OpenCode GitHub Repository— OpenCode is an open-source AI coding agent with TUI
- Language Server Protocol Specification— LSP integration for code intelligence
- OpenCode README— Multi-provider LLM support including local models
Related on TokRepo
Source & Thanks
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.