AgentSkillsCN

opencode-cli

与 Opencode CLI 交互,以执行 AI 驱动的编码任务、生成代码片段,并以非交互方式管理代理会话。当用户请求“向 Opencode 提问”或“使用 Opencode”来完成某项任务时,可使用此技能。

SKILL.md
--- frontmatter
name: opencode-cli
description: Interface with the Opencode CLI to execute AI-driven coding tasks, generate code snippets, and manage agent sessions non-interactively. Use this when the user asks to "ask Opencode" or "use Opencode" to perform a task.

Opencode CLI Skill

Goal

This skill allows the agent to utilize the opencode command-line tool to perform coding tasks, query the Opencode agent, and manage configuration. It is specifically optimized for non-interactive usage to prevent the agent from getting stuck in Terminal UI (TUI) modes.

Usage Rules

1. Non-Interactive Execution (CRITICAL)

  • NEVER run the bare command opencode without arguments. This launches an interactive TUI that will hang the agent session.
  • ALWAYS use opencode run "<prompt>" for generation, questions, or coding tasks.
  • ALWAYS use the -p or --prompt flag if run is not applicable in your specific version, but opencode run is the standard for delegation.

2. Output Handling

  • The output from Opencode is standard text. Read the output to confirm the task was completed or to retrieve the generated code.
  • If the user asks for JSON output and the CLI supports it, append --output-format json.

3. Context & Directories

  • If the user specifies a working directory, use the -c or --cwd flag: opencode run "prompt" --cwd /path/to/dir

Command Reference

ActionCommand Pattern
Run Promptopencode run "Your instruction here"
Check Versionopencode --version
List Modelsopencode models
Auth Statusopencode auth list
Set Directoryopencode run "..." --cwd ./subdir

Examples

Example 1: Generative Task

User: "Use opencode to write a Python script that calculates Fibonacci numbers." Agent Execution:

bash
opencode run "Write a Python script that calculates Fibonacci numbers and prints the first 10."