← 返回
未分类 中文

Opencode Cli

OpenCode CLI integration skill. Designed for AI agents like OpenClaw to execute coding tasks via OpenCode CLI. Core features: (1) Plan→Build workflow (2) Ses...
OpenCode CLI 集成技能,专为 AI 代理(如 OpenClaw)通过 OpenCode CLI 执行编码任务而设计。核心功能:(1) 计划→构建工作流 (2) 安全执行。
tchen6500 tchen6500 来源
未分类 clawhub v1.1.0 1 版本 100000 Key: 无需
★ 1
Stars
📥 681
下载
💾 1
安装
1
版本
#latest

概述

OpenCode CLI Integration

This skill is designed for AI agents like OpenClaw to execute coding tasks via OpenCode CLI.

OpenCode is an AI-powered code editor CLI. When called via OpenClaw, only CLI mode is used.


Security Scope

What this skill does:

  • Integrates with OpenCode CLI for coding tasks
  • Manages sessions, plans, and builds
  • Optionally connects to configured MCP servers (Playwright, Supabase, Context7)

What this skill does NOT do:

  • Install or modify system-wide packages
  • Access credentials outside configured MCP servers
  • Persist beyond user-initiated sessions

Credential access:

  • MCP servers (if configured) may use environment variables like SUPABASE_URL, SUPABASE_ANON_KEY, CONTEXT7_API_KEY
  • Skills run in project context; avoid committing secrets to version control
  • Only use this skill in repositories/environments you trust

Core Command

opencode run -m <provider/model> -- "<prompt>"

Example:

opencode run -m <provider/model> -- "Add error handling to the login function"

Plan→Build Workflow (Core)

⚠️ Key Rule: Maintain Same Session

Correct approach:

# 1. Start Plan (creates session)
opencode run -m <model> -- 'Analyze task, output plan.'

# 2. Wait for user APPROVE

# 3. Switch to Build (continue same session)
opencode run --continue --agent build -- 'Implement approved plan.'

Wrong approach (context lost):

❌ opencode run --agent plan "..."   # session A
❌ opencode run --agent build "..."  # session B (separate!)

Agent Options

AgentPurpose
----------------
planPlanning, analysis, design
buildImplementation, coding, modification
exploreCodebase exploration

Session Management

opencode run --continue -- '<prompt>'
opencode run --session <id> -- '<prompt>'
opencode run --continue --fork -- '<prompt>'
opencode session list
opencode session delete <id>

OpenClaw Integration

Standard Task

opencode run -m <model> -- '<task>'

Background Task

opencode run -m <model> -- '<task>'
process action:poll sessionId:<id> timeout:30000
process action:log sessionId:<id>
process action:kill sessionId:<id>

Monitoring Discipline

> ⚠️ Mandatory: After starting, must actively monitor. Do not wait for system event.

Start → Get sessionId
  ↓
Every 30-60s: poll + log
  ↓
Progress → Report
Error → Report immediately
Complete → Report result (do not wait for event)

Violation criteria:

  • Start without monitoring → Abandoning responsibility
  • User asks "is it done?" before checking → Failure

MCP Integration

OpenCode supports MCP integration to extend capabilities. Must run in project root directory.

Common tools: Playwright (UI automation), Supabase (database)

Scenario guide:

ScenarioReference
---------------------
Need UI automation testing (Playwright)references/mcp-config-guide.md
Need database operations (Supabase)references/mcp-config-guide.md
MCP not loading, troubleshoot configreferences/mcp-config-guide.md

Built-in Tools

OpenCode Agent built-in tools: read/write/edit, bash, grep/glob, todowrite, skill, webfetch

Scenario guide:

ScenarioReference
---------------------
Unsure if Agent can perform an operationreferences/built-in-tools-guide.md
Plan Agent reports insufficient permissionsreferences/built-in-tools-guide.md (see tool permissions table)

Practical Tips

  • File reference: Use @filename to quickly reference files
  • Undo changes: /undo to undo, /redo to restore

Scenario guide:

ScenarioReference
---------------------
Want to reference file instead of typing pathreferences/tips-guide.md (file reference)
Made mistake and want to rollbackreferences/tips-guide.md (undo/redo)
Want to learn TUI shortcutsreferences/tips-guide.md (shortcuts)

Skills Configuration

Scenario guide:

ScenarioReference
---------------------
Want to add custom skillreferences/skills-config-guide.md
Unsure where to place skill filesreferences/skills-config-guide.md

Common Patterns

> Note: Examples use openclaw system event for optional task notification. This is an OpenClaw platform command. Omit if running outside OpenClaw.

Planning Task

opencode run -m <model> -- 'Analyze task, output plan.'

For detailed plan format, see project workflow documentation.

Implementation Task

opencode run -m <model> -- 'Execute approved plan.'

Verify with: npm run build && npm test

Database Operations

cd /path/to/project
opencode run -m <model> -- 'Use Supabase MCP for database operations.'

See: references/mcp-config-guide.md for MCP setup.

UI Testing

opencode run -m <model> -- 'Use Playwright MCP for UI testing.'

See: references/mcp-config-guide.md for MCP setup.


Troubleshooting

sysctl not found

export PATH="/usr/sbin:/usr/bin:/sbin:/bin:$PATH"

MCP not loading

Ensure running in project root:

cd /path/to/project && opencode run ...

See: references/mcp-config-guide.md

Session context lost

Use --continue instead of separate starts:

✅ opencode run --continue --agent build "..."
❌ opencode run --agent build "..."

Quick Reference

Common Commands

TaskCommand
---------------
Plan taskopencode run -m -- 'Analyze...'
Build (continue session)opencode run --continue --agent build -- 'Implement...'
Continue last sessionopencode run --continue
Specific sessionopencode run --session
Fork sessionopencode run --continue --fork
List sessionsopencode session list
Delete sessionopencode session delete
View modelsopencode models

OpenClaw Integration

TaskCommand
---------------
Background taskpty:true background:true command:"opencode run..."
Monitor progressprocess action:poll sessionId:
View logsprocess action:log sessionId:
Terminate taskprocess action:kill sessionId:

Configuration Guide Index

ScenarioReference
---------------------
UI automation / Database operationsreferences/mcp-config-guide.md
Agent tool capabilities / Permissionsreferences/built-in-tools-guide.md
Shortcuts / File reference / Undoreferences/tips-guide.md
Add custom skillreferences/skills-config-guide.md

CLI Integration v2.6 - 2026-04-05

版本历史

共 1 个版本

  • v1.1.0 当前
    2026-05-03 04:17 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-agent

self-improving agent

pskoett
捕获经验教训、错误及修正内容,以实现持续改进。适用于以下场景:(1)命令或操作意外失败;(2)用户纠正Claude(如“不,那不对……”“实际上……”);(3)用户请求的功能不存在;(4)外部API或工具出现故障;(5)Claude发现自身
★ 4,078 📥 808,670
ai-agent

Self-Improving + Proactive Agent

ivangdavila
自我反思+自我批评+自我学习+自组织记忆。智能体评估自身工作、发现错误并持续改进。
★ 1,376 📥 320,195
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 676 📥 325,263