💎 快速上手
OpenCode 使用教程
在 VS Code 中实现无限的 OPUS、GPT、Claude、Gemini Pro 等模型,畅快使用 AI 能力。
1
安装 Node.js
2
安装 OpenCode CLI
打开终端(macOS 使用 Terminal, Windows 使用 PowerShell 或 CMD),执行以下命令:
npm install -g opencode-ai --registry=https://registry.npmmirror.com
验证安装:
opencode --version
3
配置 opencode.json
检查用户目录下的配置文件 ~/.config/opencode/opencode.json (macOS/Linux) 或
%USERPROFILE%\.config\opencode\opencode.json (Windows)。
如果文件不存在,请创建该文件并添加以下内容:
{
"$schema": "https://opencode.ai/config.json",
"model": "aixia/claude-opus-4-6",
"provider": {
"aixia": {
"name": "aixia",
"npm": "@ai-sdk/anthropic",
"models": {
"claude-haiku-4-5-20251001": {
"name": "haiku-4-5",
"limit": {
"context": 200000,
"output": 8192
},
"modalities": {
"input": [
"text",
"image",
"pdf"
],
"output": [
"text"
]
}
},
"claude-sonnet-4-6": {
"name": "sonnet-4-6",
"limit": {
"context": 200000,
"output": 16384
},
"modalities": {
"input": [
"text",
"image",
"pdf"
],
"output": [
"text"
]
}
},
"claude-opus-4-6": {
"name": "opus-4-6",
"limit": {
"context": 204800,
"output": 65535
},
"modalities": {
"input": [
"text",
"image",
"pdf"
],
"output": [
"text"
]
}
},
"claude-opus-4-5-20251101": {
"name": "opus-4-5",
"limit": {
"context": 200000,
"output": 16384
},
"modalities": {
"input": [
"text",
"image",
"pdf"
],
"output": [
"text"
]
}
}
},
"options": {
"apiKey": "sk-获得的实际令牌",
"baseURL": "https://aiapi.aixia.tech/v1"
}
}
},
"plugin": [
"oh-my-opencode"
]
}
💡 配置说明:
- 请将 apiKey 中的值替换为从 https://aiapi.aixia.tech 获取的实际令牌
- 配置文件路径示例:
- • Windows:
C:\Users\你的用户名\.config\opencode\opencode.json - • macOS/Linux:
~/.config/opencode/opencode.json
💡 配置令牌
在 aiapi.aixia.tech 令牌管理配置令牌
4
安装 VSCode 扩展
在 VS Code 扩展市场中搜索并安装 OpenCode 扩展(opencode for VS Code)。
安装完成后,重启 VS Code 即可开始使用。
🎉 配置完成
现在您可以在 VS Code 中使用 OpenCode 的强大 AI 能力了!
5
🔄 切换模型
安装完成后,您可以打开 OpenCode 插件。
您可以进行对话。
您可以在 OpenCode 命令窗口中切换模型。输入 /models 命令选择模型。
6
开始使用
现在你已经完成了所有配置,可以开始在 VS Code 中使用强大的 OpenCode AI 能力了!
打开命令面板 (Ctrl+Shift+P / Cmd+Shift+P),输入 "OpenCode" 即可开始使用。
!
常见问题: PowerShell 执行策略错误 (Windows)
🐛 问题现象
在 PowerShell 中运行 npm install -g opencode-ai 时出现以下错误:
无法加载文件 C:\Program Files\nodejs\npm.ps1,因为在此系统上禁止运行脚本
有关详细信息,请参阅 https://go.microsoft.com/fwlink/?LinkID=135170
✅ 解决方案
以管理员身份运行 PowerShell,执行以下命令:
Set-ExecutionPolicy RemoteSigned
执行后重新运行安装命令即可。