opencode 实战经验分享: opencode 的安装和配置,使用自己的 CPA 模型

2026-04-11 14:391阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐
问题描述:

1、安装 OpenCode

npm i -g opencode-ai

mac和Linux推荐使用brew,这样更稳定

brew install anomalyco/tap/opencode

2、打开 OpenCode

opencode

3、安装 oh-my-opencode 插件(使用opencode 这个插件必装)

把这个链接复制粘贴到 opencode 会话里,让它自己动(需要先登录 opencode 账号,免费注册,可以免费使用 GLM4.7):

Install and configure by following the instructions here https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/refs/heads/master/README.md

如果不放心,可以自己进入官网,跟着教程手动安装

github.com

GitHub - code-yeongyu/oh-my-opencode: The Best Agent Harness. Meet Sisyphus: The...

The Best Agent Harness. Meet Sisyphus: The Batteries-Included Agent that codes like you.

然后根据指引登录你的 google 账号和 gpt 或者 claude 账号(可选)

4、安装 opencode-dcp 插件

这个工具主要是可以通过从对话历史记录中删除过时的工具输出,自动减少 OpenCode 中的令牌使用量。(亲测好用)。安装很简单,下面介绍

5、编辑 OpenCode 配置文件

安装完成之后来到~/.config/opencode文件夹下面。
如果按照上面的步骤结构应该是这样
image500×490 23.1 KB
进入opencode.json文件,添加模型和 MCP 配置。
我这里以配置 CPA 为例可以删除你不要的模型.因为 opencode 可以免费使用国产模型,所以我只配了国外的模型。有需要的可以自己更改,并且我没有 claude 的 pro 会员,所以我直接把 CPA 接出来的 cladue模型放到anthropic组里面。个人觉得更方便,上面的插件使用这个配置文件就自动安装了

{ "$schema": "https://opencode.ai/config.json", "model": "anthropic/kiro-claude-opus-4-5-agentic(high)", "plugin": [ "oh-my-opencode", "opencode-antigravity-auth@1.2.8", "opencode-openai-codex-auth@4.3.0", "@tarquinen/opencode-dcp@latest" ], "provider": { "anthropic": { "options": { "baseURL": "http://127.0.0.1:8317/v1" }, "models": { "gemini-claude-opus-4-5-thinking(high)": { "name": "gemini-claude-opus-4-5-thinking(high)", "limit": { "context": 204800, "output": 65535 }, "modalities": { "input": [ "text", "image", "pdf" ], "output": [ "text" ] }, "options": { "thinking": { "type": "enabled", "budgetTokens": 24576 } } }, "gemini-claude-sonnet-4-5-thinking(high)": { "name": "gemini-claude-sonnet-4-5-thinking(high)", "limit": { "context": 204800, "output": 65535 }, "modalities": { "input": [ "text", "image", "pdf" ], "output": [ "text" ] }, "options": { "thinking": { "type": "enabled", "budgetTokens": 24576 } } }, "kiro-claude-sonnet-4-5-agentic(high)": { "name": "kiro-claude-sonnet-4-5-agentic(high)", "limit": { "context": 204800, "output": 65535 }, "modalities": { "input": [ "text", "image", "pdf" ], "output": [ "text" ] }, "options": { "thinking": { "type": "enabled", "budgetTokens": 24576 } } }, "kiro-claude-opus-4-5-agentic(high)": { "name": "kiro-claude-opus-4-5-agentic(high)", "limit": { "context": 204800, "output": 65535 }, "modalities": { "input": [ "text", "image", "pdf" ], "output": [ "text" ] }, "options": { "thinking": { "type": "enabled", "budgetTokens": 24576 } } } } }, "cpa-gemini": { "name": "cpa-gemini", "options": { "baseURL": "http://127.0.0.1:8317/v1" }, "models": { "gemini-3-pro-preview": { "name": "gemini-3-pro-preview", "limit": { "context": 1048576, "output": 65535 }, "modalities": { "input": [ "text", "image", "pdf" ], "output": [ "text" ] }, "options": { "thinking": { "type": "enabled", "budgetTokens": 24576 } } }, "gemini-3-flash-preview": { "name": "gemini-3-flash-preview", "limit": { "context": 1048576, "output": 65536 }, "modalities": { "input": [ "text", "image", "pdf" ], "output": [ "text" ] }, "options": { "thinking": { "type": "enabled", "budgetTokens": 24576 } } } } }, "google": { "name": "Google", "models": { "antigravity-gemini-3-pro-high": { "name": "Gemini 3 Pro High (Antigravity)", "thinking": true, "attachment": true, "limit": { "context": 1048576, "output": 65535 }, "modalities": { "input": [ "text", "image", "pdf" ], "output": [ "text" ] } }, "antigravity-gemini-3-pro-low": { "name": "Gemini 3 Pro Low (Antigravity)", "thinking": true, "attachment": true, "limit": { "context": 1048576, "output": 65535 }, "modalities": { "input": [ "text", "image", "pdf" ], "output": [ "text" ] } }, "antigravity-gemini-3-flash": { "name": "Gemini 3 Flash (Antigravity)", "attachment": true, "limit": { "context": 1048576, "output": 65536 }, "modalities": { "input": [ "text", "image", "pdf" ], "output": [ "text" ] } } } }, "openai": { "name": "OpenAI", "options": { "reasoningEffort": "medium", "reasoningSummary": "auto", "textVerbosity": "medium", "include": [ "reasoning.encrypted_content" ], "store": false }, "models": { "gpt-5.2": { "name": "GPT 5.2 (OAuth)", "limit": { "context": 272000, "output": 128000 }, "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "variants": { "none": { "reasoningEffort": "none", "reasoningSummary": "auto", "textVerbosity": "medium" }, "low": { "reasoningEffort": "low", "reasoningSummary": "auto", "textVerbosity": "medium" }, "medium": { "reasoningEffort": "medium", "reasoningSummary": "auto", "textVerbosity": "medium" }, "high": { "reasoningEffort": "high", "reasoningSummary": "detailed", "textVerbosity": "medium" }, "xhigh": { "reasoningEffort": "xhigh", "reasoningSummary": "detailed", "textVerbosity": "medium" } } }, "gpt-5.2-codex": { "name": "GPT 5.2 Codex (OAuth)", "limit": { "context": 272000, "output": 128000 }, "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "variants": { "low": { "reasoningEffort": "low", "reasoningSummary": "auto", "textVerbosity": "medium" }, "medium": { "reasoningEffort": "medium", "reasoningSummary": "auto", "textVerbosity": "medium" }, "high": { "reasoningEffort": "high", "reasoningSummary": "detailed", "textVerbosity": "medium" }, "xhigh": { "reasoningEffort": "xhigh", "reasoningSummary": "detailed", "textVerbosity": "medium" } } }, "gpt-5.1-codex-max": { "name": "GPT 5.1 Codex Max (OAuth)", "limit": { "context": 272000, "output": 128000 }, "modalities": { "input": [ "text", "image" ], "output": [ "text" ] }, "variants": { "low": { "reasoningEffort": "low", "reasoningSummary": "detailed", "textVerbosity": "medium" }, "medium": { "reasoningEffort": "medium", "reasoningSummary": "detailed", "textVerbosity": "medium" }, "high": { "reasoningEffort": "high", "reasoningSummary": "detailed", "textVerbosity": "medium" }, "xhigh": { "reasoningEffort": "xhigh", "reasoningSummary": "detailed", "textVerbosity": "medium" } } } } } } }

5. 绑定 API 密钥

在 OpenCode 终端执行以下操作,添加注册凭据:

  1. 终端执行命令:opencode auth login 注意不是在 opencode 里执行
  2. 选择 Anthropic,因为我登录我们之前登录了Antigravitygpt的账号在安装 oh-my-opencode**插件的时候,所以这个时候只需要添加一个 apikey 就行
  3. 选择Manually enter API Key,然后输入你的 CPA 的key
  4. 重载:保存文件,OpenCode 自动生效。
  5. 选择:输入 /models 弹出列表。
  6. 识别:找到对应你想用的模型,回车确认。
  7. 这样就大功告成了
    image2150×1666 94.2 KB
    image2120×1610 351 KB

6. 注意

如果你没有正确看到 thinking,可以按 ctrl+p,直接搜索 think,在这里打开显示,同理也在这里关闭。
image840×222 6.5 KB
当然这个只是我个人觉得好用的配置,如果不喜欢还是按照你自己的配置来。如果有佬有更方便的,欢迎大家交流!!

网友解答:
--【壹】--:

为什么你还是claude黄色,新版的闹翻了 把颜色全变蓝色了 哈哈


--【贰】--:

是的,登录账号,可以免费使用 glm4.7


--【叁】--:

共同进步


--【肆】--:

感谢教程


--【伍】--:

neovim 用户推荐sudo-tee/opencode.nvim 很好用


--【陆】--:

感谢大佬教程


--【柒】--: 沈宁:

3、安装 oh-my-opencode 插件(使用opencode 这个插件必装)

把这个链接复制粘贴到 opencode 会话里,让它自己动:

这一步之前要加上切换为免费模型吧,默认openai的用不了


--【捌】--:

感谢分享


--【玖】--:

可以的,支持


--【拾】--:

我用的是 kiro 接出来的 claudeopus4.5,工具调用很积极


--【拾壹】--:

感谢分享呢


--【拾贰】--:

安装插件之后 cc 有的功能他都有,我觉得很好用


--【拾叁】--:

兄弟的newAPI策略:{
“$schema”: “https://opencode.ai/config.json”,
“provider”: {
“mynewapi”: {
“name”: “NewAPI-Compatible”,
“npm”: “@ai-sdk/openai-compatible”,
“env”: [“NEWAPI_API_KEY”],
“options”: {
“baseURL”: “http://localhost:3000/v1”
},
“models”: {
“glm-4.7”: {
“id”: “glm-4.7”,
“name”: “GLM-4.7”,
“tool_call”: true,
“attachment”: true,
“temperature”: true,
“reasoning”: true,
“modalities”: { “input”: [“text”], “output”: [“text”] },
“limit”: {
“context”: 200000,
“output”: 128000
}
},
“miniMax-m2.1”: {
“id”: “MiniMax-M2.1”,
“name”: “miniMax-m2.1”,
“tool_call”: true,
“attachment”: true,
“temperature”: true,
“reasoning”: true,
“modalities”: { “input”: [“text”], “output”: [“text”] },
“limit”: {
“context”: 200000,
“output”: 128000
}
},
“deepseek-reasoner”: {
“id”: “deepseek-reasoner”,
“name”: “DeepSeek Reasoner”,
“tool_call”: true,
“attachment”: true,
“temperature”: true,
“reasoning”: true,
“modalities”: { “input”: [“text”], “output”: [“text”] },
“limit”: {
“context”: 128000,
“output”: 128000
}
}
}
},
“mynewapi-claude”: {
“name”: “NewAPI-Claude”,
“npm”: “@ai-sdk/anthropic”,
“env”: [“NEWAPI_API_KEY”],
“options”: {
“baseURL”: “http://localhost:3000/v1”
},
“models”: {
“claude-opus-4-5-20251101”: {
“id”: “claude-opus-4-5-20251101”,
“name”: “Claude Opus 4.5”,
“tool_call”: true,
“attachment”: true,
“temperature”: true,
“reasoning”: true,
“modalities”: { “input”: [“text”, “image”, “pdf”], “output”: [“text”] },
“limit”: { “context”: 200000, “output”: 128000 },
“options”: {
“thinking”: { “type”: “enabled”, “budgetTokens”: 32000 }
}
},
“claude-sonnet-4-5-20250929”: {
“id”: “claude-sonnet-4-5-20250929”,
“name”: “Claude Sonnet 4.5”,
“tool_call”: true,
“attachment”: true,
“temperature”: true,
“reasoning”: true,
“modalities”: { “input”: [“text”, “image”, “pdf”], “output”: [“text”] },
“limit”: { “context”: 200000, “output”: 128000 },
“options”: {
“thinking”: { “type”: “enabled”, “budgetTokens”: 16000 }
}
}
}
},
“mynewapi-gemini”: {
“name”: “NewAPI-Gemini”,
“npm”: “@ai-sdk/google”,
“env”: [“NEWAPI_API_KEY”],
“options”: {
“baseURL”: “http://localhost:3000/v1beta”
},
“models”: {
“gemini-3-pro-preview”: {
“id”: “gemini-3-pro-preview”,
“name”: “Gemini 3 Pro”,
“tool_call”: true,
“attachment”: true,
“temperature”: true,
“reasoning”: true,
“modalities”: { “input”: [“text”, “image”, “pdf”], “output”: [“text”] },
“limit”: { “context”: 1000000, “output”: 128000 }
},
“gemini-3-flash-preview”: {
“id”: “gemini-3-flash-preview”,
“name”: “Gemini 3 Flash”,
“tool_call”: true,
“attachment”: true,
“temperature”: true,
“reasoning”: true,
“modalities”: { “input”: [“text”, “image”, “pdf”], “output”: [“text”] },
“limit”: { “context”: 1000000, “output”: 128000 }
}
}
},
“mynewapi-codex”: {
“name”: “NewAPI-Codex”,
“npm”: “@ai-sdk/openai”,
“env”: [“NEWAPI_API_KEY”],
“options”: {
“baseURL”: “http://localhost:3000/v1”
},
“models”: {
“gpt-5.2”: {
“id”: “gpt-5.2”,
“name”: “GPT-5.2”,
“tool_call”: true,
“attachment”: true,
“temperature”: false,
“reasoning”: true,
“release_date”: “2025-12-11”,
“modalities”: { “input”: [“text”, “image”, “pdf”], “output”: [“text”] },
“cost”: { “input”: 1.75, “output”: 14, “cache_read”: 0.175 },
“limit”: {
“context”: 400000,
“output”: 128000
},
“options”: {
“store”: false,
“reasoningEffort”: “xhigh”,
“textVerbosity”: “medium”,
“reasoningSummary”: “auto”,
“include”: [“reasoning.encrypted_content”]
}
},
“gpt-5.2-codex-max”: {
“id”: “gpt-5.2-codex-max”,
“name”: “GPT-5.2 Codex Max”,
“tool_call”: true,
“attachment”: true,
“temperature”: false,
“reasoning”: true,
“release_date”: “2025-12-11”,
“modalities”: { “input”: [“text”, “image”, “pdf”], “output”: [“text”] },
“cost”: { “input”: 1.75, “output”: 14, “cache_read”: 0.175 },
“limit”: {
“context”: 400000,
“output”: 128000
},
“options”: {
“store”: false,
“reasoningEffort”: “xhigh”,
“textVerbosity”: “medium”,
“reasoningSummary”: “auto”,
“include”: [“reasoning.encrypted_content”]
}
}
}
}
},
“plugin”: [
“oh-my-opencode”
]
}


--【拾肆】--:

功能上和 CC 没法比. 唯一优势是三方+开源


--【拾伍】--:

这个是真有用。


--【拾陆】--:

实际体验咋样啊,跟cc比有什么优势


--【拾柒】--:

感谢大佬教程


--【拾捌】--:

赞美分享


--【拾玖】--:

这些 high,low,要设置吗,会自动判断使用吗,就是 cpa 里的模型,还有我怎么感觉反重力 cpa 出来的 claude 不太爱用子编排,我看也有 issues 有一样的情况,是设置的原因吗