跳到正文
Skillpedia
通用编程260k · #444

opencode

它能做什么

它指导你的智能体运行 OpenCode,这是一个支持多家 AI 服务商的开源编程智能体,用于处理你项目中的任务。它适合希望由 Hermes 管理一个外部编程工作者的开发者。

适用场景

  • ✓你明确希望 OpenCode 实现、重构或审阅代码的时候。
  • ✓编程任务较长,需要沿途检查进度的时候。
  • ✓你希望在不同的工作文件夹中同时运行多个编程任务的时候。

技能链接

https://github.com/NousResearch/hermes-agent/blob/main/optional-skills/autonomous-ai-agents/opencode/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/NousResearch/hermes-agent/blob/main/optional-skills/autonomous-ai-agents/opencode/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请使用 OpenCode,为我项目中的 API 调用添加重试逻辑,并更新测试。”

每周 5 个新技能,1 分钟读完。

工作原理

对于范围明确的任务,智能体在选定的文件夹中运行 opencode 命令;对于较长的会话,则使用其交互式界面。它还会检查正在运行的是哪一个 OpenCode 程序。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

OpenCode CLI

Use OpenCode as an autonomous coding worker orchestrated by Hermes terminal/process tools. OpenCode is a provider-agnostic, open-source AI coding agent with a TUI and CLI.

When to Use

  • User explicitly asks to use OpenCode
  • You want an external coding agent to implement/refactor/review code
  • You need long-running coding sessions with progress checks
  • You want parallel task execution in isolated workdirs/worktrees

Prerequisites

  • OpenCode installed: npm i -g opencode-ai@latest or brew install anomalyco/tap/opencode
  • Auth configured: opencode auth login or set provider env vars (OPENROUTER_API_KEY, etc.)
  • Verify: opencode auth list should show at least one provider
  • Git repository for code tasks (recommended)
  • pty=true for interactive TUI sessions

Binary Resolution (Important)

Shell environments may resolve different OpenCode binaries. If behavior differs between your terminal and Hermes, check:

terminal(command="which -a opencode")
terminal(command="opencode --version")

If needed, pin an explicit binary path:

terminal(command="$HOME/.opencode/bin/opencode run '...'", workdir="~/project", pty=true)

One-Shot Tasks

Use opencode run for bounded, non-interactive tasks:

terminal(command="opencode run 'Add retry logic to API calls and update tests'", workdir="~/project")

Attach context files with -f:

terminal(command="opencode run 'Review this config for security issues' -f config.yaml -f .env.example", workdir="~/project")

Show model thinking with --thinking:

terminal(command="opencode run 'Debug why tests fail in CI' --thinking", workdir="~/project")

Force a specific model:

terminal(command="opencode run 'Refactor auth module' --model openrouter/anthropic/claude-sonnet-4", workdir="~/project")

Interactive Sessions (Background)

For iterative work requiring multiple exchanges, start the TUI in background:

terminal(command="opencode", workdir="~/project", background=true, pty=true)
# Returns session_id

# Send a prompt
process(action="submit", session_id="<id>", data="Implement OAuth refresh flow and add tests")

# Monitor progress
process(action="poll", session_id="<id>")
process(action="log", session_id="<id>")

# Send follow-up input
process(action="submit", session_id="<id>", data="Now add error handling for token expiry")

# Exit cleanly — Ctrl+C
process(action="write", session_id="<id>", data="\x03")
# Or just kill the process
process(action="kill", session_id="<id>")

Important: Do NOT use /exit — it is not a valid OpenCode command and will open an agent selector dialog instead. Use Ctrl+C (\x03) or process(action="kill") to exit.

TUI Keybindings

Key Action
Enter Submit message (press twice if needed)
Tab Switch between agents (build/plan)
Ctrl+P Open command palette
Ctrl+X L Switch session
Ctrl+X M Switch model
Ctrl+X N New session
Ctrl+X E Open editor
Ctrl+C Exit OpenCode

Resuming Sessions

After exiting, OpenCode prints a session ID. Resume with:

terminal(command="opencode -c", workdir="~/project", background=true, pty=true)  # Continue last session
terminal(command="opencode -s ses_abc123", workdir="~/project", background=true, pty=true)  # Specific session

Common Flags

Flag Use
run 'prompt' One-shot execution and exit
--continue / -c Continue the last OpenCode session
--session <id> / -s Continue a specific session
--agent <name> Choose OpenCode agent (build or plan)
--model provider/model Force specific model
--format json Machine-readable output/events
--file <path> / -f Attach file(s) to the message
--thinking Show model thinking blocks
--variant <level> Reasoning effort (high, max, minimal)
--title <name> Name the session
--attach <url> Connect to a running opencode server

Procedure

  1. Verify tool readiness:
    • terminal(command="opencode --version")
    • terminal(command="opencode auth list")
  2. For bounded tasks, use opencode run '...' (no pty needed).
  3. For iterative tasks, start opencode with background=true, pty=true.
  4. Monitor long tasks with process(action="poll"|"log").
  5. If OpenCode asks for input, respond via process(action="submit", ...).
  6. Exit with process(action="write", data="\x03") or
常见问题

我如何设置它?

使用 npm 或 Homebrew 安装 OpenCode,然后通过 opencode auth login 登录,或设置服务商密钥。

我如何确认它已准备就绪?

运行 opencode auth list,查看是否至少连接了一个服务商。

为什么要检查运行的是哪个可执行文件?

技能指出,shell 找到的 OpenCode 程序可能与 Hermes 使用的不是同一个。

详情

作者的原始描述

Delegate coding to OpenCode CLI (features, PR review).

repo: NousResearch/hermes-agent

热度

GitHub 星标
260k
排名
#444
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能