彻底定制你的 AI 编程助手:OpenCode 四大核心配置
字数 1555,阅读大约需 8 分钟

OpenCode 的四大核心配置:模型、主题、快捷键、命令。把这四个玩转,你的 AI 编程助手就是独一无二的。
一、模型配置
OpenCode 用的是 AI SDK 和 Models.dev,支持 75+ LLM 提供商,本地模型也 ok。
1.1 选模型
先配置好提供商,然后运行:
/models
1.2 推荐模型
市面上的模型太多了,但真正能打的就那么几个。以下是跟 OpenCode 配合比较好的:
-
• GPT 5.2 -
• GPT 5.1 Codex -
• Claude Opus 4.5 -
• Claude Sonnet 4.5 -
• Minimax M2.1 -
• Gemini 3 Pro
1.3 设默认模型
在配置文件里加上 model 字段:
{
"$schema": "https://opencode.ai/config.json",
"model": "lmstudio/google/gemma-3n-e4b"
}
格式是 provider_id/model_id。
1.4 配置模型选项
全局配置模型的参数:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"openai": {
"models": {
"gpt-5": {
"options": {
"reasoningEffort": "high",
"textVerbosity": "low",
"reasoningSummary": "auto",
"include": ["reasoning.encrypted_content"]
}
}
}
},
"anthropic": {
"models": {
"claude-sonnet-4-5-20250929": {
"options": {
"thinking": {
"type": "enabled",
"budgetTokens": 16000
}
}
}
}
}
}
}
1.5 变体配置
1.5.1 内置变体
Anthropic:
-
• high– 高思考预算(默认) -
• max– 最大思考预算
OpenAI:
-
• none– 无推理 -
• minimal– 极少推理 -
• low– 低推理 -
• medium– 中等推理 -
• high– 高推理 -
• xhigh– 超高推理
Google:
-
• low– 较低推理 -
• high– 较高推理
1.5.2 自定义变体
自己改变体配置:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"openai": {
"models": {
"gpt-5": {
"variants": {
"thinking": {
"reasoningEffort": "high",
"textVerbosity": "low"
},
"fast": {
"disabled":true
}
}
}
}
}
}
}
用 variant_cycle 快捷键快速切变体。
1.6 模型加载优先级
启动时按这个顺序找模型:
-
1. --model或-m命令行参数 -
2. 配置文件的 model 字段 -
3. 上次用的模型 -
4. 内部优先级最高的那个
二、主题配置
内置主题够用了,也能自己写。
2.1 终端要求
想看到完整的颜色,终端必须支持真彩色(24 位色)。
-
• 查一下: echo $COLORTERM(显示truecolor或24bit就 ok) -
• 没显示的话:设环境变量 COLORTERM=truecolor
2.2 内置主题
|
|
|
|---|---|
system |
|
tokyonight |
|
everforest |
|
ayu |
|
catppuccin |
|
catppuccin-macchiato |
|
gruvbox |
|
kanagawa |
|
nord |
|
matrix |
|
one-dark |
|
默认是 opencode 主题。
2.3 系统主题
system 这货比较聪明,会自动适配终端配色:
-
• 自动生成灰度色阶 -
• 用 ANSI 标准色(0-15) -
• 颜色设成 none就能继承终端默认
2.4 用主题
运行 /theme 或者改 tui.json:
{
"$schema": "https://opencode.ai/tui.json",
"theme": "tokyonight"
}
2.5 自定义主题
2.5.1 加载优先级
从这些地方加载,后面盖前面:
-
1. 内置主题 -
2. 用户配置: ~/.config/opencode/themes/*.json -
3. 项目根目录: <project-root>/.opencode/themes/*.json -
4. 当前目录: ./.opencode/themes/*.json
2.5.2 创建主题
用户级:
mkdir -p ~/.config/opencode/themes
vim ~/.config/opencode/themes/my-theme.json
项目级:
mkdir -p .opencode/themes
vim .opencode/themes/my-theme.json
2.5.3 JSON 格式
支持:
-
• 十六进制: "#ffffff" -
• ANSI 色号: 3(0-255) -
• 颜色引用: "primary" -
• 深浅分离: {"dark": "#000", "light": "#fff"} -
• 继承终端: "none"
2.5.4 终端默认值
用 "none" 继承终端颜色:
-
• "text": "none"— 终端默认前景 -
• "background": "none"— 终端默认背景
三、快捷键配置
快捷键在 tui.json 里改。
3.1 前导键
默认 ctrl+x 是前导键。比如新建会话:先按 ctrl+x,再按 n。
3.2 常用快捷键
会话操作
|
|
|
|---|---|
<leader>e |
|
<leader>t |
|
<leader>b |
|
<leader>s |
|
<leader>x |
|
<leader>n |
|
<leader>l |
|
<leader>g |
|
escape |
|
<leader>c |
|
消息导航
|
|
|
|---|---|
pageup
pagedown |
|
ctrl+alt+y
ctrl+alt+e |
|
ctrl+alt+u
ctrl+alt+d |
|
ctrl+g
home |
|
ctrl+alt+g
end |
|
<leader>y |
|
<leader>u
<leader>r |
|
模型操作
|
|
|
|---|---|
<leader>m |
|
f2 |
|
shift+f2 |
|
ctrl+t |
|
命令与代理
|
|
|
|---|---|
ctrl+p |
|
<leader>a |
|
tab
shift+tab |
|
输入编辑
|
|
|
|---|---|
ctrl+a |
|
ctrl+e |
|
alt+b
alt+f |
|
ctrl+d |
|
ctrl+k |
|
ctrl+u |
|
ctrl+w |
|
alt+d |
|
ctrl+t |
|
ctrl+g |
|
3.3 禁用快捷键
设成 "none" 就关了:
{
"$schema": "https://opencode.ai/tui.json",
"keybinds": {
"session_compact": "none"
}
}
3.4 Shift+Enter
有些终端得配一下。Windows Terminal 的 settings.json 加这些:
{
"actions": [
{
"command": {
"action": "sendInput",
"input": "\u001b[13;2u"
},
"id": "User.sendInput.ShiftEnterCustom"
}
],
"keybindings": [
{
"keys": "shift+enter",
"id": "User.sendInput.ShiftEnterCustom"
}
]
}
四、自定义命令
写好的命令可以复用,配合内置命令 /init、/undo、/redo 这些一起用。
4.1 创建命令文件
在 commands/ 目录放 markdown 文件:
.opencode/commands/test.md
---
description: Run tests with coverage
agent: build
model: anthropic/claude-3-5-sonnet-20241022
---
Run the full test suite with coverage report and show any failures.
Focus on the failing tests and suggest fixes.
用 /test 调用。
4.2 配置方式
JSON
{
"$schema": "https://opencode.ai/config.json",
"command": {
"test": {
"template": "Run the full test suite with coverage report...",
"description": "Run tests with coverage",
"agent": "build",
"model": "anthropic/claude-3-5-sonnet-20241022"
}
}
}
Markdown 位置
-
• 全局: ~/.config/opencode/commands/ -
• 项目级: .opencode/commands/
4.3 提示词配置
参数
用 $ARGUMENTS 接收参数:
---
description: Create a new component
---
Create a new React component named $ARGUMENTS with TypeScript support.
调用:/component Button
位置参数 $1、$2、$3:
---
description: Create a new file with content
---
Create a file named $1 in the directory $2 with the following content: $3
调用:/create-file config.json src "{ \"key\": \"value\" }"
Shell 输出
!`command` 注入命令结果:
---
description: Analyze test coverage
---
Here are the current test results:
!`npm test`
Based on these results, suggest improvements to increase coverage.
文件引用
@文件名 引用文件:
---
description: Review component
---
Review the component in @src/components/Button.tsx.
Check for performance issues and suggest improvements.
4.4 配置选项
|
|
|
|
|---|---|---|
template |
|
|
description |
|
|
agent |
|
|
subtask |
|
|
model |
|
|
4.5 覆盖内置命令
可以覆盖内置命令。定义 /help 就会用你自己的。
总结
四个配置:
-
1. 模型:75+ 提供商、推荐型号、变体、加载顺序 -
2. 主题:11 种内置、自己写、加载优先级 -
3. 快捷键:80+ 个、前导键、能关能改 -
4. 命令:参数、Shell 输出、文件引用
把这四个摸透,OpenCode 就是你想要的样子了。
夜雨聆风