内容
# OpenCode 配置
个人 [OpenCode](https://opencode.ai) 配置,包括 MCP 服务器、代理预设和跨平台安装程序。
## 内容
| 文件 | 用途 |
|------|---------|
| `opencode.json` | 主要配置文件 — MCP 服务器、插件、代理开关、LSP |
| `oh-my-opencode-slim.json` | 代理模型预设(zen-free、openai、poe、opencode-go) |
| `install.sh` | macOS / Linux / Windows(WSL/Git Bash)安装程序 |
| `install.ps1` | 原生 Windows(PowerShell)安装程序 |
## MCP 服务器
默认启用:
- **gitnexus** — 代码知识图谱(本地,npx)
- **xcodebuild** — Apple 平台构建/测试/调试(本地,npx)
- **mobile** — 移动设备自动化(本地,npx)
- **firebase** — Firebase CLI 集成(本地,npx)
- **figma** — Figma 设计交接(远程)
- **sentry** — 错误跟踪(远程)
- **github** — GitHub Copilot MCP(远程,需要密钥)
禁用(按需启用):
- **linear** — Linear 项目管理
- **clickup** — ClickUp 项目管理
- **luciq** — Instabug 集成
- **ios-simulator** — iOS 模拟器控制(被 xcodebuild 取代)
## 代理预设(`oh-my-opencode-slim.json`)
默认预设为 **zen-free** — 所有免费模型,不需要 API 密钥。
| 预设 | 协调器 | 神谕 | 用例 |
|--------|-------------|--------|----------|
| `zen-free` | `opencode/big-pickle` | `opencode/nemotron-3-ultra-free` | 免费,零配置 |
| `openai` | `openai/gpt-5.5` | `openai/gpt-5.5` | OpenAI API 用户 |
| `poe` | `poe/anthropic/claude-opus-4.8` | `poe/anthropic/claude-opus-4.8` | Poe 订阅者 |
| `opencode-go` | `opencode-go/glm-5.1` | `opencode-go/deepseek-v4-pro` | OpenCode Go 用户 |
通过更改 `oh-my-opencode-slim.json` 中的 `"preset": "zen-free"` 来切换预设。
## 快速安装
### macOS / Linux
```bash
git clone https://github.com/HossamYoussof/opencode-config.git opencode-config && cd opencode-config
./install.sh
```
### Windows (PowerShell)
```powershell
git clone https://github.com/HossamYoussof/opencode-config.git opencode-config; cd opencode-config
.\install.ps1
```
脚本将:
1. 安装 OpenCode(如果尚未安装)(通过 curl、npm、brew、winget、scoop 或 choco)
2. 将配置文件复制到全局配置目录
3. 在覆盖之前备份任何现有配置
### 配置位置
| 操作系统 | 路径 |
|----|------|
| macOS / Linux | `~/.config/opencode/` |
| Windows | `%APPDATA%\opencode\` |
## 手动安装
直接复制配置文件:
```bash
# macOS / Linux
mkdir -p ~/.config/opencode
cp opencode.json oh-my-opencode-slim.json ~/.config/opencode/
# Windows (PowerShell)
New-Item -ItemType Directory -Force -Path "$env:APPDATA\opencode"
Copy-Item opencode.json, oh-my-opencode-slim.json "$env:APPDATA\opencode\"
```
## 自定义
### 添加 MCP 服务器
编辑 `opencode.json` → `mcp` 部分:
```json
"my-server": {
"type": "local",
"command": ["npx", "-y", "my-mcp-server"],
"enabled": true
}
```
### 切换模型预设
编辑 `oh-my-opencode-slim.json` → 更改 `preset` 字段:
```json
"preset": "openai"
```
### 添加新预设
在 `oh-my-opencode-slim.json` 中,在 `presets` 下添加一个条目,遵循现有的结构(协调器、神谕、图书管理员、探险家、设计师、修复代理配置)。
## 要求
- [OpenCode](https://opencode.ai) CLI 已安装
- [Node.js](https://nodejs.org/) + npm(用于基于 npx 的 MCP 服务器)
- 为非免费预设配置 OpenCode 中的 API 密钥
## 许可证
MIT