opencode-expert
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseOpenCode Expert
OpenCode 专家指南
Comprehensive guide for OpenCode - the open-source AI coding agent.
这是开源AI编码Agent OpenCode的全面使用指南。
Quick Reference
快速参考
| Task | Command/Action |
|---|---|
| Start TUI | |
| Continue session | |
| Run non-interactive | |
| Start headless server | |
| Web interface | |
| Switch agent | |
| File search | |
| Undo changes | |
| Redo changes | |
| Share conversation | |
| Initialize project | |
| Configure API keys | |
| 任务 | 命令/操作 |
|---|---|
| 启动TUI | |
| 继续会话 | |
| 运行非交互模式 | |
| 启动无头服务器 | |
| 网页界面 | |
| 切换Agent | |
| 文件搜索 | 输入 |
| 撤销更改 | |
| 重做更改 | |
| 分享对话 | |
| 初始化项目 | |
| 配置API密钥 | |
Agents
Agent
OpenCode has two primary agents, switchable with :
TabOpenCode有两个主要Agent,可通过键切换:
TabBuild Agent (Default)
构建Agent(默认)
- Full access to all tools
- Can edit files, run commands, make changes
- Use for active development work
- 拥有所有工具的完整访问权限
- 可编辑文件、运行命令、进行修改
- 适用于活跃的开发工作
Plan Agent
规划Agent
- Read-only mode for analysis and exploration
- File edits and bash commands require approval (mode)
ask - Use for reviewing implementation strategy before changes
- 用于分析和探索的只读模式
- 文件编辑和bash命令需要批准(模式)
ask - 适用于在进行更改前审查实现策略
Subagents
子Agent
Invoke subagents with mention:
@- @general - Complex research and multi-step tasks with full tool access
- @explore - Fast read-only codebase searches and code questions
通过提及调用子Agent:
@- @general - 拥有完整工具访问权限,用于复杂研究和多步骤任务
- @explore - 快速只读代码库搜索和代码相关问题解答
Keyboard Shortcuts
键盘快捷键
| Key | Action |
|---|---|
| Switch between Build and Plan agents |
| Fuzzy file search |
| Cancel current operation |
| 按键 | 操作 |
|---|---|
| 在构建Agent和规划Agent之间切换 |
| 模糊文件搜索 |
| 取消当前操作 |
Slash Commands
斜杠命令
| Command | Description |
|---|---|
| Configure LLM provider API keys |
| Initialize project and create |
| Revert recent changes (stackable) |
| Restore undone changes |
| Create shareable conversation link |
| 命令 | 描述 |
|---|---|
| 配置LLM提供商的API密钥 |
| 初始化项目并创建 |
| 撤销最近的更改(可堆叠) |
| 恢复已撤销的更改 |
| 创建可分享的对话链接 |
CLI Commands
CLI命令
Interactive Mode
交互模式
bash
undefinedbash
undefinedStart TUI in current directory
在当前目录启动TUI
opencode
opencode
Start in specific project
在指定项目中启动
opencode /path/to/project
opencode /path/to/project
Continue previous session
继续之前的会话
opencode --continue
opencode -c
opencode --continue
opencode -c
Use specific session
使用特定会话
opencode --session <id>
opencode -s <id>
opencode --session <id>
opencode -s <id>
Start with specific model
使用特定模型启动
opencode --model <model>
opencode -m <model>
opencode --model <model>
opencode -m <model>
Start with specific agent
使用特定Agent启动
opencode --agent build
opencode --agent plan
undefinedopencode --agent build
opencode --agent plan
undefinedNon-Interactive Mode
非交互模式
bash
undefinedbash
undefinedRun single prompt
运行单个提示
opencode run "Fix the bug in auth.py"
opencode run "Fix the bug in auth.py"
Run with file attachment
带文件附件运行
opencode run "Review this" --file README.md
opencode run "Review this" -f README.md
opencode run "Review this" --file README.md
opencode run "Review this" -f README.md
Run and share result
运行并分享结果
opencode run "Explain this code" --share
opencode run "Explain this code" --share
Run specific command
运行特定命令
opencode run --command "npm test"
undefinedopencode run --command "npm test"
undefinedServer Mode
服务器模式
bash
undefinedbash
undefinedStart headless API server
启动无头API服务器
opencode serve
opencode serve
With custom port
使用自定义端口
opencode serve --port 3000
opencode serve --port 3000
With mDNS discovery
启用mDNS发现
opencode serve --mdns
opencode serve --mdns
Web interface
网页界面
opencode web
undefinedopencode web
undefinedManagement Commands
管理命令
bash
undefinedbash
undefinedAuthentication
认证
opencode auth login
opencode auth list
opencode auth logout
opencode auth login
opencode auth list
opencode auth logout
Models
模型
opencode models # List available models
opencode models --refresh # Refresh model cache
opencode models # 列出可用模型
opencode models --refresh # 刷新模型缓存
Agents
Agent
opencode agent create # Create custom agent
opencode agent list # List agents
opencode agent create # 创建自定义Agent
opencode agent list # 列出Agent
MCP servers
MCP服务器
opencode mcp add <server>
opencode mcp list
opencode mcp auth
opencode mcp debug
opencode mcp add <server>
opencode mcp list
opencode mcp auth
opencode mcp debug
Sessions
会话
opencode session list
opencode session list -n 10 # Last 10 sessions
opencode session list
opencode session list -n 10 # 最近10个会话
Statistics
统计信息
opencode stats
opencode stats --days 7
opencode stats --tools
opencode stats --models
opencode stats
opencode stats --days 7
opencode stats --tools
opencode stats --models
Export/Import
导出/导入
opencode export <sessionID>
opencode import <file>
opencode export <sessionID>
opencode import <file>
Upgrade
升级
opencode upgrade
opencode upgrade <version>
undefinedopencode upgrade
opencode upgrade <version>
undefinedBuilt-in Tools
内置工具
OpenCode provides these tools to agents:
| Tool | Description |
|---|---|
| read | Read file contents with optional line ranges |
| write | Create new files or overwrite existing |
| edit | Modify files using exact string replacements |
| patch | Apply patch files |
| grep | Search file contents with regex |
| glob | Find files by pattern ( |
| list | List files and directories |
| bash | Execute shell commands |
| lsp | Language Server Protocol integration (experimental) |
| todowrite | Create/update task lists |
| todoread | Read current todo state |
| skill | Load skill files into conversation |
| webfetch | Fetch and read web pages |
| question | Ask user clarifying questions |
OpenCode为Agent提供以下工具:
| 工具 | 描述 |
|---|---|
| read | 读取文件内容,可指定行范围 |
| write | 创建新文件或覆盖现有文件 |
| edit | 使用精确字符串替换修改文件 |
| patch | 应用补丁文件 |
| grep | 使用正则表达式搜索文件内容 |
| glob | 按模式查找文件( |
| list | 列出文件和目录 |
| bash | 执行shell命令 |
| lsp | 语言服务器协议集成(实验性) |
| todowrite | 创建/更新任务列表 |
| todoread | 读取当前待办事项状态 |
| skill | 将Skill文件加载到对话中 |
| webfetch | 获取并读取网页内容 |
| question | 向用户询问澄清问题 |
Skills
Skill
File Locations
文件位置
Skills are discovered from (in order):
- (project)
.opencode/skills/<name>/SKILL.md - (global)
~/.config/opencode/skills/<name>/SKILL.md - (Claude-compatible project)
.claude/skills/<name>/SKILL.md - (Claude-compatible global)
~/.claude/skills/<name>/SKILL.md
Skill的发现顺序如下:
- (项目级)
.opencode/skills/<name>/SKILL.md - (全局级)
~/.config/opencode/skills/<name>/SKILL.md - (兼容Claude的项目级)
.claude/skills/<name>/SKILL.md - (兼容Claude的全局级)
~/.claude/skills/<name>/SKILL.md
Skill Format
Skill格式
markdown
---
name: my-skill
description: Description of what this skill does and when to use it.
---markdown
---
name: my-skill
description: Description of what this skill does and when to use it.
---Skill Content
Skill Content
Instructions and documentation here...
undefinedInstructions and documentation here...
undefinedName Rules
命名规则
- Lowercase alphanumeric with single hyphens
- Cannot start/end with hyphens
- No consecutive hyphens ()
-- - Must match directory name
- 小写字母数字,使用单个连字符分隔
- 不能以连字符开头或结尾
- 不能有连续连字符()
-- - 必须与目录名称匹配
Configuration
配置
Config Locations
配置文件位置
- Project: or
.opencode/opencode.json - Global:
~/.config/opencode/
- 项目级:或
.opencode/opencode.json - 全局级:
~/.config/opencode/
Environment Variables
环境变量
| Variable | Description |
|---|---|
| Custom config path |
| Permission mode |
| Server auth password |
| Disable auto-updates |
| Enable experimental features |
| Enable Exa search |
| 变量 | 描述 |
|---|---|
| 自定义配置路径 |
| 权限模式 |
| 服务器认证密码 |
| 禁用自动更新 |
| 启用实验性功能 |
| 启用Exa搜索 |
Custom Agents
自定义Agent
Create agents via or define in:
opencode agent createopencode.json~/.config/opencode/agents/.opencode/agents/
Agent config options: description, temperature, model, tool permissions, system prompts.
可通过创建Agent,或在以下位置定义:
opencode agent createopencode.json~/.config/opencode/agents/.opencode/agents/
Agent配置选项包括:描述、温度参数、模型、工具权限、系统提示。
Best Practices
最佳实践
Use Plan Mode First
先使用规划模式
Switch to Plan agent () to review implementation strategy before making changes.
Tab切换到规划Agent(键),在进行更改前审查实现策略。
TabFile References
文件引用
Use to fuzzy search and reference files in prompts.
@filename在提示中使用进行模糊搜索和引用文件。
@filenameUndo Stack
撤销栈
Use liberally - changes are stackable and reversible with .
/undo/redo灵活使用命令 - 更改可堆叠,且可通过恢复。
/undo/redoSession Management
会话管理
Use or to resume previous sessions and maintain context.
--continue-c使用或恢复之前的会话,保持上下文。
--continue-cReferences
参考资料
For detailed documentation, see:
- - Complete CLI reference
references/cli.md - - Tool details and permissions
references/tools.md - - Agent configuration guide
references/agents.md
如需详细文档,请查看:
- - 完整CLI参考
references/cli.md - - 工具详情和权限说明
references/tools.md - - Agent配置指南
references/agents.md