Skills2026年4月9日·1 分钟阅读

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.

Agent 就绪

先审查再安装

这个资产需要先审查。复制的指令会要求 Agent dry-run、列出写入项,确认后再继续。

Needs Confirmation · 64/100策略:需确认
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Community
入口
step-1.md
先审查命令
npx -y tokrepo@latest install 4374a5c2-33ce-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run,确认写入项后再运行此命令。

TL;DR
OpenCode is an open-source terminal AI coding agent with TUI design, LSP integration, and multi-provider LLM support.
§01

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.

§02

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.

§03

How to use

  1. 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
  1. Configure your LLM provider:
export OPENAI_API_KEY='sk-...'
# Or
export ANTHROPIC_API_KEY='sk-ant-...'
  1. 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.

§04

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
§05

Related on TokRepo

§06

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.

常见问题

Is OpenCode free?+

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.

How does OpenCode compare to Claude Code?+

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.

Does OpenCode support local models?+

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.

What is LSP integration?+

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.

Can OpenCode edit files directly?+

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.

引用来源 (3)
🙏

来源与感谢

Created by anomalyco. Licensed under MIT.

OpenCode — ⭐ 140,000+

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产