
大家好,我是 Ai 学习的老章
今天给大家介绍一个我最近在用的 AI 编程神器 —— OpenCode。4.6万 Star,500+ 贡献者,每月被 65 万开发者使用。这货基本上就是开源版的 Claude Code,而且完全不绑定任何一家模型提供商!

OpenCode 是一个 100% 开源的 AI 编程智能体,可以在终端、桌面应用或 IDE 里使用。
和 Claude Code 有什么区别?官方自己也说了:
核心功能与特点:
安装方式超级多,官方推荐一键脚本:
curl -fsSL https://opencode.ai/install | bash
各平台包管理器也都支持:
# macOS / Linux
brew install opencode
# Windows (Chocolatey)
choco install opencode
# Windows (Scoop)
scoop bucket add extras
scoop install extras/opencode
# npm/pnpm/yarn
npm install -g opencode-ai
# Docker(也能用)
docker run -it --rm ghcr.io/anomalyco/opencode
# Arch Linux
paru -S opencode-bin
桌面应用也有 Beta 版了,支持 macOS(Intel/Apple Silicon)、Windows 和 Linux(deb/rpm):
下载地址:https://opencode.ai/download

# macOS 通过 Homebrew 安装桌面版
brew install --cask opencode-desktop
还可以直接在IDE中直接安装插件

进入项目目录,运行 opencode 就能启动:
cd /path/to/project
opencode
首次使用建议先运行 /init 命令,让 OpenCode 分析你的项目,自动生成一个 AGENTS.md 文件:
/init
这个文件可以帮助 OpenCode 更好地理解你的项目结构和编码规范,建议 commit 到 Git 里。
OpenCode 内置了两种 Agent,用 Tab 键切换:
Plan 模式特别适合:
还有个 @general 子智能体,可以处理复杂搜索和多步骤任务。
OpenCode 支持的模型提供商多到离谱,文档里列了 30 多个:
配置 API Key 超简单,直接在界面里运行:
/connect
选择你要用的 provider,输入 API Key 就完事了。Key 会保存在 ~/.local/share/opencode/auth.json。
OpenCode 的 CLI 功能非常强大,远不止一个 opencode 命令。来看看有哪些骚操作:
不想打开 TUI?直接命令行问问题:
opencode run "Explain the use of context in Go"
这个太适合写脚本/自动化了。还可以指定模型、附加文件:
opencode run --model anthropic/claude-3.5-sonnet --file ./src/main.py "帮我优化这段代码"
这是我觉得最骚的设计。你可以在服务器上启动一个 headless 服务:
# 在服务器上
opencode serve --port 4096 --hostname 0.0.0.0
然后在另一台机器(甚至手机)上远程连接:
# 在本地
opencode attach http://10.20.30.40:4096
这意味着什么?你可以让一台高性能服务器跑 OpenCode 后端,自己用轻薄本甚至 iPad 远程操控。对于需要在服务器上编译/测试的场景,简直不要太爽。
不喜欢终端?还有 Web 界面:
opencode web
会自动打开浏览器,通过 Web 界面操作 OpenCode。
# 列出所有会话
opencode session list
# 导出会话(方便分享或备份)
opencode export <sessionID>
# 导入会话(支持 JSON 文件或分享链接)
opencode import session.json
opencode import https://opncd.ai/s/abc123
想知道自己用了多少 token、花了多少钱?
opencode stats
opencode stats --days 7 --models # 按模型统计最近7天
OpenCode 还能直接当 GitHub Agent 用!在仓库里安装:
opencode github install
这会设置 GitHub Actions 工作流,让 OpenCode 自动处理 issue、PR 等任务。
MCP(Model Context Protocol) 是 Anthropic 搞的协议,用来给 AI 智能体扩展工具能力。OpenCode 原生支持 MCP,配置起来超简单。
在 opencode.json 配置文件里加:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"my-local-mcp": {
"type": "local",
"command": ["npx", "-y", "@modelcontextprotocol/server-everything"],
"enabled": true
}
}
}
远程服务器也能用,比如接入 Sentry 来查 bug:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"sentry": {
"type": "remote",
"url": "https://mcp.sentry.dev/mcp",
"oauth": {}
}
}
}
配置完后认证一下:
opencode mcp auth sentry
然后就可以在对话里用了:
Show me the latest unresolved issues in my project. use sentry
官方文档给了几个实用例子:
Context7 - 搜索技术文档:
{
"mcp": {
"context7": {
"type": "remote",
"url": "https://mcp.context7.com/mcp"
}
}
}
使用:Configure a Cloudflare Worker script to cache JSON API responses for five minutes. use context7
Grep by Vercel - 搜索 GitHub 代码:
{
"mcp": {
"gh_grep": {
"type": "remote",
"url": "https://mcp.grep.app"
}
}
}
不确定怎么实现某个功能?让它帮你在 GitHub 上搜代码示例!
# 添加 MCP 服务器(交互式)
opencode mcp add
# 列出所有已配置的 MCP
opencode mcp list
# 调试 OAuth 问题
opencode mcp debug my-oauth-server
# 登出
opencode mcp logout my-oauth-server
这是 OpenCode 的另一个杀手级功能:Skills。你可以定义可复用的技能,让 Agent 在特定场景下自动加载。
在项目里创建 .opencode/skill/<name>/SKILL.md,比如 .opencode/skill/git-release/SKILL.md:
---
name: git-release
description: Create consistent releases and changelogs
license: MIT
compatibility: opencode
metadata:
audience: maintainers
workflow: github
---
## What I do
- Draft release notes from merged PRs
- Propose a version bump
- Provide a copy-pasteable `gh release create` command
## When to use me
Use this when you are preparing a tagged release.
Ask clarifying questions if the target versioning scheme is unclear.
OpenCode 会从这些位置查找 Skill:
.opencode/skill/<name>/SKILL.md~/.config/opencode/skill/<name>/SKILL.md.claude/skills/<name>/SKILL.md(方便从 Claude Code 迁移)可以在 opencode.json 里控制哪些 Skill 可用:
{
"permission": {
"skill": {
"pr-review": "allow",
"internal-*": "deny",
"experimental-*": "ask",
"*": "allow"
}
}
}
支持通配符,比如 internal-* 可以匹配所有 internal- 开头的 Skill。
这个功能太适合团队协作了!你可以把常用的代码规范、发布流程、Code Review 检查清单都封装成 Skill,团队成员直接复用。
如果你懒得折腾各种模型 API,官方还搞了个 OpenCode Zen 服务。
Zen 是什么?就是官方帮你精选了一批专门针对编程智能体优化过的模型,测试过了,好用的才放进来。你只需要充值 20 刀,按用量付费,不用自己去各个平台申请 API。
说白了就是"交钱省心"模式。关键是:
不过得说一句,如果你已经有各家的 API Key,直接用就行,Zen 不是必须的。
命令 | 作用 |
|---|---|
Tab | 切换 Build/Plan 模式 |
/init | 初始化项目 |
/connect | 配置 API Key |
/models | 查看可用模型 |
/share | 分享当前会话 |
/undo | 撤销上一步修改 |
/redo | 重做 |
@ | 模糊搜索项目文件 |
@general | 调用通用子智能体 |
CLI 命令:
命令 | 作用 |
|---|---|
opencode run "prompt" | 非交互模式运行 |
opencode serve | 启动 headless 服务 |
opencode attach <url> | 连接远程服务 |
opencode web | 启动 Web 界面 |
opencode stats | 查看用量统计 |
opencode session list | 列出会话 |
opencode export <id> | 导出会话 |
opencode mcp add | 添加 MCP 服务器 |
opencode mcp list | 列出 MCP 服务器 |
opencode github install | 安装 GitHub Agent |
opencode upgrade | 升级版本 |
特性 | OpenCode | Claude Code |
|---|---|---|
开源 | ✅ 100% MIT | ❌ 闭源 |
模型 | 任意(75+ providers) | 仅 Claude |
价格 | 按 API 实际消耗 | Claude 订阅费 |
LSP | ✅ 开箱即用 | ❌ |
MCP 支持 | ✅ 完整支持 | ✅ |
Skills | ✅ 支持 | ✅ |
TUI | ✅ 极致体验 | ✅ |
Web 界面 | ✅ | ❌ |
桌面应用 | ✅ Beta | ❌ |
远程控制 | ✅ | ❌ |
GitHub Agent | ✅ | ❌ |
OpenCode 是我目前用过最舒服的开源编程智能体。不只是"能用",而是功能真的很全:
优点:
不足:
4.6 万 Star 的项目,500 多个贡献者,这势头很猛。喜欢折腾的朋友,强烈建议试试。
项目地址:https://github.com/anomalyco/opencode
官网:https://opencode.ai
文档:https://opencode.ai/docs