opencode 配置 ai-router 使用 claude code
最近 opencode + ohmyopencode 的组合使用方式比较火,在网络上未找到如何将 opencode 和 AI 中转站平台 进行结合的使用方式,我使用的是自己的平台。
这里对实践过程做一个记录。
首先,我们需要在电脑安装 opencode, 安装方式比较多,可以直接查看官网安装步骤: https://opencode.ai/docs/#install
接下来,在 opencode 的配置文件 ~/.config/opencode/opencode.json 中保存我们的自定义 provider: ai_router , 见下方我提供的参考:
{
"$schema": "https://opencode.ai/config.json",
"tui": {
"scroll_speed": 0.5,
"scroll_acceleration": {
"enabled": false
},
"diff_style": "auto"
},
"provider": {
"ai_router": {
"npm": "@ai-sdk/openai-compatible",
"name": "ai-router",
"options": {
"baseURL": "https://ai-router.plugins-world.cn/v1",
"apiKey": "sk-xxxxx"
},
"models": {
"claude-sonnet-4-5-20250929": {},
"claude-haiku-4-5": {}
}
}
},
"enabled_providers": ["ai_router"],
"model": "ai_router/claude-sonnet-4-5-20250929",
"small_model": "ai_router/claude-haiku-4-5",
"plugin": [
"oh-my-opencode"
],
"server": {
"port": 4096,
"hostname": "0.0.0.0",
"mdns": true,
"cors": ["http://localhost:5173"]
}
}
这里注意一下,我增加了一些额外配置,例如滚动速度设置,例如 web 访问端口等等。具体配置参考的: https://linux.do/t/topic/1415352
如果希望开启多个
opencode,请在配置文件中移除server部分的配置信息
当上方配置完成后,重新启动终端,即可参考 oh my opencode 文档,让 llm 帮我们完成插件的安装:
Install and configure by following the instructions here https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/refs/heads/master/README.md
安装完成后,重启终端驶入 opencode 即可开始使用。
参考
https://discuss.plugins-world.cn/post/dnGC7sAb
实践记录