opencode 初尝试

最近opencode很火,我也在电脑上装了。这篇文章记录一下安装和使用过程。

官方说明

OpenCode is an open source agent that helps you write code in your terminal, IDE, or desktop.

  • [*]LSP enabled Automatically loads the right LSPs for the LLM。自动识别编程语言。
  • [*]Multi-session Start multiple agents in parallel on the same project。多个对话同时进行。
  • [*]Share links Share a link to any session for reference or to debug。分享编程过程。
  • [*]Claude Pro Log in with Anthropic to use your Claude Pro or Max account
  • [*]ChatGPT Plus/Pro Log in with OpenAI to use your ChatGPT Plus or Pro account
  • [*]Any model 75+ LLM providers through Models.dev, including local models。支持各种AI模型。
  • [*]Any editor Available as a terminal interface, desktop app, and IDE extension。什么编辑器,都能用OpenCode。

安装

最简单的方式是使用Homebrew:

brew install anomalyco/tap/opencode

17d49a1866572e2827a26cfcb655a474

启动OpenCode并配置模型:

cd ~/Workspace  # 进入你的工作目录
opencode        # 启动OpenCode

image-20260120下午60449579

在TUI界面中,输入 /connect 配置模型提供商:

  • 新手推荐: OpenCode Zen(经过验证的模型)
  • 进阶选择: Claude Sonnet 4.5(编程能力强)

首次使用,运行 /init 让OpenCode分析你的项目结构。

image-20260120下午60552057

基础操作

掌握这几个核心命令就能开始使用:

/help          # 查看所有命令
@文件名         # 引用文件内容
!命令           # 执行shell命令
/undo          # 撤销操作
/redo          # 重做操作
Tab键          # 切换Plan/Build模式
Esc            # 退出、打断当前操作

初上手

先拿我的blog项目进行练手:

请分析我这个blog项目的结构和功能,然后告诉我可以用OpenCode做什么改进?

41fec82fadb26603f326c6373bd72213

1d11a8e8c8630c94c2fb0b782642eed3

image-20260204下午12500986

595f8b14f35bbee299f4fbd2e0f73958

68166df70b8a2a8ec494d9dfcc02eab4

e8f331a93ec3795bbbd85cd39ea88c04

其他类似的上手问答工作都可以试试:

  1. 检查macOS版本
  2. 显示内存使用情况
  3. 列出Homebrew安装的包
  4. 检查磁盘空间

在 Mac 下搞定了 Jekyll 环境:一次踩坑全记录 解决macOS应用程序“已损坏”警告