OpenCode 2.0
OpenCode 2.0
OpenCode 2.0 is a major overhaul. It draws on millions of daily users’ experience to deliver a system that can flex to everything an agent needs to be. There are quite a lot of new features, performance improvements, and bug fixes but here are some of the more impactful user-facing changes.
OpenCode 2.0 是一次重大升级。它汲取了数百万日常用户的经验,旨在提供一个能够灵活适应智能体(agent)各种需求的系统。此次更新包含了大量新功能、性能改进和错误修复,以下是一些对用户影响较大的变化。
From the beginning OpenCode adopted a client/server model. However, this was not something it took advantage of by default and was mostly used by power users.
从一开始,OpenCode 就采用了客户端/服务器模型。然而,这并非默认启用的功能,且主要由高级用户使用。
In 2.0 this server now automatically runs as a single background process on your machine. When you open up a TUI, the web interface or the desktop app they’re all talking to the same central process.
在 2.0 版本中,该服务器现在会自动作为单一后台进程在您的机器上运行。当您打开 TUI、Web 界面或桌面应用程序时,它们都会与同一个中央进程进行通信。
If you’re using the programmatic client @opencode/client to make your own scripts, they will autodiscover the local service and just work. This is particularly useful for scheduled tasks. You can also call it via CLI by using opencode api commands.
如果您正在使用编程客户端 @opencode/client 来编写自己的脚本,它们将自动发现本地服务并直接运行。这对于定时任务特别有用。您也可以通过 CLI 使用 opencode api 命令来调用它。
You can expose it to other hosts and run /pair or opencode pair to connect it to other applications. We have native apps in the works that take advantage of this flow.
您可以将其暴露给其他主机,并运行 /pair 或 opencode pair 将其连接到其他应用程序。我们正在开发利用此流程的原生应用程序。
The old API grew haphazardly as we and the world collectively learned what agents are and should be. It was bad.
旧版 API 是在我们与全球用户共同探索智能体的定义及其应有形态的过程中随意增长起来的。它非常糟糕。
We started from scratch and examined all the weird use cases across the millions of users who use OpenCode every day. It now supports nearly anything you need to be able to do.
我们从零开始,审视了每天使用 OpenCode 的数百万用户所涉及的所有特殊用例。现在,它几乎支持您需要完成的任何操作。
OpenCode is also aware of its own API and will call it to do useful things like moving the current session into a git worktree when starting new work.
OpenCode 现在也能感知自身的 API,并会调用它来执行一些有用的操作,例如在开始新工作时将当前会话移动到 git 工作树中。
We’ve also shipped a new client package @opencode/client that contains clients for vanilla JavaScript as well as Effect.
我们还发布了一个新的客户端包 @opencode/client,其中包含了适用于原生 JavaScript 以及 Effect 的客户端。
The models love to write code and OpenCode 2.0 takes advantage of that more than any other coding agent. We’ve built a minimal JavaScript interpreter in the @opencode/codemode package.
模型非常擅长编写代码,而 OpenCode 2.0 比任何其他编码智能体都更充分地利用了这一点。我们在 @opencode/codemode 包中构建了一个极简的 JavaScript 解释器。
This package ingests MCP servers or OpenAPI endpoints, converting them into functions that the agent can call in a script. It can run these scripts natively without the complexity of Node.js VMs or embedding complicated solutions like QuickJS.
该包可以摄取 MCP 服务器或 OpenAPI 端点,并将它们转换为智能体可以在脚本中调用的函数。它无需 Node.js 虚拟机或嵌入 QuickJS 等复杂解决方案,即可原生运行这些脚本。
This lets your agent write scripts that can do things like call a tool, map over the results and call another tool. Single round trip instead of calling them one at a time.
这使得您的智能体能够编写脚本来执行诸如调用工具、映射结果并调用另一个工具等操作。实现单次往返,而不是一次只调用一个。
All MCP servers in 2.0 are opted into codemode by default. This means you can add a thousand of them with minimal context bloat and your agent will discover and compose them to get things done.
2.0 版本中的所有 MCP 服务器默认都加入 codemode。这意味着您可以添加上千个服务器而不会造成过多的上下文膨胀,您的智能体将能够发现并组合它们以完成任务。
The latest batch of models are incredibly good at orchestration and it is important for harnesses to let them express the full extent of that capability.
最新的一批模型在编排方面表现极其出色,因此对于开发框架(harnesses)而言,让它们充分发挥这种能力至关重要。
First, we’ve added background subagents. This allows the primary agent to kick off some work to another one while it continues.
首先,我们增加了后台子智能体。这允许主智能体在继续工作的同时,将部分任务分派给另一个智能体。
This happens automatically but you can also trigger it manually - even with a different model. It lets you do things like “spawn a background fable subagent to review this code” while you keep prompting the primary agent.
这会自动发生,但您也可以手动触发它——甚至可以使用不同的模型。这让您可以执行诸如“生成一个后台 fable 子智能体来审查这段代码”的操作,同时继续向主智能体发送提示。
Second, we’ve added background shell commands. The shell tool can be invoked asynchronously so long-running work does not have to block the primary agent. It’ll be notified when things are complete.
其次,我们增加了后台 shell 命令。Shell 工具可以异步调用,因此长时间运行的任务不必阻塞主智能体。任务完成后,主智能体会收到通知。
If any foreground shell command or subagent takes longer than you expect, you can hit a hotkey to move them to the background so you can keep prompting.
如果任何前台 shell 命令或子智能体运行时间超过预期,您可以按下快捷键将其移至后台,以便继续进行提示。
Although OpenCode 1.0 had a plugin system, it never got the attention it needed. To correct that, we forced ourselves to implement nearly every OpenCode 2.0 feature as an internal plugin and there are now 80+ of them. This guarantees that the Plugin API stays well maintained.
尽管 OpenCode 1.0 拥有插件系统,但它从未得到应有的重视。为了纠正这一点,我们强制将几乎每一个 OpenCode 2.0 功能都实现为内部插件,目前已有 80 多个。这保证了插件 API 能够得到良好的维护。
We’ve also promoted TUI plugins from experimental to stable. Since it is all powered by OpenTUI, you can build nearly anything. Here is an example of something useless.
我们还将 TUI 插件从实验性提升为稳定版。由于这一切都由 OpenTUI 提供支持,您可以构建几乎任何东西。这里有一个无用功能的示例。
We also spent quite a lot of time ensuring everything in OpenCode 2.0 can be hot-reloaded. So it can write a plugin for itself mid-session and use it right away - we covered the design of this in a previous blogpost.
我们还花费了大量时间确保 OpenCode 2.0 中的所有内容都可以热重载。因此,它可以在会话期间为自己编写插件并立即使用——我们在之前的博客文章中介绍了这一设计。
You can ask OpenCode to build whatever plugin you want and it knows how to. But if you do want to read the docs, they are available here.
您可以要求 OpenCode 构建您想要的任何插件,它知道如何操作。但如果您确实想阅读文档,可以在此处获取。
OpenCode can also now be used as a library with the @opencode/sdk package. This is the exact same code that powers our CLI.
OpenCode 现在也可以通过 @opencode/sdk 包作为库使用。这与驱动我们 CLI 的代码完全相同。
This means you can strip it down and make your own flavor of OpenCode that runs on a server or in specialized environments like Durable Objects. And then you can connect to it from any OpenCode client since it speaks the standard OpenCode server protocol.
这意味着您可以对其进行精简,制作出属于您自己的 OpenCode 版本,并在服务器或 Durable Objects 等专用环境中运行。由于它遵循标准的 OpenCode 服务器协议,您可以从任何 OpenCode 客户端连接到它。
It also has an optional Effect-based API.
它还提供了一个可选的基于 Effect 的 API。
This one is still in development as things are shifting but you can already use it.
由于相关内容仍在调整中,该功能尚处于开发阶段,但您已经可以使用它。
To upgrade the CLI, make sure you’re on the latest 1.x release, then run opencode upgrade —major.
要升级 CLI,请确保您使用的是最新的 1.x 版本,然后运行 opencode upgrade --major。
To upgrade your desktop app, download the latest here.
要升级您的桌面应用程序,请在此处下载最新版本。
There are some breaking changes.
存在一些破坏性变更。
1.0 plugins will not work in 2.0
1.0 版本的插件在 2.0 中无法工作。
Server API is completely different
服务器 API 完全不同。
tui.json config is moved to json
tui.json 配置已迁移至 json。
There are a lot of other changes but they are backwards compatible. It is worth pointing OpenCode at this doc so it can migrate things for you.
还有许多其他更改,但它们是向后兼容的。建议让 OpenCode 读取此文档,以便它能为您迁移相关内容。