一键导入
opencode
Delegate coding tasks to OpenCode CLI (autonomous AI coding agent).
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Delegate coding tasks to OpenCode CLI (autonomous AI coding agent).
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | opencode |
| description | Delegate coding tasks to OpenCode CLI (autonomous AI coding agent). |
| version | 2.0.0 |
| author | Hermes Agent |
| license | MIT |
| metadata | {"hermes":{"tags":["Coding-Agent","OpenCode","AI-Agent","Code-Review","Refactoring","PTY","Automation"],"related_skills":["claude-code","codex","hermes-agent"]}} |
Delegate coding tasks to OpenCode CLI via the Hermes terminal. OpenCode is an autonomous coding agent that can read files, write code, run shell commands, and manage git workflows. It supports multiple AI providers (OpenAI, Anthropic, Azure, Vercel AI Gateway, GitHub Copilot, Google, Perplexity, OpenCode Go) and can operate in print mode, interactive TUI, ACP server, or headless server modes.
~/.opencode/bin/opencode (v1.14.33)PATH by default. Always use the full path ~/.opencode/bin/opencode or add ~/.opencode/bin to PATH.opencode providers login for each provider you want to use. Credentials are stored in ~/.local/share/opencode/auth.json.opencode providers list shows configured credentials.opencode models lists all available models across all configured providers.opencode --versionopencode upgrade or opencode upgrade <version>opencode doctor or opencode debug config| Path | Purpose |
|---|---|
~/.opencode/bin/opencode | Binary |
~/.local/share/opencode/ | Data (auth.json, opencode.db, sessions, tool-output) |
~/.config/opencode/ | Config files |
~/.cache/opencode/ | Cache |
~/.local/state/opencode/ | State |
/tmp/opencode/ | Temporary files |
Hermes interacts with OpenCode in four modes. Choose based on the task.
opencode run) — Non-Interactive (PREFERRED for most tasks)Print mode runs a one-shot task and returns the result. No PTY needed. No interactive prompts.
terminal(command="~/.opencode/bin/opencode run 'Add error handling to all API calls in src/' --format json --dangerously-skip-permissions", workdir="/path/to/project", timeout=120)
When to use print mode:
--format jsoncat file | opencode run "analyze this")Print mode flags:
| Flag | Purpose |
|---|---|
-m, --model | Model in provider/model format (e.g., opencode-go/kimi-k2.6) |
--variant | Reasoning effort: high, max, minimal (provider-specific) |
--thinking | Show thinking blocks in output |
--dangerously-skip-permissions | Auto-approve all tool use (no interactive prompts) |
--format json | Output newline-delimited JSON events instead of formatted text |
-f, --file | Attach file(s) to the message |
--title | Set session title |
--agent | Use a specific agent (e.g., build, explore) |
--attach | Attach to a running opencode server instead of spawning |
--dir | Directory to run in |
--port | Port for local server (random if not specified) |
-c, --continue | Continue last session |
-s, --session | Resume specific session ID |
--fork | Fork session when continuing |
--share | Share the session |
Interactive mode gives you a full conversational REPL. Requires tmux orchestration.
# Start a tmux session
terminal(command="tmux new-session -d -s opencode-work -x 140 -y 40")
# Launch OpenCode inside it
terminal(command="tmux send-keys -t opencode-work 'cd /path/to/project && ~/.opencode/bin/opencode' Enter")
# Wait for startup, then send your task
terminal(command="sleep 5 && tmux send-keys -t opencode-work 'Refactor the auth module to use JWT tokens' Enter")
# Monitor progress by capturing the pane
terminal(command="sleep 15 && tmux capture-pane -t opencode-work -p -S -50")
# Send follow-up tasks
terminal(command="tmux send-keys -t opencode-work 'Now add unit tests for the new JWT code' Enter")
# Exit when done
terminal(command="tmux send-keys -t opencode-work '/exit' Enter")
When to use interactive mode:
opencode acp) — External Agent ConnectionStart an Agent Client Protocol server that other agents can connect to.
# Start ACP server in background
terminal(command="~/.opencode/bin/opencode acp --port 8080", background=true)
# Attach from another process
terminal(command="~/.opencode/bin/opencode attach http://127.0.0.1:8080")
ACP flags:
| Flag | Purpose |
|---|---|
--port | Port to listen on (default: random) |
--hostname | Hostname to bind (default: 127.0.0.1) |
--mdns | Enable mDNS discovery (sets hostname to 0.0.0.0) |
--mdns-domain | Custom mDNS domain (default: opencode.local) |
--cors | Additional CORS domains |
--cwd | Working directory |
opencode serve)Start a headless server without the TUI. Useful for API-like access.
terminal(command="~/.opencode/bin/opencode serve --port 8080", background=true)
Use --format json to get structured, machine-readable output:
terminal(command="~/.opencode/bin/opencode run 'Review auth.py for security issues' --format json --dangerously-skip-permissions", workdir="/project", timeout=120)
Returns newline-delimited JSON events:
| Event Type | Description |
|---|---|
step_start | Beginning of an agentic step |
tool_use | Tool execution with input/output |
text | Text response from the agent |
step_finish | End of step with token/cost info |
Key fields in step_finish:
{
"type": "step_finish",
"part": {
"reason": "tool-calls|stop",
"tokens": { "total": 9658, "input": 133, "output": 28, "reasoning": 25 },
"cost": 0.000625068
}
}
Note: Unlike Claude Code, OpenCode does not have a single final JSON result object. You must parse the event stream.
Extract just the text responses:
~/.opencode/bin/opencode run "Explain X" --format json --dangerously-skip-permissions | \
jq -r 'select(.type == "text") | .part.text'
Extract tool outputs:
~/.opencode/bin/opencode run "Run tests" --format json --dangerously-skip-permissions | \
jq -r 'select(.type == "tool_use" and .part.tool == "bash") | .part.state.output'
# Pipe a file for analysis
terminal(command="cat src/auth.py | ~/.opencode/bin/opencode run 'Review this code for bugs' --format json --dangerously-skip-permissions", timeout=60)
# Pipe command output
terminal(command="git diff HEAD~3 | ~/.opencode/bin/opencode run 'Summarize these changes' --format json --dangerously-skip-permissions", timeout=60)
# Continue last session
terminal(command="~/.opencode/bin/opencode run 'Continue refactoring' --continue --format json --dangerously-skip-permissions", workdir="/project", timeout=120)
# Resume specific session
terminal(command="~/.opencode/bin/opencode run 'What did we do last time?' --session ses_xxx --format json --dangerously-skip-permissions", timeout=60)
# Fork a session (new ID, keeps history)
terminal(command="~/.opencode/bin/opencode run 'Try a different approach' --session ses_xxx --fork --format json --dangerously-skip-permissions", timeout=120)
# Connect to an existing opencode server instead of spawning a new one
terminal(command="~/.opencode/bin/opencode run 'Check status' --attach http://127.0.0.1:8080 --format json", timeout=60)
# Periodic capture to check if OpenCode is still working or waiting for input
terminal(command="tmux capture-pane -t opencode-work -p -S -10")
Status indicators:
❯ at bottom = waiting for input (done or asking a question)● or spinner = processingOpenCode may present permission prompts. In interactive mode, handle via tmux send-keys. For fully automated use, prefer print mode with --dangerously-skip-permissions.
terminal(command="~/.opencode/bin/opencode providers list")
terminal(command="~/.opencode/bin/opencode providers login <url>")
terminal(command="~/.opencode/bin/opencode providers logout")
terminal(command="~/.opencode/bin/opencode models")
terminal(command="~/.opencode/bin/opencode run 'Task' -m opencode-go/kimi-k2.6 --format json --dangerously-skip-permissions", timeout=120)
Common providers:
| Provider | Example Model |
|---|---|
opencode-go | opencode-go/kimi-k2.6 (DEFAULT, 262K cap), opencode-go/deepseek-v4-pro |
anthropic | anthropic/claude-sonnet-4-6, anthropic/claude-opus-4-6 |
openai | openai/gpt-5, openai/gpt-4o |
azure | azure/gpt-4o, azure/claude-sonnet-4-6 |
github-copilot | github-copilot/claude-sonnet-4 |
google | google/gemini-2.5-pro |
vercel | vercel/anthropic/claude-sonnet-4-6 |
terminal(command="~/.opencode/bin/opencode session list")
terminal(command="~/.opencode/bin/opencode session delete <sessionID>")
terminal(command="~/.opencode/bin/opencode export <sessionID> --sanitize > /tmp/session.json")
Pitfall: opencode export prepends a log line before the JSON. Strip it before parsing:
terminal(command="~/.opencode/bin/opencode export <sessionID> --sanitize | tail -n +2 | jq '.info.id'")
terminal(command="~/.opencode/bin/opencode import /tmp/session.json")
Note: Sessions are stored in ~/.local/share/opencode/opencode.db (SQLite). The session list command queries this database.
OpenCode has built-in agents with different permission profiles:
| Agent | Type | Purpose |
|---|---|---|
build | primary | General coding with full tool access |
compaction | primary | Context compaction and summarization |
plan | primary | Task planning (restricted to read + plan files) |
summary | primary | Session summarization (read-only) |
title | primary | Auto-generate session titles (read-only) |
explore | subagent | Code exploration (read, grep, glob, bash) |
general | subagent | General purpose assistant |
terminal(command="~/.opencode/bin/opencode agent list")
terminal(command="~/.opencode/bin/opencode run 'Refactor auth.py' --agent build --format json --dangerously-skip-permissions", timeout=120)
terminal(command="~/.opencode/bin/opencode github install")
terminal(command="~/.opencode/bin/opencode github run")
terminal(command="~/.opencode/bin/opencode pr 42")
This fetches and checks out the PR branch, then launches OpenCode.
terminal(command="~/.opencode/bin/opencode mcp add")
terminal(command="~/.opencode/bin/opencode mcp list")
terminal(command="~/.opencode/bin/opencode mcp auth <name>")
terminal(command="~/.opencode/bin/opencode mcp debug <name>")
Instead of using raw tmux to manage multiple instances, prefer using Hermes' native delegate_task tool to spawn isolated subagents that run OpenCode independently. This avoids terminal multiplexing headaches and keeps output structured.
{
"tasks": [
{
"goal": "Fix the auth bug in src/auth.py using OpenCode",
"context": "Use terminal to run: ~/.opencode/bin/opencode run 'Fix auth bug' --format json --dangerously-skip-permissions",
"toolsets": ["terminal"]
},
{
"goal": "Write integration tests for API endpoints using OpenCode",
"context": "Use terminal to run: ~/.opencode/bin/opencode run 'Write tests' --format json --dangerously-skip-permissions",
"toolsets": ["terminal"]
}
]
}
If you absolutely must orchestrate without subagents, use tmux:
# Task 1 via tmux
terminal(command="tmux new-session -d -s task1 -x 140 -y 40 && tmux send-keys -t task1 'cd ~/project && ~/.opencode/bin/opencode run \"Fix the auth bug in src/auth.py\" --format json --dangerously-skip-permissions' Enter")
terminal(command="~/.opencode/bin/opencode stats")
terminal(command="~/.opencode/bin/opencode stats --days 7 --models 5")
--format json sparingly — it captures full event streams which can be verboseterminal(timeout=120) acts as a cost ceiling since OpenCode lacks built-in --max-turns or --max-budgetsummary and title agents are read-only and cheaperopencode-go models are often more cost-effective than premium providersstats — track spend across providers and models| Variable | Effect |
|---|---|
OPENCODE_SERVER_PASSWORD | Default password for server attach (-p flag) |
terminal(command="~/.opencode/bin/opencode debug config")
terminal(command="~/.opencode/bin/opencode debug paths")
terminal(command="~/.opencode/bin/opencode debug scrap")
terminal(command="~/.opencode/bin/opencode debug skill")
terminal(command="~/.opencode/bin/opencode debug agent build")
terminal(command="~/.opencode/bin/opencode db 'SELECT * FROM sessions LIMIT 5' --format json")
~/.opencode/bin/opencode or add ~/.opencode/bin to PATH first.--max-turns or --max-budget-usd — OpenCode lacks built-in cost/turn limits. Use Hermes timeout parameter as a proxy.--output-format json, OpenCode returns newline-delimited events. You must parse the stream.--dangerously-skip-permissions is required for automation — Without it, OpenCode may prompt for permission, causing the process to hang.~/.local/share/opencode/opencode.db. The session list command queries this DB.auth.json — never commit or expose ~/.local/share/opencode/auth.json.provider/model — not just model name. Use opencode models to see valid values.--variant is provider-specific — not all providers support high/max/minimal.tmux kill-session -t <name> when done.opencode pr checks out the branch — it modifies your working directory.--port if you need a fixed endpoint.opencode export prepends a log line — output starts with Exporting session: ses_xxx\n before the JSON body. Pipe through tail -n +2 before jq.opencode-go/kimi-k2.6 model has an empirically confirmed hard context cap at 262K tokens. If your project approaches this limit, it will crash or fail to ingest new files.opencode run --agent compaction "Compact the current context" before issuing large queries, or break tasks into smaller isolated opencode run commands instead of long-running interactive sessions.run) for single tasks — cleaner, no dialog handling, structured output via --format json~/.opencode/bin/opencode unless PATH has been configured--dangerously-skip-permissions in print mode — prevents permission prompt hangsworkdir — keep OpenCode focused on the right project directorytimeout as cost control — since OpenCode lacks --max-turns, rely on Hermes terminal timeoutstmux capture-pane -t <session> -p -S -50 to check progress❯ prompt — indicates OpenCode is waiting for input (done or asking a question)--format json for automation — parse the event stream for structured data extraction--agent for specialized tasks — build for coding, explore for investigation, summary for read-only analysis