GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing www.runoob.com — OpenCode 配置文件 | 菜鸟教程
OpenCode 教程
OpenCode 教程
OpenCode 简介
OpenCode 安装
OpenCode API 设置
OpenCode DeepSeek
OpenCode 配置文件
OpenCode 第一次使用
OpenCode VSCode
OpenCode TUI
OpenCode CLI 使用
OpenCode Web 使用
OpenCode GitHub
OpenCode GitLab
OpenCode 工具
OpenCode 规则
OpenCode 代理
OpenCode 主题
OpenCode 快捷键
OpenCode 自定义命令
OpenCode 格式化工具
OpenCode 权限配置
OpenCode LSP 服务器配置
OpenCode MCP 服务器配置
OpenCode Skills
OpenCode skills 使用
OpenCode 自定义工具
OpenCode oh-my-openagent
OpenCode 生态系统
OpenCode 配置文件
OpenCode 配置文件OpenCode 使用 JSON 格式来配置。 我们可以先看在全局配置文件 ~/.config/opencode/opencode.json: touch ~/.config/opencode/opencode.json
包含模型提供商及配置信息: {
// JSON Schema(用于编辑器校验和自动补全)
"$schema": "https://opencode.ai/config.json",
"provider": {
// 自定义 Provider 名称(使用时:deepseek/xxx)
"deepseek": {
// 使用 OpenAI 兼容适配器(适用于 DeepSeek 这类兼容接口)
"npm": "@ai-sdk/openai-compatible",
"options": {
// API 基础地址(必须是 OpenAI 兼容格式)
"baseURL": "https://api.deepseek.com/v1",
// API Key
"apiKey": "sk-xxxx",
// 是否强制设置缓存 key(提升缓存命中率,降低成本)
"setCacheKey": true
},
"models": {
// 本地模型别名(CLI/TUI 中使用:deepseek/Deepseek-v4)
"Deepseek-v4": {
// 实际调用的模型名称(API 层)
"name": "deepseek-v4-pro"
}
}
}
}
}
一个最小可用配置示例{
"$schema": "https://opencode.ai/config.json",
"model": "anthropic/claude-sonnet-4-5",
"autoupdate": true,
"theme": "default"
}常用全局配置项:
Provider 示例: {
"provider": {
"anthropic": {
"options": {
"timeout": 600000,
"setCacheKey": true
}
}
}
}
理解配置的"合并机制"OpenCode 的配置不是覆盖,而是分层合并。 加载顺序(由低到高)
合并规则
示例全局配置: {
"autoupdate": true
}
项目配置: {
"model": "anthropic/claude-sonnet-4-5"
}
最终结果: {
"autoupdate": true,
"model": "anthropic/claude-sonnet-4-5"
}
项目配置在项目根目录创建: opencode.json 作用:
示例:项目级配置{
"$schema": "https://opencode.ai/config.json",
"model": "anthropic/claude-sonnet-4-5",
"tools": {
"write": true,
"bash": true
}
}
核心配置模块详解{
"model": "anthropic/claude-sonnet-4-5",
"small_model": "anthropic/claude-haiku-4-5"
}
模型与 Provider{
"model": "anthropic/claude-sonnet-4-5",
"small_model": "anthropic/claude-haiku-4-5"
}
工具控制{
"tools": {
"write": false,
"bash": false
}
}
这是安全控制的第一层。 权限控制{
"permission": {
"edit": "ask",
"bash": "ask"
}
}
Agent(核心能力){
"agent": {
"code-reviewer": {
"description": "代码审查",
"model": "anthropic/claude-sonnet-4-5",
"prompt": "You are a code reviewer",
"tools": {
"write": false
}
}
}
}
本质:给 AI 定义角色 + 能力范围 Command(自动化 Prompt){
"command": {
"test": {
"template": "Run tests and fix failures",
"description": "运行测试"
}
}
}
本质:Prompt 模板系统 TUI 配置{
"tui": {
"scroll_speed": 3,
"scroll_acceleration": {
"enabled": true
},
"diff_style": "auto"
}
}
Server 配置(API / Web){
"server": {
"port": 4096,
"hostname": "0.0.0.0",
"mdns": true
}
}
上下文压缩(Token 优化){
"compaction": {
"auto": true,
"prune": true,
"reserved": 10000
}
}
插件系统{
"plugin": [
"opencode-helicone-session",
"@my-org/custom-plugin"
]
}
MCP(扩展生态){
"mcp": {}
}
用于接入外部工具(如 Jira、数据库等) 指令系统(AI 规则){
"instructions": [
"CONTRIBUTING.md",
"docs/*.md"
]
}
Provider 控制{
"enabled_providers": ["anthropic"],
"disabled_providers": ["openai"]
}
优先级: disabled > enabled 变量系统环境变量:{
"model": "{env:OPENCODE_MODEL}"
}
文件引用{
"apiKey": "{file:~/.secrets/key}"
}
目录扩展机制OpenCode 不只是 JSON 配置,还支持目录扩展: .opencode/ ├── agents/ ├── commands/ ├── plugins/ ├── tools/ ├── themes/ 作用:
推荐入门配置{
"$schema": "https://opencode.ai/config.json",
"model": "anthropic/claude-sonnet-4-5",
"small_model": "anthropic/claude-haiku-4-5",
"autoupdate": "notify",
"tools": {
"write": true,
"bash": true
},
"permission": {
"bash": "ask"
},
"compaction": {
"auto": true,
"prune": true
}
}
总结(架构视角)可以把 OpenCode 配置理解为四层结构: 配置层(多级 merge)
↓
能力层(agent / tools / mcp)
↓
执行层(model / provider)
↓
交互层(tui / server / web)
本质上,它不是简单配置文件,而是一个: 可编程 AI Agent 操作系统的配置中心
AI 思考中...
点我分享笔记取消
分类导航
Advertisement
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |