🚀 Control Bridge for OpenClaw Agent to manage OpenCode CLI
OpenCode Agent is an OpenClaw Skill that enables OpenClaw Agent to control OpenCode CLI — a free, open-source AI coding assistant (an alternative to Claude Code).
- External Perspective (User): A tool that helps you write code, review code, and fix bugs
- Internal Perspective (Agent): "Control Bridge for OpenCode CLI" — decides when to call, how to call, parse output, handle errors
- ✍️ Write Code: "Implement user registration", "Add API error handling"
- 👀 Code Review: "Review code security", "Check code quality"
- 🔧 Refactor: "Optimize performance", "Improve code structure"
- 💡 Explain Code: "Explain what this file does", "Analyze architecture"
- 🐛 Fix Bugs: "Fix login failure", "Debug this error"
- 🎯 Intent Recognition: Automatically detect coding tasks
- 🤔 Context Awareness: Gather relevant files, check session history
- 🧠 Command Decision: Select correct commands and flags (
--continue,--fork,--file) - 📤 Output Parsing: Parse OpenCode responses and extract key information
- 🔄 Error Recovery: Automatically handle failures, retry, or fallback
Choose one method:
# NPM (cross-platform)
npm install -g opencode-ai
# Homebrew (macOS/Linux)
brew install anomalyco/tap/opencode
# Chocolatey (Windows)
choco install opencode
# Scoop (Windows)
scoop install opencode# Login to AI provider (opens browser)
opencode auth login
# Check configured providers
opencode auth list# Clone to OpenClaw skills directory
cd ~/.openclaw/skills
git clone https://github.com/xuha233/opencode-agent-skill.git opencode-agentOr manually copy to ~/.openclaw/skills/opencode-agent/.
Simply ask OpenClaw Agent to code:
"Implement user login functionality"
The Agent will:
- Recognize this as a coding task ✅
- Gather relevant files (
src/auth/login.ts) - Call OpenCode:
opencode run "Implement user login" --file src/auth/login.ts - Parse output and present to you
- Use
--continueif more work needed
You: Implement user registration
Agent: ✅ Implementing user registration...
[OpenCode generates code...]
You: Add email verification
Agent: ✅ Adding email verification...
[OpenCode continues implementing...]
You: Review the code
Agent: ✅ Reviewing code...
[OpenCode reviews security, quality...]
Internal documentation for OpenClaw Agent
Activate skill when user request matches these patterns:
- Implementation: "implement", "build", "create", "write code", "generate"
- Code Review: "review", "audit", "check", "analyze code"
- Refactoring: "refactor", "improve", "optimize", "clean up"
- Explanation: "explain", "what does", "how does", "understand"
- Bug Fix: "fix bug", "debug", "resolve error", "investigate issue"
User Request → Intent Recognition → Context Check → Command Selection
Example:
User: "Add error handling"
→ Intent: Implementation ✅
→ Context: Continue task
→ Command: opencode run --continue "Add error handling"
| Scenarios | Command |
|---|---|
| New task | opencode run "prompt" |
| Continue task | opencode run --continue "prompt" |
| Fork alternative | opencode run --continue --fork "prompt" |
| Review single file | opencode run --file file.ts "review" |
| Deep reasoning | opencode run -m claude-sonnet-4 "prompt" |
1. Intent Recognition → Is this a coding task?
2. Gather Context → Relevant files, session history
3. Construct Command → Select command + flags
4. Execute Command → opencode run "prompt" --file ...
5. Parse Output → Extract code, suggestions, errors
6. Present to User → Summary, code blocks, key points
7. Error Handling → Retry, fallback, user feedback
For details: references/AGENTS_GUIDE.md
┌─────────────────────────────────────────────────────────┐
│ SKILL.md │
├─────────────────────────────────────────────────────────┤
│ • Activation conditions (when to activate) │
│ • Command decision logic (which command to use) │
│ • Context awareness rules (how to gather context) │
│ • Error handling (what to do when errors occur) │
└─────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ CLAUDE.md │
├─────────────────────────────────────────────────────────┤
│ • Workflow standards (workflow patterns) │
│ • Code review patterns (review patterns) │
│ • Dev persona (developer character) │
└─────────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────────┐
│ references/ │
├─────────────────────────────────────────────────────────┤
│ • AGENTS_GUIDE.md (Agent control guide) │
│ • COMMANDS.md (Detailed command reference) │
│ • WORKFLOW.md (Workflow patterns) │
│ • STANDARDS.md (Coding standards) │
│ • quick-reference.md (Command cheat sheet) │
└─────────────────────────────────────────────────────────┘
| File | Location | Purpose |
|---|---|---|
config.json |
~/.local/share/opencode/ |
Main configuration |
auth.json |
~/.local/share/opencode/ |
Provider credentials |
| Model | Best For | Cost |
|---|---|---|
deepseek/deepseek-chat |
Fast tasks, simple queries | Low |
anthropic/claude-sonnet-4-20250514 |
Balanced tasks | Medium |
anthropic/claude-opus-4-20250514 |
Deep reasoning, architecture | High |
You: "Implement user logout functionality"
Agent:
- ✅ Intent recognition: Implementation
- 📁 File context:
src/auth/session.ts - 🔧 Command:
opencode run "Implement user logout with JWT invalidation and session management" --file src/auth/session.ts - 📤 Parse output: Extract code
- 💬 Present to user:
✅ Implemented user logout Files created/modified: - src/auth/logout.ts (new) - src/api/auth/logout.ts (new) - src/auth/session.ts (modified: added invalidateSession) Main functionality: - Clear JWT token - Invalidate session - Return success response
You: "Review the login code"
Agent:
- ✅ Intent recognition: Code Review
- 📁 File context:
src/auth/login.ts,src/auth/session.ts - 🔧 Command:
opencode run "Review authentication login and session management for security, quality, best practices" --file src/auth/login.ts --file src/auth/session.ts - 📤 Parse output: Extract review findings
- 💬 Present to user:
✅ Code review completed 🔴 Critical Issues: 1. SQL injection risk (src/auth/login.ts:45) - Query not parameterized 2. JWT token not checked for expiration 🟡 Suggested Improvements: 1. Add input validation 2. Add failure retry limit 3. Improve error messages Recommend prioritizing 🔴 critical issues. Should I fix these issues?
You: "Login always fails"
Agent:
- ✅ Intent recognition: Bug Fix
- 📁 File context:
logs/error.log,src/auth/login.ts - 🔧 Command:
opencode run "Investigate: User reports login always fails. Find root cause and propose fix" --file logs/error.log --file src/auth/login.ts - 📤 Parse output: Extract root cause
- 💬 Present to user:
🔍 Problem Analysis Root Cause: Password comparison logic error (src/auth/login.ts:78) ❌ Wrong: `if (password !== user.password)` ✅ Should be: `bcrypt.compare(password, user.password)` Should I fix this?
You: "Implement registration, then add email verification, then test"
Agent:
# Phase 1
opencode run "Implement user registration with password hashing"
# Phase 2 (continue)
opencode run --continue "Add email verification after registration"
# Phase 3 (continue)
opencode run --continue "Write tests for registration + verification"| Feature | Claude Code | OpenCode | Notes |
|---|---|---|---|
| Open Source | ❌ No | ✅ Yes | OpenCode fully open source |
| Price | 💰 Subscription | ✅ Pay-as-you-go | Pay per use |
| LLM Providers | Anthropic only | ✅ 15+ providers | Supports GPT, DeepSeek, Claude, etc. |
| Session Resume | --resume |
--continue / -c |
Same semantics |
| Fork Sessions | ❌ Not supported | ✅ --fork |
OpenCode exclusive |
| Server Mode | ❌ Not supported | ✅ opencode serve |
Persistent backend, faster |
| GitHub Integration | ✅ Yes | ✅ Yes | Both support |
Cost Comparison (estimated):
| Task | Claude Code ($10/mo) | OpenCode (Pay-as-you-go) |
|---|---|---|
| 100 prompts (simple) | $10 | ≈ $2-5 |
| 50 prompts (complex) | $10 | ≈ $8-15 |
Recommendation:
- Frequent use → OpenCode more cost-effective
- Occasional use → Claude Code simpler
This skill is based on actual OpenCode CLI source code analysis:
packages/opencode/src/cli/cmd/run.tspackages/opencode/src/cli/cmd/session.tspackages/opencode/src/cli/cmd/stats.tspackages/opencode/src/cli/cmd/export.tspackages/opencode/src/cli/cmd/import.ts
All commands and flags validated against source implementation.
-
v2.0.0 — Control Bridge redesign (current)
- SKILL.md: Agent-centric tool guide
- references/AGENTS_GUIDE.md: Detailed integration guide
- README.md: User + Agent perspectives
-
v1.0.0 — Initial release
- User-oriented documentation
# Check version
opencode --version
# Reinstall
npm install -g opencode-ai# Check credentials
opencode auth list
# Re-login
opencode auth login- Agent will search workspace
- If not found, will ask user for correct path
- Complex tasks may take time
- Agent will wait and report progress
- Can cancel with user command
- This README — Quick start, examples, comparison
- SKILL.md — Activation conditions, command logic
- CLAUDE.md — Workflow standards, dev persona
- references/AGENTS_GUIDE.md — Detailed integration guide
- references/COMMANDS.md — Command reference
- references/WORKFLOW.md — Workflow patterns
- references/STANDARDS.md — Coding standards
- references/quick-reference.md — Command cheat sheet
MIT
- 📦 GitHub: https://github.com/xuha233/opencode-agent-skill
- 📖 OpenCode Docs: https://opencode.ai/docs/
- 🔧 OpenCode CLI Ref: https://opencode.ai/docs/cli
- 💻 OpenCode GitHub: https://github.com/anomalyco/opencode
- 🔗 Model Hub: https://models.dev/
- 🐛 Issue Tracker: https://github.com/anomalyco/opencode/issues
- OpenCode CLI: https://github.com/anomalyco/opencode
- Design Philosophy: Control bridge pattern — Agent → CLI → Execution
- Documentation: Based on actual source code analysis (v1.2.10)
Issues, feature requests, contributions: https://github.com/xuha233/opencode-agent-skill/issues
🚀 Happy coding with OpenClaw + OpenCode!
Author: 言午间
Contact: 3537183821@qq.com