New to Claude Skills? Learn how to install them →

nousresearch on GitHub

OpenCode CLI

Free

Autonomous coding with OpenCode and Hermes tools.

Get this skill

Free · Opens the source repo

What OpenCode CLI does

OpenCode CLI serves as an autonomous coding assistant that integrates seamlessly with the Hermes terminal and process tools. This open-source AI coding agent is designed to facilitate various coding tasks through both a terminal user interface (TUI) and command-line interface (CLI). It allows users to delegate coding responsibilities such as implementation, refactoring, and code reviews, making it a valuable tool for developers seeking to enhance their productivity.

The skill is particularly useful for long-running coding sessions where users can check progress and manage tasks in parallel. By utilizing isolated work directories or worktrees, developers can avoid code collisions and maintain organized workflows. OpenCode CLI supports both one-shot tasks and interactive sessions, enabling users to choose the most efficient method for their coding needs. With commands to run specific tasks or to engage in iterative dialogues, it provides flexibility in how coding challenges are approached.

To get started, users need to have OpenCode installed and properly configured, including authentication with their chosen provider. The skill supports a variety of commands for executing tasks, monitoring progress, and managing sessions, ensuring that developers have the tools they need to work effectively. The ability to attach context files and specify models further enhances its usability, allowing for tailored coding solutions.

Overall, OpenCode CLI is designed for developers who want to leverage AI to streamline their coding processes, whether they are working on individual tasks or managing complex projects. Its integration with Hermes tools makes it a robust choice for those looking to enhance their coding efficiency and effectiveness.

When to use it

Use OpenCode CLI when you need an external agent for coding tasks, especially for long-running sessions or parallel work.

When not to use it

This skill may not be suitable for simple coding tasks that can be handled quickly without automation or for environments where OpenCode is not installed or configured properly.

What you can build with it

Implementing New Features

Use OpenCode CLI to autonomously implement new features in your project, allowing you to focus on design and architecture.

Code Review Automation

Leverage OpenCode CLI to automate code reviews, identifying bugs and security risks in pull requests.

Parallel Development Tasks

Run multiple coding tasks in isolated directories with OpenCode, improving efficiency and reducing code conflicts.

How to install OpenCode CLI

View source

1. Install with the skills CLI

npx skills add nousresearch/hermes-agent/opencode --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by nousresearch

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

KeyAction
EnterSubmit message (press twice if needed)
TabSwitch between agents (build/plan)
Ctrl+POpen command palette
Ctrl+X LSwitch session
Ctrl+X MSwitch model
Ctrl+X NNew session
Ctrl+X EOpen editor
Ctrl+CExit 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

FlagUse
run 'prompt'One-shot execution and exit
--continue / -cContinue the last OpenCode session
--session <id> / -sContinue a specific session
--agent <name>Choose OpenCode agent (build or plan)
--model provider/modelForce specific model
--format jsonMachine-readable output/events
--file <path> / -fAttach file(s) to the message
--thinkingShow 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 process(action="kill").
  7. Summarize file changes, test results, and next steps back to user.

PR Review Workflow

OpenCode has a built-in PR command:

terminal(command="opencode pr 42", workdir="~/project", pty=true)

Or review in a temporary clone for isolation:

terminal(command="REVIEW=$(mktemp -d) && git clone https://github.com/user/repo.git $REVIEW && cd $REVIEW && opencode run 'Review this PR vs main. Report bugs, security risks, test gaps, and style issues.' -f $(git diff origin/main --name-only | head -20 | tr '\n' ' ')", pty=true)

Parallel Work Pattern

Use separate workdirs/worktrees to avoid collisions:

terminal(command="opencode run 'Fix issue #101 and commit'", workdir="/tmp/issue-101", background=true, pty=true)
terminal(command="opencode run 'Add parser regression tests and commit'", workdir="/tmp/issue-102", background=true, pty=true)
process(action="list")

Session & Cost Management

List past sessions:

terminal(command="opencode session list")

Check token usage and costs:

terminal(command="opencode stats")
terminal(command="opencode stats --days 7 --models anthropic/claude-sonnet-4")

Pitfalls

  • Interactive opencode (TUI) sessions require pty=true. The opencode run command does NOT need pty.
  • /exit is NOT a valid command — it opens an agent selector. Use Ctrl+C to exit the TUI.
  • PATH mismatch can select the wrong OpenCode binary/model config.
  • If OpenCode appears stuck, inspect logs before killing:
    • process(action="log", session_id="<id>")
  • Avoid sharing one working directory across parallel OpenCode sessions.
  • Enter may need to be pressed twice to submit in the TUI (once to finalize text, once to send).

Verification

Smoke test:

terminal(command="opencode run 'Respond with exactly: OPENCODE_SMOKE_OK'")

Success criteria:

  • Output includes OPENCODE_SMOKE_OK
  • Command exits without provider/model errors
  • For code tasks: expected files changed and tests pass

Rules

  1. Prefer opencode run for one-shot automation — it's simpler and doesn't need pty.
  2. Use interactive background mode only when iteration is needed.
  3. Always scope OpenCode sessions to a single repo/workdir.
  4. For long tasks, provide progress updates from process logs.
  5. Report concrete outcomes (files changed, tests, remaining risks).
  6. Exit interactive sessions with Ctrl+C or kill, never /exit.

Frequently asked questions about OpenCode CLI

Similar skills