OpenCode API

v1.0.2

透過 HTTP API 呼叫 OpenCode Server 進行 code review 與編碼任務。適用於 OpenClaw 派工給 OpenCode 執行的場景。

0· 29·0 current·0 all-time
MIT-0
Download zip
LicenseMIT-0 · Free to use, modify, and redistribute. No attribution required.
Security Scan
VirusTotalVirusTotal
Benign
View report →
OpenClawOpenClaw
Benign
high confidence
Purpose & Capability
The name/description (OpenCode API for code review) matches the code and SKILL.md. The package provides HTTP client wrappers, task helpers, and a PR-review wrapper that legitimately require access to a local OpenCode HTTP API and optional local repo data (git/gh). No unrelated env vars, binaries, or cloud credentials are requested.
Instruction Scope
Runtime instructions and code stay within the stated purpose. The scripts contact only the configured base_url (default http://127.0.0.1:4096), create sessions and post messages. They also read local files (analyze_file, batch_review), and opencode_review runs 'gh' and 'git' to fetch diffs — these behaviors are expected for a PR review integration but mean the skill will access local repository files and may invoke local CLIs.
Install Mechanism
No install spec is provided (instruction-only with bundled Python scripts). The only optional dependency is the well-known 'requests' Python package for one client file. No downloads from external or untrusted URLs are performed.
Credentials
The skill declares no required environment variables or credentials. However, opencode_review invokes the 'gh' CLI and 'git' which will use the user's existing Git/GitHub configuration and credentials if present; starting the 'opencode' server relies on a locally installed 'opencode' binary. This is proportionate to the stated purpose but worth noting.
Persistence & Privilege
The skill does not request 'always: true' and does not modify other skills or global configs. It may spawn a local 'opencode serve' process when auto-start is enabled; that is local process activity without elevated platform privileges.
Assessment
This skill appears to do what it says: it talks to a local OpenCode HTTP server on 127.0.0.1:4096, can auto-start a local 'opencode' server, and can read local repository files or invoke 'git'/'gh' to fetch diffs for PR reviews. Before installing, ensure you: 1) trust the bundled code or review it (scripts are included); 2) have or trust the 'opencode' binary the skill will try to run if auto-start is enabled; 3) understand that using the PR-review wrapper may read your repository files and use your local 'gh' credentials (if gh is invoked); and 4) install the optional 'requests' package if you plan to use the full client. If you do not want the skill to spawn processes, run with auto-start disabled and point base-url to a manually started, trusted OpenCode server.

Like a lobster shell, security has layers — review code before you run it.

code-reviewvk97783d22pbwst3tzwg5yk8hsx8448jacodingvk979w8r3e3srtprm80ryb9hs4d845xd0http-apivk97783d22pbwst3tzwg5yk8hsx8448jaintegrationvk97783d22pbwst3tzwg5yk8hsx8448jalatestvk97783d22pbwst3tzwg5yk8hsx8448jaopencodevk97783d22pbwst3tzwg5yk8hsx8448ja

License

MIT-0
Free to use, modify, and redistribute. No attribution required.

SKILL.md

OpenCode API Skill

透過 HTTP API 呼叫已啟動的 OpenCode Server,讓 OpenClaw 可以派工給 OpenCode 處理 code review 或編碼任務。

前置條件

  • OpenCode Server 必須已在 http://127.0.0.1:4096 啟動(會自動啟動)
  • 或使用 --no-auto-start 手動管理模式

快速開始

Sub-agent 直接 import(推薦)

import sys
sys.path.insert(0, "C:/Users/admin/.openclaw/workspace/skills/opencode-api/scripts")
from opencode_task import run_opencode_task, OpenCodeAPI

# 單次任務
result = run_opencode_task(
    prompt="請用繁體中文對以下程式碼進行 code review:\ndef foo(): pass",
    model="minimax/MiniMax-M2.7",
    reasoning="high",
)
print(result.text)        # 回覆文字
print(result.session_id)  # 可續接多輪
print(result.ok)          # True/False

# 多輪對話
client = OpenCodeAPI(auto_start=True)
sid = client.create_session(title="PR Review")
r1 = client.send_message("請 review...", session_id=sid, model="minimax/MiniMax-M2.7")
r2 = client.send_message("第三點再詳細點", session_id=sid)

CLI 呼叫

python scripts/opencode_task.py --prompt "請幫我分析這個函數" --model minimax/MiniMax-M2.7 --reasoning high

Script 總覽

檔案用途推薦場景
opencode_task.py乾淨的任務封裝(推薦)單次/多輪對話、sub-agent import
opencode_client.py完整 HTTP client需精細控制 API 底層
opencode_review.pyPR Review 專用 wrapper直接 review GitHub PR

模型速查表

模型 ID名稱思考支援適合場景
minimax/MiniMax-M2.7MiniMax M2.7性價比 coding(預設)
minimax/MiniMax-M2.5MiniMax M2.5中等複雜度任務
minimax/MiniMax-M2.7-highspeedMiniMax M2.7 高速快速響應
big-pickle:highBig Pickle High✅ 16K tokens深度分析(免費)
big-pickle:maxBig Pickle Max✅ 32K tokens極深度推理(免費)

查看完整模型清單:GET /config/providers


思考深度(reasoning)

說明
none關閉
minimal / low輕量思考
medium標準(預設)
high深度分析
xhigh極深度推理

⚡ 自動啟動 Server

所有 script 都支援自動啟動 OpenCode Server(預設開啟):

執行 script
    ├── 檢查 health
    │       ├── ✅ 已運行 → 直接執行
    │       └── ❌ 未運行 → 自動執行 opencode serve
    │               └── 等待最多 15 秒直到就緒

關閉自動啟動:--no-auto-start


觸發關鍵字

關鍵字對應行為
用 OpenCode review PR#xxxCLI: opencode_task.py --prompt "review PR#xxx"
用 OpenCode 分析這個檔案CLI: opencode_client.py --task analyze
用 OpenCode 多輪對話import OpenCodeAPI + 多輪
OpenCode 用高思考--reasoning high

依賴

# opencode_task.py:無外部依賴(標準函式庫)
# opencode_client.py:pip install requests

Files

9 total
Select a file
Select a file to preview.

Comments

Loading comments…