{"success":true,"name":"opencode","description":"Delegate coding to OpenCode CLI (features, PR review).","category":"autonomous-ai-agents","path":"autonomous-ai-agents/opencode/SKILL.md","file":"SKILL.md","content":"---\nname: opencode\ndescription: \"Delegate coding to OpenCode CLI (features, PR review).\"\nversion: 1.2.0\nauthor: Hermes Agent\nlicense: MIT\nplatforms: [linux, macos, windows]\nmetadata:\n  hermes:\n    tags: [Coding-Agent, OpenCode, Autonomous, Refactoring, Code-Review]\n    related_skills: [claude-code, codex, hermes-agent]\n---\n\n# OpenCode CLI\n\nUse [OpenCode](https://opencode.ai) 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.\n\n## When to Use\n\n- User explicitly asks to use OpenCode\n- You want an external coding agent to implement/refactor/review code\n- You need long-running coding sessions with progress checks\n- You want parallel task execution in isolated workdirs/worktrees\n\n## Prerequisites\n\n- OpenCode installed: `npm i -g opencode-ai@latest` or `brew install anomalyco/tap/opencode`\n- Auth configured: `opencode auth login` or set provider env vars (OPENROUTER_API_KEY, etc.)\n- Verify: `opencode auth list` should show at least one provider\n- Git repository for code tasks (recommended)\n- `pty=true` for interactive TUI sessions\n\n## Binary Resolution (Important)\n\nShell environments may resolve different OpenCode binaries. If behavior differs between your terminal and Hermes, check:\n\n```\nterminal(command=\"which -a opencode\")\nterminal(command=\"opencode --version\")\n```\n\nIf needed, pin an explicit binary path:\n\n```\nterminal(command=\"$HOME/.opencode/bin/opencode run '...'\", workdir=\"~/project\", pty=true)\n```\n\n## One-Shot Tasks\n\nUse `opencode run` for bounded, non-interactive tasks:\n\n```\nterminal(command=\"opencode run 'Add retry logic to API calls and update tests'\", workdir=\"~/project\")\n```\n\nAttach context files with `-f`:\n\n```\nterminal(command=\"opencode run 'Review this config for security issues' -f config.yaml -f .env.example\", workdir=\"~/project\")\n```\n\nShow model thinking with `--thinking`:\n\n```\nterminal(command=\"opencode run 'Debug why tests fail in CI' --thinking\", workdir=\"~/project\")\n```\n\nForce a specific model:\n\n```\nterminal(command=\"opencode run 'Refactor auth module' --model openrouter/anthropic/claude-sonnet-4\", workdir=\"~/project\")\n```\n\n## Interactive Sessions (Background)\n\nFor iterative work requiring multiple exchanges, start the TUI in background:\n\n```\nterminal(command=\"opencode\", workdir=\"~/project\", background=true, pty=true)\n# Returns session_id\n\n# Send a prompt\nprocess(action=\"submit\", session_id=\"<id>\", data=\"Implement OAuth refresh flow and add tests\")\n\n# Monitor progress\nprocess(action=\"poll\", session_id=\"<id>\")\nprocess(action=\"log\", session_id=\"<id>\")\n\n# Send follow-up input\nprocess(action=\"submit\", session_id=\"<id>\", data=\"Now add error handling for token expiry\")\n\n# Exit cleanly — Ctrl+C\nprocess(action=\"write\", session_id=\"<id>\", data=\"\\x03\")\n# Or just kill the process\nprocess(action=\"kill\", session_id=\"<id>\")\n```\n\n**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.\n\n### TUI Keybindings\n\n| Key | Action |\n|-----|--------|\n| `Enter` | Submit message (press twice if needed) |\n| `Tab` | Switch between agents (build/plan) |\n| `Ctrl+P` | Open command palette |\n| `Ctrl+X L` | Switch session |\n| `Ctrl+X M` | Switch model |\n| `Ctrl+X N` | New session |\n| `Ctrl+X E` | Open editor |\n| `Ctrl+C` | Exit OpenCode |\n\n### Resuming Sessions\n\nAfter exiting, OpenCode prints a session ID. Resume with:\n\n```\nterminal(command=\"opencode -c\", workdir=\"~/project\", background=true, pty=true)  # Continue last session\nterminal(command=\"opencode -s ses_abc123\", workdir=\"~/project\", background=true, pty=true)  # Specific session\n```\n\n## Common Flags\n\n| Flag | Use |\n|------|-----|\n| `run 'prompt'` | One-shot execution and exit |\n| `--continue` / `-c` | Continue the last OpenCode session |\n| `--session <id>` / `-s` | Continue a specific session |\n| `--agent <name>` | Choose OpenCode agent (build or plan) |\n| `--model provider/model` | Force specific model |\n| `--format json` | Machine-readable output/events |\n| `--file <path>` / `-f` | Attach file(s) to the message |\n| `--thinking` | Show model thinking blocks |\n| `--variant <level>` | Reasoning effort (high, max, minimal) |\n| `--title <name>` | Name the session |\n| `--attach <url>` | Connect to a running opencode server |\n\n## Procedure\n\n1. Verify tool readiness:\n   - `terminal(command=\"opencode --version\")`\n   - `terminal(command=\"opencode auth list\")`\n2. For bounded tasks, use `opencode run '...'` (no pty needed).\n3. For iterative tasks, start `opencode` with `background=true, pty=true`.\n4. Monitor long tasks with `process(action=\"poll\"|\"log\")`.\n5. If OpenCode asks for input, respond via `process(action=\"submit\", ...)`.\n6. Exit with `process(action=\"write\", data=\"\\x03\")` or `process(action=\"kill\")`.\n7. Summarize file changes, test results, and next steps back to user.\n\n## PR Review Workflow\n\nOpenCode has a built-in PR command:\n\n```\nterminal(command=\"opencode pr 42\", workdir=\"~/project\", pty=true)\n```\n\nOr review in a temporary clone for isolation:\n\n```\nterminal(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)\n```\n\n## Parallel Work Pattern\n\nUse separate workdirs/worktrees to avoid collisions:\n\n```\nterminal(command=\"opencode run 'Fix issue #101 and commit'\", workdir=\"~/.hermes/cache/scratch/issue-101\", background=true, pty=true)\nterminal(command=\"opencode run 'Add parser regression tests and commit'\", workdir=\"~/.hermes/cache/scratch/issue-102\", background=true, pty=true)\nprocess(action=\"list\")\n```\n\n## Session & Cost Management\n\nList past sessions:\n\n```\nterminal(command=\"opencode session list\")\n```\n\nCheck token usage and costs:\n\n```\nterminal(command=\"opencode stats\")\nterminal(command=\"opencode stats --days 7 --models anthropic/claude-sonnet-4\")\n```\n\n## Pitfalls\n\n- Interactive `opencode` (TUI) sessions require `pty=true`. The `opencode run` command does NOT need pty.\n- `/exit` is NOT a valid command — it opens an agent selector. Use Ctrl+C to exit the TUI.\n- PATH mismatch can select the wrong OpenCode binary/model config.\n- If OpenCode appears stuck, inspect logs before killing:\n  - `process(action=\"log\", session_id=\"<id>\")`\n- Avoid sharing one working directory across parallel OpenCode sessions.\n- Enter may need to be pressed twice to submit in the TUI (once to finalize text, once to send).\n\n## Verification\n\nSmoke test:\n\n```\nterminal(command=\"opencode run 'Respond with exactly: OPENCODE_SMOKE_OK'\")\n```\n\nSuccess criteria:\n- Output includes `OPENCODE_SMOKE_OK`\n- Command exits without provider/model errors\n- For code tasks: expected files changed and tests pass\n\n## Rules\n\n1. Prefer `opencode run` for one-shot automation — it's simpler and doesn't need pty.\n2. Use interactive background mode only when iteration is needed.\n3. Always scope OpenCode sessions to a single repo/workdir.\n4. For long tasks, provide progress updates from `process` logs.\n5. Report concrete outcomes (files changed, tests, remaining risks).\n6. Exit interactive sessions with Ctrl+C or kill, never `/exit`.\n","linked_files":[],"origin":"brimind","owner_id":null,"source":"router"}