OpenCode Server API Skill Handbook
Version: v4.6.0 | Server: v1.2.15 | oho CLI: v1.1.2
⚠️ Important: All OpenCode operations must be sent via oho CLI. Python SDK or curl are no longer supported.
🚫 Telegram Message Guidelines (Important)
Prohibited Content:
- - ❌ Do not send notifications like "There are updates", "Skill has been updated"
- ❌ Do not send formatted version changelogs
- ❌ Do not send lengthy confirmation reports after task submission
Correct Approach:
- - ✅ Return only a concise session ID and status after task submission
- ✅ Notify users only when there is substantial progress
- ✅ Keep messages brief and direct
Example:
✅ Task submitted
Session: ses_xxx
Project: babylon3DWorld
🚀 Quick Start
Submit Tasks (Async Mode to Avoid Timeout)
CODEBLOCK1
Key Parameters
| Parameter | Type | Description | Default |
|---|
| INLINECODE0 | string | Session title (auto-generated if not provided) | Auto-generated |
| INLINECODE1 |
string | Parent session ID (for creating child sessions) | - |
|
--directory | string | Session working directory, project path | Current directory |
|
--agent | string | Agent ID for the message | - |
|
--model | string | Model ID for the message (e.g.,
provider:model) | minimax-cn-coding-plan/MiniMax-M2.7 |
|
--no-reply | bool | Do not wait for AI response | false |
|
--system | string | System prompt | - |
|
--tools | string[] | Tool list (can be specified multiple times) | - |
|
--file | string[] | File attachments (can be specified multiple times) | - |
|
--timeout | int | Request timeout in seconds | 300 |
|
-j, --json | bool | JSON output | false |
📋 Common Commands
Session Management
CODEBLOCK2
Message Management
CODEBLOCK3
Project Management
CODEBLOCK4
Global Commands
CODEBLOCK5
Configuration Management
CODEBLOCK6
Provider Management
CODEBLOCK7
File Operations
CODEBLOCK8
Find Commands
CODEBLOCK9
Other Commands
CODEBLOCK10
⚠️ Timeout Handling (Important)
The oho add command waits for AI response by default. For complex tasks, the AI may need more time to think, which could cause timeout.
Ways to Avoid Timeout
Method 1: Use --no-reply Parameter (Recommended)
CODEBLOCK11
Method 2: Increase Timeout
CODEBLOCK12
Method 3: Use --timeout Parameter (Most Convenient)
CODEBLOCK13
Method 4: Use Async Commands
CODEBLOCK14
Timeout Configuration
| Configuration Method | Priority | Description |
|---|
| INLINECODE15 parameter | Highest | Temporary override, only effective for current command |
| INLINECODE16 env var |
Medium | Effective for current shell session |
| Default value | Lowest | 300 seconds (5 minutes) |
Timeout Error Messages
If timeout occurs, you will see a friendly error:
CODEBLOCK15
Background Polling (Optional)
CODEBLOCK16
🤖 Agent System
| Agent | Role | Use Cases |
|---|
| @sisyphus | Main coordinator | Large feature development, parallel execution |
| @hephaestus |
Deep worker | Code exploration, performance optimization |
|
@prometheus | Strategic planner | Requirements clarification, architecture design |
📝 Practical Examples
babylon3DWorld Project Tasks
CODEBLOCK17
Multi-Project Batch Tasks
CODEBLOCK18
OpenCode Server Usage
- 1. rerun.sh
CODEBLOCK19
- 2. run.sh
CODEBLOCK20
🔧 Troubleshooting
Restart OpenCode Server
Standard Restart (Recommended):
CODEBLOCK21
Description:
- -
rerun.sh automatically stops old service and starts new one - Use
& to run in background to avoid blocking - Wait 3-5 seconds after restart for service to fully start
Verify Service is Running:
CODEBLOCK22
View Logs:
CODEBLOCK23
If Restart Script Gets Stuck:
CODEBLOCK24
401 Unauthorized
CODEBLOCK25
Session Not Found
CODEBLOCK26
Task Timeout
CODEBLOCK27
ConfigInvalidError (500 Error)
Symptoms:
CODEBLOCK28
Cause:
The opencode.json or .opencode/opencode.json config file in the project does not comply with the schema requirements.
Common Errors:
CODEBLOCK29
Solution:
CODEBLOCK30
Prevention:
- - Backup
opencode.json before modifying - Use
oho config get to verify config is valid - Reference official schema: https://opencode.ai/config.json
🔗 MCP Server
oho can act as an MCP (Model Context Protocol) server, allowing external MCP clients (like Claude Desktop, Cursor, etc.) to call OpenCode API via MCP protocol.
Start MCP Server
CODEBLOCK31
Available MCP Tools
| Tool | Description |
|---|
| INLINECODE23 | List all sessions |
| INLINECODE24 |
Create new session |
|
session_get | Get session details |
|
session_delete | Delete session |
|
session_status | Get all session statuses |
|
message_list | List messages in session |
|
message_add | Send message to session |
|
config_get | Get OpenCode configuration |
|
project_list | List all projects |
|
project_current | Get current project |
|
provider_list | List AI providers |
|
file_list | List files in directory |
|
file_content | Read file content |
|
find_text | Search text in project |
|
find_file | Find files by name |
|
global_health | Check server health status |
MCP Client Configuration
Claude Desktop (macOS/Windows)
Add to claude_desktop_config.json:
CODEBLOCK32
Cursor
Add to Cursor settings (JSON mode):
CODEBLOCK33
🔗 Related Resources
- - OpenCode Official Docs: https://opencode.ai/docs/
- oho CLI Repository: https://github.com/tornado404/opencode_cli
- OpenAPI Spec: http://localhost:4096/doc
Created: 2026-02-27 13:46 CST
Last Updated: 2026-04-02 00:43 CST - Added session achieve command
OpenCode Server API 技能手册
版本: v4.6.0 | 服务器: v1.2.15 | oho CLI: v1.1.2
⚠️ 重要提示: 所有 OpenCode 操作必须通过 oho CLI 发送。不再支持 Python SDK 或 curl。
🚫 Telegram 消息指南(重要)
禁止内容:
- - ❌ 不要发送类似有更新、技能已更新的通知
- ❌ 不要发送格式化的版本更新日志
- ❌ 任务提交后不要发送冗长的确认报告
正确做法:
- - ✅ 任务提交后仅返回简洁的会话 ID 和状态
- ✅ 仅在取得实质性进展时通知用户
- ✅ 保持消息简短直接
示例:
✅ 任务已提交
会话: ses_xxx
项目: babylon3DWorld
🚀 快速开始
提交任务(异步模式避免超时)
bash
最常用:一条命令创建会话并发送消息,directory 为项目路径
oho add 修复登录 bug --title Bug 修复 --directory /mnt/d/fe/babylon3DWorld --model minimax-cn-coding-plan:MiniMax-M2.7 --no-reply
另一个示例:总结今日进展
oho add 总结今天的变更 --title 命令测试 --directory /mnt/d/fe/opencode_cli --model minimax-cn-coding-plan:MiniMax-M2.7 --no-reply
指定 Agent
oho add @hephaestus 修复登录 bug --title Bug 修复 --directory /mnt/d/fe/project --model minimax-cn-coding-plan:MiniMax-M2.7 --no-reply
附加文件
oho add 分析日志 --file /var/log/app.log --directory /mnt/d/fe/project --no-reply
关键参数
| 参数 | 类型 | 描述 | 默认值 |
|---|
| --title | 字符串 | 会话标题(未提供时自动生成) | 自动生成 |
| --parent |
字符串 | 父会话 ID(用于创建子会话) | - |
| --directory | 字符串 | 会话工作目录,项目路径 | 当前目录 |
| --agent | 字符串 | 消息的 Agent ID | - |
| --model | 字符串 | 消息的模型 ID(例如 provider:model) | minimax-cn-coding-plan/MiniMax-M2.7 |
| --no-reply | 布尔值 | 不等待 AI 响应 | false |
| --system | 字符串 | 系统提示词 | - |
| --tools | 字符串数组 | 工具列表(可多次指定) | - |
| --file | 字符串数组 | 文件附件(可多次指定) | - |
| --timeout | 整数 | 请求超时时间(秒) | 300 |
| -j, --json | 布尔值 | JSON 输出 | false |
📋 常用命令
会话管理
bash
列出所有会话
oho session list
按 ID 过滤(模糊匹配)
oho session list --id ses_abc
按标题过滤(模糊匹配)
oho session list --title 测试
按项目 ID 过滤
oho session list --project-id proj1
按目录过滤
oho session list --directory babylon
按时间戳过滤
oho session list --created 1773537883643
oho session list --updated 1773538142930
按状态过滤
oho session list --status running # running/completed/error/aborted/idle
oho session list --running # 仅显示运行中的会话
排序和分页
oho session list --sort updated --order desc # 按更新时间降序排序
oho session list --limit 10 --offset 0 # 分页
JSON 输出
oho session list -j
创建会话
oho session create
oho session create --title 名称
oho session create --parent ses_xxx # 创建子会话
oho session create --path /path # 在指定目录创建
获取会话详情
oho session get
更新会话
oho session update --title 新标题
获取子会话
oho session children
获取待办事项
oho session todo
分支会话
oho session fork
中止会话
oho session abort
共享/取消共享会话
oho session share
oho session unshare
获取文件差异
oho session diff
会话总结
oho session summarize
回退消息
oho session revert --message
oho session unrevert
响应权限请求
oho session permissions --response allow
删除会话
oho session delete ses_xxx
归档会话
oho session achieve --directory /mnt/d/fe/project
消息管理
bash
列出消息
oho message list -s ses_xxx
获取消息详情
oho message get -s ses_xxx
发送消息(同步)
oho message add -s ses_xxx 继续任务
异步发送(不等待响应)
oho message prompt-async -s ses_xxx 任务内容
执行命令
oho message command -s ses_xxx /help
运行 shell 命令
oho message shell -s ses_xxx --agent default ls -la
项目管理
bash
列出所有项目
oho project list
获取当前项目
oho project current
获取当前路径
oho path
获取 VCS 信息
oho vcs
释放当前实例
oho instance dispose
全局命令
bash
检查服务器健康状态
oho global health
监听全局事件流(SSE)
oho global event
配置管理
bash
获取配置
oho config get
更新配置
oho config set --theme dark
列出提供商
oho config providers
提供商管理
bash
列出所有提供商
oho provider list
获取认证方式
oho provider auth
OAuth 授权
oho provider oauth authorize
处理回调
oho provider oauth callback
文件操作
bash
列出文件
oho file list [路径]
读取文件内容
oho file content <路径>
获取文件状态
oho file status
查找命令
bash
搜索文本
oho find text 模式
查找文件
oho find file 查询
查找符号
oho find symbol 查询
其他命令
bash
列出 Agent
oho agent list
列出命令
oho command list
列出工具 ID
oho tool ids
列出工具
oho tool list --provider xxx --model xxx
LSP 状态
oho lsp status
格式化器状态
oho formatter status
MCP 服务器
oho mcp list
oho mcp add <名称> --config {}
TUI
oho tui open-help
oho tui show-toast --message 消息
认证设置
oho auth set --credentials key=value
⚠️ 超时处理(重要)
oho add 命令默认会等待 AI 响应。对于复杂任务,AI 可能需要更多时间思考,这可能导致超时。
避免超时的方法
方法 1:使用 --no-reply 参数(推荐)
bash
✅ 发送消息后立即返回,不等待 AI 响应
oho add 分析项目结构 --directory /mnt/d/fe/project --no-reply
稍后检查结果
oho message list -s
方法 2:增加超时时间
bash
设置超时时间为 10 分钟(600 秒)
export OPENCODECLIENTTIMEOUT=600
oho add 复杂任务 --directory /mnt/d/fe/project
或临时设置
OPENCODECLIENTTIMEOUT=600 oho add 复杂任务 --directory /mnt/d/fe/project
方法 3:使用 --timeout 参数(最便捷)
bash
临时设置超时时间为 10 分钟
oho add 复杂任务 --directory /mnt/d/fe/project --timeout 600
设置超时时间为 1 小时
oho add 大规模重构 --directory /mnt/d/