agentleFS
ethosagentethosagent/ethos/skills/autonomous-ai-agents/opencode/SKILL.md

opencode

Skill22 starsChanged 9 days agoMITView on GitHub

Deep-dive reference for delegating implementation work to the OpenCode CLI. Provider-agnostic — pick it when the user wants a specific non-Anthropic, non-OpenAI model (local Ollama, Bedrock, Vertex, Azure). Covers binary resolution, one-shot mode, provider selection, and common pitfalls.

  • Reads credentials
  • Installs packages

34 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use touchdesigner-mcp, minecraft-modpack-server and 8 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • john-data-chenSkill

    touchdesigner-mcp

    Control a running TouchDesigner instance via twozero MCP — create operators, set parameters, wire connections, execute Python, build real-time visuals. 36 native tools.

    Also in 7 projects that use this

  • math-incSkill

    minecraft-modpack-server

    Set up a modded Minecraft server from a CurseForge/Modrinth server pack zip. Covers NeoForge/Forge install, Java version, JVM tuning, firewall, LAN config, backups, and launch scripts.

    Also in 5 projects that use this

  • math-incSkill

    pokemon-player

    Play Pokemon games autonomously via headless emulation. Starts a game server, reads structured game state from RAM, makes strategic decisions, and sends button inputs — all from the terminal.

    Also in 5 projects that use this

  • john-data-chenSkill

    teams-meeting-pipeline

    Operate the Teams meeting summary pipeline via Hermes CLI — summarize meetings, inspect pipeline status, replay jobs, manage Microsoft Graph subscriptions.

    Also in 8 projects that use this

  • Tommy-ywSkill

    songwriting-and-ai-music

    Songwriting craft, AI music generation prompts (Suno focus), parody/adaptation techniques, phonetic tricks, and lessons learned. These are tools and ideas, not rules. Break any of them when the art calls for it.

    Also in 10 projects that use this

  • mae616Skill

    p5js

    p5.js(クリエイティブコーディング)のProcessing由来「コードでスケッチ」思想を軸に、setup/drawループ・座標系・インタラクション・パフォーマンス最適化を整理する。p5.js、Processing、クリエイティブコーディング、ジェネラティブアート、インタラクティブ表現、ビジュアルプログラミング、Canvas描画、パーティクル、フラクタル、ノイズ表現に関する相談で必ず使うこと。ユーザーが「コードでアート」「動くビジュアル」「インタラクティブな描画」と言った場合にも適用する。

    Also in 10 projects that use this

  • +2 more from math-inc

The file

Show its rules and text

We split this skill into the rules it gives an agent

19 rules. 0 are common, 11 are distinctive, and 8 are very specific to this project.

  • 0

    Common

    Most of the 32 edited versions we read keep these.

  • 11

    Distinctive

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Do not use: when Claude Code or Codex would suffice.

    line 38
  2. Distinctive:

    If the command is not found, check common installation locations:

    line 48
  3. Distinctive:

    If none of these resolve, the CLI is not installed.

    line 64
  4. Distinctive:

    After resolving the binary, verify the version:

    line 70
  5. Very specific:

    If that fails, process_stop (SIGTERM).

    line 148
  6. Distinctive:

    If that fails, SIGKILL.

    line 149
  7. Very specific:

    Always use run mode for delegation to avoid this entirely.

    line 151
  8. Distinctive:

    Before delegating real work, verify the CLI and provider are functional:

    line 155
  9. Distinctive:

    Check that the provider is reachable (network, auth).

    line 163
  10. Distinctive:

    Check that the model exists on the provider.

    line 164
  11. Very specific:

    Check opencode --version for a supported version.

    line 165
  12. Distinctive:

    Run the smoke test once per session, not per delegation.

    line 167
  13. Very specific:

    When available (version-dependent), use --format json for structured output:

    line 171
  14. Very specific:

    Not all OpenCode versions support --format json.

    line 189
  15. Very specific:

    Always attempt JSON first and fall back gracefully.

    line 198
  16. Very specific:

    If --cwd is not supported by the installed version, set the working directory via process_start's cwd parameter instead.

    line 208
  17. Distinctive:

    Before spawning an OpenCode delegation, verify:

    line 247
  18. Distinctive:

    Use this table to choose the right CLI for the task.

    line 268
  19. Very specific:

    Fall back gracefully on --format json: Not all versions support it — parse plain text as a fallback.

    line 276

“Common” is measured: kept by at least 6 in 10 of the 32 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

OpenCode — Deep-Dive Delegation Reference

Comprehensive reference for spawning and managing the OpenCode CLI (opencode) as a delegated coding agent under ethos process control. OpenCode is provider-agnostic — it connects to any LLM backend (Ollama, AWS Bedrock, Google Vertex, Azure OpenAI, OpenRouter, and more).

When to use

  • Provider-agnostic delegation — the user wants a specific model that neither Claude Code nor Codex exposes (local Ollama, a Bedrock-hosted model, an enterprise Azure deployment, a Google Vertex model).
  • Cost-controlled environments — where the choice of provider matters for billing, data residency, or compliance reasons.
  • Local models — when the user wants to run a local LLM (via Ollama) for privacy or offline work.
  • Multi-provider comparison — delegate the same task to multiple providers via OpenCode and compare results.

Do not use when Claude Code or Codex would suffice. Those CLIs have tighter integration with their respective APIs and less surface area for configuration errors. OpenCode's strength is flexibility, not depth — use it when flexibility is what you need.

Binary resolution and PATH caveat

OpenCode may not be in $PATH depending on how it was installed. Always verify before delegating:

which opencode || command -v opencode

If the command is not found, check common installation locations:

# npm global install
ls ~/.local/bin/opencode 2>/dev/null

# npm local install (project-local)
ls ./node_modules/.bin/opencode 2>/dev/null

# Go install
ls ~/go/bin/opencode 2>/dev/null

# Homebrew
ls /opt/homebrew/bin/opencode 2>/dev/null

If none of these resolve, the CLI is not installed. Print the install instructions:

OpenCode is not installed. Install with npm i -g opencode-ai (or see https://opencode.ai for alternative install methods) and authenticate with opencode login.

Version check

After resolving the binary, verify the version:

opencode --version

Some features (like --format json) are version-dependent. Document the minimum version you tested against when adding new invocation patterns.

One-shot invocation — the core pattern

opencode run "<task description>"

run mode executes the task and exits. This is the canonical pattern for delegation from process_start. Do not use interactive mode — it opens a TUI that cannot be driven programmatically.

Minimal delegation

process_start({
  command: 'opencode run "Add error handling to the database connection pool in src/db/pool.ts"',
  name: 'delegated-opencode-db-error-handling',
  cwd: '/path/to/project'
})

With provider and model

process_start({
  command: 'opencode run "Refactor the auth middleware to support JWT rotation" --model ollama/llama3',
  name: 'delegated-opencode-auth-refactor',
  cwd: '/path/to/project'
})

Provider and model selection

OpenCode's key differentiator is provider flexibility. The --model flag uses a provider/model syntax:

Provider examples

ProviderSyntaxAuth required
Ollama (local)--model ollama/llama3None (local)
AWS Bedrock--model bedrock/anthropic.claude-v2AWS credentials
Google Vertex--model vertex/gemini-proGCP credentials
Azure OpenAI--model azure/gpt-4Azure credentials
OpenRouter--model openrouter/anthropic/claude-3.5-sonnetOPENROUTER_API_KEY
Together--model together/meta-llama/Llama-3-70bTOGETHER_API_KEY

Provider selection guidelines

  • Local/private: Ollama — no data leaves the machine. Best for sensitive codebases or offline work.
  • Enterprise AWS: Bedrock — uses existing AWS IAM roles. Best for teams already on AWS.
  • Enterprise GCP: Vertex — uses existing GCP service accounts. Best for teams already on GCP.
  • Enterprise Azure: Azure OpenAI — uses existing Azure AD. Best for teams on Azure.
  • Cost optimization: OpenRouter or Together — access many models with a single API key, often at lower cost.

Authentication per provider

Each provider has its own auth flow. Run opencode login and follow the interactive setup, or set the provider-specific environment variable before spawning:

# Ollama — no auth needed (local)
# Bedrock — standard AWS credential chain (AWS_PROFILE, AWS_ACCESS_KEY_ID, etc.)
# Vertex — standard GCP credential chain (GOOGLE_APPLICATION_CREDENTIALS, gcloud auth)
# Azure — standard Azure credential chain (AZURE_OPENAI_API_KEY, az login)
# OpenRouter — OPENROUTER_API_KEY

The /exit trap

In interactive mode (the TUI), /exit is the only way to quit cleanly. Ctrl+C may leave the process dangling with orphaned child processes.

This does not apply to run mode — one-shot invocations exit cleanly on their own. But if someone accidentally spawns OpenCode in interactive mode (by omitting run), the only reliable cleanup is:

  1. Send /exit via the PTY.
  2. If that fails, process_stop (SIGTERM).
  3. If that fails, SIGKILL.

Always use run mode for delegation to avoid this entirely.

Smoke test

Before delegating real work, verify the CLI and provider are functional:

opencode run "echo hello"

This should produce a response within a few seconds. If it hangs, errors, or produces no output:

  1. Check that the provider is reachable (network, auth).
  2. Check that the model exists on the provider.
  3. Check opencode --version for a supported version.

Run the smoke test once per session, not per delegation.

Structured output with --format json

When available (version-dependent), use --format json for structured output:

opencode run "<task>" --format json

Expected JSON shape (when supported):

{
  "result": "The response text — what was done.",
  "model": "ollama/llama3",
  "duration_ms": 12400
}

Fallback for plain text

Not all OpenCode versions support --format json. The fallback parsing strategy:

1. Check if --format json is supported: opencode run "test" --format json 2>&1
2. If it errors with "unknown flag", fall back to plain text mode.
3. In plain text mode, capture raw stdout as the result.
4. Use the exit code as the success/failure indicator.

Always attempt JSON first and fall back gracefully. Do not hard-fail on a missing --format flag.

Working directory

Set the project root explicitly with --cwd:

opencode run "<task>" --cwd /absolute/path/to/project

If --cwd is not supported by the installed version, set the working directory via process_start's cwd parameter instead. Both achieve the same result — process_start.cwd is the more reliable option since it works regardless of OpenCode version.

Session continuation

Resume the last session for the current directory:

opencode run "<follow-up task>" --continue

--continue carries over the conversation history from the previous invocation in the same directory. Use it for multi-step delegations where context should accumulate (e.g., "now add tests for what you just changed").

Caveat: session continuation is directory-scoped. If you use worktrees, each worktree has its own session history. This is usually the desired behavior — parallel delegations in different worktrees should not share context.

Error recovery

Common failures

SymptomCauseRecovery
"command not found"Binary not in PATHCheck install locations (see Binary Resolution above)
Connection refused (Ollama)Ollama server not runningStart it: ollama serve
Auth error (cloud providers)Credentials expired or missingRe-authenticate: opencode login or set the provider env var
Model not foundModel name typo or model not pulledFor Ollama: ollama pull <model>. For cloud: verify model ID in provider docs
TimeoutModel too slow or network issueRetry; for Ollama, check that the model fits in available RAM
Garbled outputEncoding issue with local modelTry a different model; some local models produce malformed output

Recovery pattern

1. Capture exit code and stderr from process_logs.
2. Match stderr against known failure patterns.
3. For transient errors (timeout, rate limit): retry up to 2 times with a 30-second backoff.
4. For permanent errors (auth, model not found): surface to the user with specific remediation.
5. For local model issues (Ollama): check RAM, model compatibility, and suggest alternatives.

Delegation checklist

Before spawning an OpenCode delegation, verify:

  1. which opencode succeeds — the CLI is installed.
  2. Smoke test passes — opencode run "echo hello" produces output.
  3. The target provider is reachable and authenticated.
  4. The target model exists on the provider.
  5. --cwd or process_start.cwd points to the correct project root.
  6. A process_start name is chosen (descriptive slug).
  7. The user has authorized the delegation.

Comparison with other CLIs

DimensionClaude CodeCodexOpenCode
ProviderAnthropic onlyOpenAI onlyAny
Structured output--output-format json (rich)None (plain text)--format json (if supported)
Tool scoping--allowedToolsNoneNone
Git requirementNoYesNo
PTY requirementNoYesNo
Best forDeep reasoning, large refactorsFast iteration, batch opsProvider flexibility, local models

Use this table to choose the right CLI for the task. OpenCode is the fallback when the other two do not support the required provider or model.

Hard rules

  • Always use run mode. Interactive TUI mode cannot be driven from process_start.
  • Always smoke-test first. Provider misconfigurations fail silently or with opaque errors.
  • Always verify the binary is in PATH. OpenCode installs vary — do not assume it is available.
  • Never delegate without the process tool. Without process_start, the orchestrator blocks for the full duration and the user cannot kill the delegation.
  • Fall back gracefully on --format json. Not all versions support it — parse plain text as a fallback.

Adapted from NousResearch/hermes-agent (MIT)

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.