跳到主要内容
OpenCode:开源版 Claude Code,支持多模型与远程终端 | 极客日志
编程语言 AI
OpenCode:开源版 Claude Code,支持多模型与远程终端 OpenCode 是一款开源 AI 编程智能体,类似 Claude Code 但不绑定特定模型。支持终端、桌面及 IDE 插件,兼容 75+ 个 LLM 提供商。具备 LSP 自动加载、TUI 交互、会话共享、远程控制等功能。内置 Build 和 Plan 模式,支持 MCP 协议扩展能力及自定义 Skills。提供 CLI 非交互模式及 Web 界面,可集成 GitHub Actions。支持本地或云端 API Key 配置,适合开发者进行自动化编程辅助。
未来可期 发布于 2026/3/30 更新于 2026/5/29 29 浏览
简介
OpenCode 是一个 100% 开源的 AI 编程智能体,可以在终端、桌面应用或 IDE 里使用。
与 Claude Code 的区别:
完全开源 :代码全在 GitHub 上,可自由修改
不绑定模型 :支持 Claude、GPT、Gemini、DeepSeek 甚至本地模型,兼容 75+ 个 LLM provider
内置 LSP 支持 :自动识别项目语言并加载对应 LSP
TUI 体验 :基于 Neovim 用户设计,对终端交互有深度优化
客户端/服务端架构 :支持在电脑运行 OpenCode,通过手机远程控制
核心功能与特点:
🔌 LSP 自动加载 :根据项目自动配置语言服务器
🧵 多会话并行 :同一项目可同时开启多个 Agent
🔗 分享会话链接 :遇到问题可分享给同事 debug
🔐 Claude Pro 直连 :支持登录 Anthropic 直接使用订阅
🌐 全平台支持 :终端、桌面应用、IDE 插件均有
安装
官方推荐一键脚本:
curl -fsSL https://opencode.ai/install | bash
各平台包管理器支持:
brew install opencode
choco install opencode
scoop bucket add extras
scoop install extras/opencode
npm install -g opencode-ai
docker run -it --rm ghcr.io/anomalyco/opencode
paru -S opencode-bin
桌面应用 Beta 版支持 macOS(Intel/Apple Silicon)、Windows 和 Linux(deb/rpm):
下载地址:https://opencode.ai/download
brew install --cask opencode-desktop
快速开始 cd /path/to/project
opencode
首次使用建议先运行 /init 命令,让 OpenCode 分析项目,自动生成 AGENTS.md 文件:
该文件帮助 OpenCode 理解项目结构和编码规范,建议 commit 到 Git。
两种内置 Agent OpenCode 内置两种 Agent,用 Tab 键切换:
Build 模式 (默认):全权限,可读写文件、执行命令
Plan 模式 :只读模式,仅分析和规划,不修改代码
探索不熟悉代码库
先规划再动手的工作流程
让 AI 出方案但不执行
还有 @general 子智能体,可处理复杂搜索和多步骤任务。
配置模型
Anthropic(Claude)
OpenAI(GPT)
DeepSeek
Google Vertex AI
Ollama(本地模型)
LM Studio
llama.cpp
Groq
Together AI
Fireworks AI
OpenRouter
选择 provider 输入 API Key。Key 保存在 ~/.local/share/opencode/auth.json。
CLI 命令详解
非交互模式:脚本自动化 opencode run "Explain the use of context in Go"
opencode run --model anthropic/claude-3.5-sonnet --file ./src/main.py "帮我优化这段代码"
远程控制:服务器 + TUI 分离
opencode serve --port 4096 --hostname 0.0.0.0
opencode attach http://10.20.30.40:4096
Web 界面
会话管理
opencode session list
opencode export <sessionID>
opencode import session.json
opencode import https://opencode.ai/s/abc123
统计消耗 opencode stats
opencode stats --days 7 --models
GitHub 集成 设置 GitHub Actions 工作流,自动处理 issue、PR 等任务。
MCP Server 集成 MCP(Model Context Protocol)用于给 AI 智能体扩展工具能力。OpenCode 原生支持 MCP。
添加本地 MCP Server {
"$schema" : "https://opencode.ai/config.json" ,
"mcp" : {
"my-local-mcp" : {
"type" : "local" ,
"command" : [ "npx" , "-y" , "@modelcontextprotocol/server-everything" ] ,
"enabled" : true
}
}
}
添加远程 MCP Server {
"$schema" : "https://opencode.ai/config.json" ,
"mcp" : {
"sentry" : {
"type" : "remote" ,
"url" : "https://mcp.sentry.dev/mcp" ,
"oauth" : { }
}
}
}
Show me the latest unresolved issues in my project. use sentry
实用 MCP 示例 { "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" } } }
MCP 管理命令
opencode mcp add
opencode mcp list
opencode mcp debug my-oauth-server
opencode mcp logout my-oauth-server
Agent Skills:自定义技能 定义可复用的技能,让 Agent 在特定场景下自动加载。
创建一个 Skill 在项目里创建 .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.
Skill 存放位置
项目级:.opencode/skill/<name>/SKILL.md
全局级:~/.config/opencode/skill/<name>/SKILL.md
Claude 兼容:.claude/skills/<name>/SKILL.md
权限控制 在 opencode.json 里控制哪些 Skill 可用:
{
"permission" : {
"skill" : {
"pr-review" : "allow" ,
"internal-*" : "deny" ,
"experimental-*" : "ask" ,
"*" : "allow"
}
}
}
OpenCode Zen:付费服务 官方提供 OpenCode Zen 服务,精选针对编程智能体优化过的模型。充值按用量付费,无需自行申请 API。
Zero markup(无加价),价格透明
余额到 5 刀自动充值 20 刀
设置每月消费限额
若已有各家的 API Key,可直接使用,Zen 非必须。
命令速查表 命令 作用 Tab切换 Build/Plan 模式 /init初始化项目 /connect配置 API Key /models查看可用模型 /share分享当前会话 /undo撤销上一步修改 /redo重做 @模糊搜索项目文件 @general调用通用子智能体
命令 作用 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升级版本
和 Claude Code 对比 特性 OpenCode Claude Code 开源 ✅ 100% MIT ❌ 闭源 模型 任意(75+ providers) 仅 Claude 价格 按 API 实际消耗 Claude 订阅费 LSP ✅ 开箱即用 ❌ MCP 支持 ✅ 完整支持 ✅ Skills ✅ 支持 ✅ TUI ✅ 极致体验 ✅ Web 界面 ✅ ❌ 桌面应用 ✅ Beta ❌ 远程控制 ✅ ❌ GitHub Agent ✅ ❌
总结 OpenCode 是一款功能全面的开源编程智能体:
CLI 非交互模式方便写脚本
服务器/客户端分离支持远程控制
完整的 MCP 生态可无限扩展能力
Skills 让团队协作更顺畅
GitHub Agent 替代部分 DevOps 工作
完全开源,不绑定任何厂商
支持模型众多
TUI 交互体验佳
MCP、Skills 等高级功能齐全
客户端/服务端架构灵活
桌面应用为 Beta 版,可能有 bug
没有 Claude Code 那种原生集成的流畅度
入门需自行配置 API Key
相关免费在线工具 RSA密钥对生成器 生成新的随机RSA私钥和公钥pem证书。 在线工具,RSA密钥对生成器在线工具,online
Mermaid 预览与可视化编辑 基于 Mermaid.js 实时预览流程图、时序图等图表,支持源码编辑与即时渲染。 在线工具,Mermaid 预览与可视化编辑在线工具,online
随机西班牙地址生成器 随机生成西班牙地址(支持马德里、加泰罗尼亚、安达卢西亚、瓦伦西亚筛选),支持数量快捷选择、显示全部与下载。 在线工具,随机西班牙地址生成器在线工具,online
Base64 字符串编码/解码 将字符串编码和解码为其 Base64 格式表示形式即可。 在线工具,Base64 字符串编码/解码在线工具,online
Base64 文件转换器 将字符串、文件或图像转换为其 Base64 表示形式。 在线工具,Base64 文件转换器在线工具,online
Markdown转HTML 将 Markdown(GFM)转为 HTML 片段,浏览器内 marked 解析;与 HTML转Markdown 互为补充。 在线工具,Markdown转HTML在线工具,online