OpenCode 终极入门指南:开源 AI 编程助手的安装、配置与高阶玩法

Claude Code 的最佳开源替代 | 隐私优先、多模型支持与终端极致体验

本文详解如何安装和使用 OpenCode——2026 年最热门的开源 AI 编程代理。涵盖终端、桌面版及 VS Code 插件多种安装方式,深入解析 Antigravity 插件认证(解锁 Gemini 3 Pro/Claude 4.5)、OpenRouter 多模型接入配置。重点介绍 LSP 智能感知、多会话并行、会话分享等亮点功能。助您打造零摩擦、完全掌控数据的本地 AI 开发工作流
Abstract
想要拥有 Claude Code 的强大能力,却担心数据隐私或订阅费用?OpenCode 是您的最佳选择。这款由前滑铁卢大学团队打造的开源 AI 代理,主打“零摩擦”体验和“模型无关性”,支持在终端、桌面及 IDE 中无缝运行。本文将带您从零开始,掌握 OpenCode 的多平台安装技巧,配置 Antigravity 插件以解锁 Google 内部顶级模型,并通过 OpenRouter 接入全球 75+ 大模型。此外,我们将深入解析其 LSP 智能感知、多会话并行处理及隐私保护机制,助您构建高效、安全的下一代编程工作流

1. 背景

OpenCode 是一个开源的 AI 编程代理(AI coding agent),支持在终端(Terminal)、桌面应用和主流 IDE(如 VS Code)中与 AI 交互完成代码相关任务。

OpenCode 可以帮助我们理解代码库、编写新功能、重构代码、修复 Bug 等,大幅提升开发效率。OpenCode 类似于 Claude 的 Code 模式或 Cursor 的 Agent 功能,但完全开源、隐私优先,支持多种大语言模型(LLM),并强调终端体验。

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

软件工程领域最热门的“OpenCode”。它是由 Jay V 和 Frank Wang(滑铁卢大学校友)创办的开源 AI 编程工具。

  • 正式发布(2025年6月19日): OpenCode 正式上线。它主打“零摩擦”体验(无需账号、无需信用卡)和“模型无关性”(支持所有主流 AI 模型)。

  • 现状(2026年): 截至 2026 年初,它已成为全球最受欢迎的开源编程 Agent 之一,因其不存储任何用户代码的隐私设计,被 Cloudflare 等大型企业广泛采用。

  • 启用了 LSP(Language Server Protocol),会自动为当前使用的大语言模型(LLM)加载合适的语言服务器。

  • Multi-session Start multiple agents in parallel on the same project

  • 可以把某一次使用 OpenCode(或类似工具)的会话生成一个链接,方便他人查看、参考或排查问题(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

  • Any editor Available as a terminal interface, desktop app, and IDE extension

Opencode可看作开源版本的Claude Code

2. 安装

有多种方式进行安装

2.1 终端安装

OpenCode可以和Claude 一样成为终端版安装使用,使用下面的命令进行不同操作系统的安装

curl -fsSL https://opencode.ai/install | bash

npm i -g opencode-ai

bun add -g opencode-ai

brew install anomalyco/tap/opencode

paru -S opencode

安装后之后,在目录之下,输入opencode即可启动OpenCode

opencode

opencode

2.2 桌面版安装

OpenCode 官网进行不同操作版本桌面版下载,测试版目前还没有稳定

opencode istall

opencode install

2.3 扩展安装

The OpenCode extension for VS Code, Cursor, and other IDEs。OpenCode 可以与 VS Code、Cursor 或任何支持终端的 IDE 集成。只需在终端中运行 opencode 即可开始使用。

opencode IDE

IDE install

在VSCode搜素opencode插件进行安装,安装好之后,输入shift+command+p,打开控制面板,然后输入opencode,打开opencode功能

2.4 云端安装

3.使用

OpenCode也是使用/命令,调用功能

3.1 模型更改

使用/model查看可使用的模型

  • Big Pickle
    • GLM-4.7
    • Grok Code Fast 1
    • MiniMax M2.1
  • Popular providers
    • OpenCode Zen
    • Claude
    • Github Copilot
    • OpenAI

3.2 Antigravity 插件

启用 Opencode 通过 OAuth 对 Antigravity(Google 的 IDE)进行身份验证,以便您可以使用 Google 凭据使用 Antigravity 速率限制和访问 gemini-3-pro 和 claude-opus-4-5-thinking 等模型。

opencode-antigravity-auth 是目前最热门的开源 AI 编程助手 OpenCode(由 SST 团队开发)的一个核心插件。可以通过 Google 账号登录 OpenCode,并调用 Google 内部或特定 IDE 环境(代号为 “Antigravity”)中的高性能 AI 模型。

该插件充当了一个“认证网桥”。它允许 OpenCode 绕过标准的 API 密钥限制,直接使用 Google Antigravity 环境提供的配额。通过它,你可以在 OpenCode 中使用以下顶级模型:

  • Gemini 3 Pro / Gemini 3 Pro High(具备极强推理能力的模型)。
  • Claude 4.5 / Claude 3.5 Sonnet (Thinking)(Google Antigravity 环境中有时会提供这些模型的访问权限)

安装

将此内容粘贴到任何 LLM 代理(Claude Code、OpenCode、Cursor 等)中:自动安装

Install the opencode-antigravity-auth plugin and add the Antigravity model definitions to ~/.config/opencode/opencode.json by following: https://raw.githubusercontent.com/NoeFabris/opencode-antigravity-auth/dev/README.md

等待自行安装成功,提示

> Thinking: The config file has been created with the plugin and model definitions. Now the user needs to run opencode auth login to authenticate with their Google account.

已安装 opencode-antigravity-auth 插件并添加了 Antigravity 模型配置到 ~/.config/opencode/opencode.json。
接下来需要运行 opencode auth login 进行 Google 账户认证

认证 退出当前opencode,然后在终端中输入opencode auth login

opencode auth

opencode auth

选择google,然后一直Enter,直到跳转到google浏览器,进行账户认证,直到出现


Add another account? (1 added) (y/n):
│
●  Multi-account setup complete (1 account(s)).
│
◇  Login successful
│
└  Done

表示设置成功

切换模型

opencode中输入/models,找到gemini-3-pro-thinking 或 claude-4.5-thinking,输入问题,响应成功即可

3.2 OpenRuter接入

OpenRouter 就是一个大模型 API 路由器,旨在将各种 AI 模型和服务集成到一个统一的接口中。它允许用户通过简单的配置就能调用不同大模型的能力。

  • 统一接口:提供标准化的 API,简化了模型的集成和部署过程。
  • 多模型支持:支持多种预训练模型,如 GPT-4、Claude、Gemini 等。
  • 无需 GPU 服务器:通过调用预训练模型的 API,用户无需自建 GPU 服务器。

进入openrouter官网 注册之后,创建API key,然后把key复制

Tip

一定要及时复制,关闭之后就无法复制

Connect

opencode中输入/connect,输入openrouter,然后把APIkey输入

opencode router

openrouter

4. 亮点功能