配置完成后使用 /model 切换模型!
完整配置只需 5 步:
| 系统 | 配置文件路径 |
|---|---|
| Windows | C:\Users\<用户名>\.config\opencode\opencode.json |
| macOS | ~/.config/opencode/opencode.json |
| Linux | ~/.config/opencode/opencode.json |
如果配置文件不存在,需要手动创建。
快速打开方式:
%USERPROFILE%\.config\opencodeopen ~/.config/opencode 或 xdg-open ~/.config/opencode
在 opencode.json 中添加以下配置:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"huanyu": {
"npm": "@ai-sdk/anthropic",
"name": "huanyu",
"options": {
"baseURL": "https://api.huanyuf.top/v1",
"apiKey": "sk-xxx"
},
"models": {
"claude-opus-4-6": {
"name": "Claude Opus 4.6",
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"claude-opus-4-6-thinking": {
"name": "Claude Opus 4.6 Thinking",
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
},
"reasoning": true,
"variants": {
"low": {
"thinkingConfig": { "thinkingBudget": 8192 },
"thinking": { "type": "enabled", "budget_tokens": 8192, "budgetTokens": 8192 }
},
"medium": {
"thinkingConfig": { "thinkingBudget": 16384 },
"thinking": { "type": "enabled", "budget_tokens": 16384, "budgetTokens": 16384 }
},
"high": {
"thinkingConfig": { "thinkingBudget": 24576 },
"thinking": { "type": "enabled", "budget_tokens": 24576, "budgetTokens": 24576 }
},
"max": {
"thinkingConfig": { "thinkingBudget": 32768 },
"thinking": { "type": "enabled", "budget_tokens": 32768, "budgetTokens": 32768 }
}
}
},
"claude-sonnet-4-6": {
"name": "Claude Sonnet 4.6",
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"claude-sonnet-4-6-thinking": {
"name": "Claude Sonnet 4.6 Thinking",
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
},
"reasoning": true,
"variants": {
"low": {
"thinkingConfig": { "thinkingBudget": 8192 },
"thinking": { "type": "enabled", "budget_tokens": 8192, "budgetTokens": 8192 }
},
"medium": {
"thinkingConfig": { "thinkingBudget": 16384 },
"thinking": { "type": "enabled", "budget_tokens": 16384, "budgetTokens": 16384 }
},
"high": {
"thinkingConfig": { "thinkingBudget": 24576 },
"thinking": { "type": "enabled", "budget_tokens": 24576, "budgetTokens": 24576 }
},
"max": {
"thinkingConfig": { "thinkingBudget": 32768 },
"thinking": { "type": "enabled", "budget_tokens": 32768, "budgetTokens": 32768 }
}
}
},
"gemini-3.1-pro": {
"name": "Gemini 3.1 Pro",
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
},
"gemini-3-flash": {
"name": "Gemini 3 Flash",
"modalities": {
"input": ["text", "image", "pdf"],
"output": ["text"]
}
}
}
}
}
}
注意: apiKey 字段填入你在令牌页面生成的 API Key,替换 sk-xxx。
| 字段 | 说明 |
|---|---|
$schema | JSON Schema,提供自动补全 |
npm | SDK 包名 |
name | Provider 显示名称 |
options.baseURL | API 地址 |
options.apiKey | 你的 API 密钥(在令牌页面生成) |
models | 模型配置列表 |
reasoning | 是否为思考模型(thinking 模型设为 true) |
variants | 思考预算等级配置:low / medium / high / max |
thinkingBudget | 思考 token 预算(越大思考越深入) |
huanyu在页面底部的下拉菜单中选择你配置的模型。
Oh My OpenCode 是 OpenCode 的增强插件,提供智能体编排、后台任务、LSP 工具等强大功能。
在 OpenCode 中直接输入以下指令,让 AI 自动完成安装配置:
按照这里的说明进行安装和配置 https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/refs/heads/master/README.md
AI 会自动读取官方文档并完成所有配置步骤。
ulw(ultrawork 的缩写)即可启用全部增强功能ultrawork 或 ulw 自动启用最强模式| 命令/快捷键 | 功能 |
|---|---|
/model | 切换模型 |
/init | 初始化项目(生成 AGENTS.md) |
/undo | 撤销更改 |
/redo | 重做更改 |
/compact | 压缩上下文 |
Tab | 切换 Plan/Build 模式 |
Esc 两次 | 中断当前操作 |
Ctrl+C | 退出 OpenCode |
Q: 提示 401 错误?
A: API Key 无效或未设置。检查 opencode.json 中 options.apiKey 是否正确填写,或是否已在 Connect provider 中正确输入。
Q: 模型列表中看不到配置的模型?
A: opencode.json 格式错误。使用 在线 JSON 校验工具 检查语法。
Q: 如何更新 OpenCode?
A: 重新下载安装最新版即可覆盖更新。
Q: 代理/VPN 环境下无法连接?
A: 设置环境变量:
# Linux/macOS export HTTP_PROXY=http://127.0.0.1:7890 export HTTPS_PROXY=http://127.0.0.1:7890 # Windows PowerShell $env:HTTP_PROXY="http://127.0.0.1:7890" $env:HTTPS_PROXY="http://127.0.0.1:7890"