AgentSkillsCN

opencode-agent

启动并管理完全配置的opencode CLI会话。当用户希望在本地或远程机器上启动opencode,从Git仓库中导入技能以初始化环境,配置CLI认证与Vault密钥,或编排opencode代理时使用此功能。当用户提及opencode-agent、启动代理、远程opencode,或进行多机编排时,此功能也会自动触发。

SKILL.md
--- frontmatter
name: opencode-agent
description: Spawn and manage fully-configured opencode CLI sessions. Use when the user wants to launch opencode on a local or remote machine, bootstrap environments with skills from a git repo, set up config-cli auth and vault secrets, or orchestrate opencode agents. Also triggers when the user mentions opencode-agent, spawning agents, remote opencode, or multi-machine orchestration.

opencode-agent

Two scripts, two concerns:

ScriptPurposeWhen to run
setup.shEnvironment prep — sync skills, config-cli auth, vault secrets, install/update opencodeOnce per machine/project, or when environment changes
opencode-agent.shLaunch opencode for a task — lightweight, no network calls, no updatesEvery task invocation

Always run setup.sh first, then use opencode-agent.sh for all interactions.

Execution Method Priority

PriorityMethodWhen to use
1. SSH directssh host "cd /project && bash .../opencode-agent.sh ..."SSH available, simple/single-turn tasks, good network
2. tmux-ttytmux-wrapper.sh + opencode-agent.shNo reliable SSH, need TTY, multi-turn interaction, or poor network (tmux survives disconnects)

SSH is preferred for straightforward invocations — no tmux overhead, direct stdout capture. Fall back to tmux for persistent sessions, TTY interaction, or network resilience.

CLI vs TUI Mode

opencode-agent.sh defaults to CLI mode (opencode run):

  • New session (no -s): uses --format json automatically to capture the session ID, prints [opencode-agent] session=<id>
  • Continue session (with -s <id>): runs opencode run normally — no --format json

Use --tui only when the user explicitly requests interactive exploration.

ScenarioWhat happens
New sessionopencode run --format json → JSON output + session ID
Continue sessionopencode run -s <id> → normal output
TUIopencode --tui → interactive terminal UI

Best Practice: Use /opendog Slash Command

Prefer /opendog [task] over raw prompts whenever the project has opendog skills installed (.opencode/commands/opendog.md exists). The /opendog command provides structured triage, tool preference enforcement, memory management, and sub-agent delegation.

Prompt styleWhen to use
/opendog implement the login featureDefault — project has opendog skills
"implement the login feature"Fallback — project lacks opendog skills, or task needs no orchestration

Best Practice: Session Tracking with -s

ALWAYS use -s <session-id> for session continuity. Never rely on -c — it is ambiguous with parallel agents.

The session ID is captured on the first run only:

code
1st run:  opencode-agent.sh "/opendog build the auth module"
          → JSON output (--format json, automatic)
          → [opencode-agent] session=ses_abc123

2nd run:  opencode-agent.sh -s ses_abc123 "/opendog add rate limiting"
          → normal output

3rd run:  opencode-agent.sh -s ses_abc123 "/opendog write tests"
          → normal output

Extract session ID from captured output:

bash
grep -o 'session=ses_[^ ]*' <<< "$CAPTURED_OUTPUT" | tail -1 | cut -d= -f2

Workflow (CLI Mode — Recommended)

1. Setup (once)

bash
bash <skill-path>/scripts/setup.sh \
  --repo https://github.com/VincentHanxiaoDu/opendog \
  --config-cli-endpoint "https://..."

2. First task (new session)

bash
bash <skill-path>/scripts/opencode-agent.sh "/opendog implement the login feature"
# → [opencode-agent] session=ses_abc123

3. Continue the session

bash
bash <skill-path>/scripts/opencode-agent.sh -s ses_abc123 "/opendog add unit tests"

Via tmux (when TTY needed)

bash
<tmux-skill-path>/tmux-wrapper.sh start oc bash
<tmux-skill-path>/tmux-wrapper.sh send oc 'cd /path/to/project' Enter

# Setup (once)
<tmux-skill-path>/tmux-wrapper.sh send oc 'bash <skill-path>/scripts/setup.sh \
  --repo https://github.com/VincentHanxiaoDu/opendog' Enter

# First task
<tmux-skill-path>/tmux-wrapper.sh send oc 'bash <skill-path>/scripts/opencode-agent.sh \
  "/opendog implement the login feature"' Enter

# Capture session ID
sleep 30
OUTPUT=$(<tmux-skill-path>/tmux-wrapper.sh capture oc)
SID=$(echo "$OUTPUT" | grep -o 'session=ses_[^ ]*' | tail -1 | cut -d= -f2)

# Continue
<tmux-skill-path>/tmux-wrapper.sh send oc "bash <skill-path>/scripts/opencode-agent.sh \
  -s $SID \"/opendog add unit tests\"" Enter

# Cleanup
<tmux-skill-path>/tmux-wrapper.sh stop oc

Workflow (TUI Mode)

Launch

bash
bash <skill-path>/scripts/setup.sh --repo https://github.com/VincentHanxiaoDu/opendog
bash <skill-path>/scripts/opencode-agent.sh --tui

Interact

bash
<tmux-skill-path>/tmux-wrapper.sh send oc '/opendog implement the login feature' Enter
sleep 0.5
<tmux-skill-path>/tmux-wrapper.sh send oc Enter

Quit TUI

Send C-c — the process terminates and tmux session auto-destroys:

bash
<tmux-skill-path>/tmux-wrapper.sh send oc C-c

If the session lingers, force-kill:

bash
<tmux-skill-path>/tmux-wrapper.sh stop oc

Authenticate (if needed)

Exit TUI first (C-c), then:

bash
<tmux-skill-path>/tmux-wrapper.sh send oc 'opencode auth login' Enter
sleep 2
<tmux-skill-path>/tmux-wrapper.sh capture oc

Script Arguments

setup.sh

bash
bash <skill-path>/scripts/setup.sh [options]
FlagArgPurpose
--repo<url>Git repo with .opencode/skills/ (required first run)
--repo-branch<branch>Branch to use (default: main)
--config-cli-endpoint<url>config-cli login endpoint
--config-cli-token<token>config-cli token (alternative to endpoint)
--graphiti-group-id<id>Override GRAPHITI_GROUP_ID (default: opendog)
--graphiti-model<model>Override MODEL_NAME for graphiti

opencode-agent.sh

bash
bash <skill-path>/scripts/opencode-agent.sh [options] [prompt...]
FlagArgPurpose
-s, --session<id>Continue specific session (preferred)
-c, --continue-Continue the last session (unsafe with parallel agents)
--tui-Launch interactive TUI
--log-level<level>Log level (default: DEBUG)

All unrecognized flags pass through to opencode.

Environment Variables

setup.sh injects these from config-cli vault:

VariableSourceNotes
AZURE_OPENAI_API_KEYconfig-cli vaultRequired for graphiti
AZURE_OPENAI_ENDPOINTconfig-cli vaultAzure OpenAI endpoint
AZURE_OPENAI_DEPLOYMENTvault or --graphiti-modelLLM deployment name
NEO4J_PASSWORDconfig-cli vaultOptional, for Neo4j
GRAPHITI_GROUP_ID--graphiti-group-id or defaultDefault: opendog

Prerequisites

  • git — for cloning the skills repo
  • tmux — for TTY session management (via tmux-tty skill)
  • brew — for installing/updating opencode (macOS)
  • rsync — for incremental skills merge

Pitfalls

  • Run setup.sh before opencode-agent.sh — the agent script assumes opencode is installed and env is ready
  • Always use -s <id>, never -c for automation-c picks "last session" globally, breaks with parallel agents
  • Prefer CLI mode for automation — structured output, no TUI artifacts
  • Always sleep after send before capture — let commands initialize
  • Always stop tmux sessions when done — prevents orphaned sockets
  • Secrets go through config-cli — never pass secrets as plain arguments
  • TUI exit — send C-c; do NOT use /exit (triggers slash-command palette fuzzy match)
  • TUI prompt submission — text typed via send lands in input field; needs an extra Enter to submit