Opencode Runner 标志

Opencode Runner

社区
luongnv89
opencode-runner

Run coding tasks via opencode using free cloud models. Use when asked to offload work to opencode.ai or run a free model. Don't use for local models (Ollama, LM Studio), Claude/OpenAI calls, or when Claude should do the work itself.

概览

发布者luongnv89
代码仓库skills
技能名称opencode-runner
星标数
124
复刻数
18
附带文件
2
许可协议MIT
链接
  • Markdown 格式的指令

    模型按需加载 SKILL.md 文件,因此只有在请求确实与该技能匹配时才会消耗 Token。

  • 兼容任何大语言模型

    AI 技能采用纯 Markdown,而非特定提供商的代码,因此可搭配 GPT、Claude、Gemini、Grok 或本地模型使用。

  • 2 个附带文件

    模型执行任务时可读取的脚本、模板和参考资料。这些文件为只读文件,绝不会被执行。

  • 开源

    由 luongnv89 发布于 GitHub。请在安装前查看技能的源文件。

安装

在 TypingMind 中安装 Opencode Runner AI 技能,即可搭配任意大语言模型使用;也可以将其放入其他支持读取 SKILL.md 的智能体中。

1

安装到 TypingMind

TypingMind 可直接从 GitHub 文件夹安装技能:读取 SKILL.md,打包资源文件,并将结果保存在本地。

  1. 打开应用,前往“插件 → 技能”。
  2. 选择“从 GitHub 安装”。
  3. 粘贴下方的技能文件夹 URL 并确认。
    https://github.com/luongnv89/skills/tree/main/skills/opencode-runner
  4. 请在每个需要使用该技能的聊天中启用它。
依次选择“插件 → 技能 → 添加技能 → 从 GitHub URL 导入”,然后粘贴文件夹 URL 并点击“继续”。
2

安装到其他智能体

任何支持 Agent Skills 格式的智能体都可以使用此技能,只需将文件夹复制到该智能体的技能目录中。

Claude Code — .claude/skills
git clone --depth 1 https://github.com/luongnv89/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/skills/opencode-runner .claude/skills/opencode-runner
复制后,请重启 Claude Code,以加载新技能。

在 TypingMind 中使用此技能

在任意 TypingMind 聊天中启用 Opencode Runner,后续即可交由模型处理。技能的名称和描述会放在系统提示词中,一旦请求匹配,模型就会自动加载完整指令,无需您手动调用,且在实际使用前不会消耗 Token。

一旦请求与技能匹配,模型就会自动加载 Opencode Runner。

兼容任何 AI 模型

AI 技能是纯 Markdown 指令,而非特定提供商的代码,因此 Opencode Runner 不局限于最初适配的模型。只需在 TypingMind 中安装一次,即可搭配 GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 或您自行运行的本地模型使用,全程使用您自己的 API 密钥。

  • 仅在需要时加载

    系统提示词中仅包含技能名称和描述。首次遇到匹配的请求时才会加载完整指令,因此技能未使用时,这些指令不会消耗 Token。

  • 在聊天中切换模型

    技能是指令而非代码,因此切换模型不会导致技能失效,新模型会读取同一个 SKILL.md。

技能指令

这是模型会加载的 SKILL.md 内容。请在安装前阅读,因为技能就是模型将遵循的指令。

OpenCode Runner

Delegate coding tasks to opencode using free models — zero cost, fully automated.

OpenCode (opencode.ai) is a terminal AI coding assistant that supports multiple providers and models. This skill automates the process of selecting the best available free model, launching the task, and reporting progress back to you.

Prerequisites

  • opencode installed: which opencode must succeed; install via npm i -g opencode-ai@latest or brew install opencode if missing
  • Internet access: required for cloud model selection and task execution via OpenCode Zen
  • Project context: the current working directory should be the project root for file-context tasks

Critical Rules

  1. Never do the task yourself. This skill exists solely to delegate work to opencode. If opencode is not installed, fails to run, or no free cloud model is available — report the problem to the user and stop. Do not fall back to editing files directly, writing code yourself, or using any other tool to accomplish the user's coding task. The whole point is that opencode does the work.

  2. Only select cloud models. Never select local models (e.g., ollama/*, lmstudio/*, or any model running on localhost). Only select models from the opencode/* provider namespace, which are cloud-hosted on OpenCode Zen. Local models have unpredictable availability, performance, and may not support the tool-use capabilities opencode needs.

  3. Always clean up after yourself. opencode spawns background processes (LSP servers, MCP servers, node workers) that persist after the task finishes. Every execution path — success, failure, error, timeout — must end with the cleanup steps in Phase 6. Orphaned opencode processes silently eat CPU and memory, and users won't notice until their machine slows to a crawl.

Repo Sync Before Edits (mandatory)

Before creating/updating/deleting files in an existing repository, sync the current branch with remote:

bash
branch="$(git rev-parse --abbrev-ref HEAD)"
git fetch origin
git pull --rebase origin "$branch"

If the working tree is not clean, stash first, sync, then restore:

bash
git stash push -u -m "pre-sync"
branch="$(git rev-parse --abbrev-ref HEAD)"
git fetch origin && git pull --rebase origin "$branch"
git stash pop

If origin is missing or conflicts occur, stop and ask the user before continuing.

Phase 1: Verify Installation

Check that opencode is installed and at the latest version.

Step 1: Check if installed

bash
which opencode && opencode --version

If opencode is not found, tell the user:

opencode is not installed. Install it with one of these commands:

bash
curl -fsSL https://opencode.ai/install | bash

or

bash
npm i -g opencode-ai@latest

or (macOS)

bash
brew install opencode

Then stop completely — do not proceed to any other phase, do not attempt the task yourself, do not edit any files. Wait for the user to install opencode and re-invoke this skill.

Step 2: Check for updates

bash
opencode upgrade

This will upgrade to the latest version if one is available, or confirm already up to date. If the upgrade fails, inform the user of the error and suggest running the command manually. If the upgrade itself breaks opencode, stop and report — do not continue.

Phase 2: Discover Free Models & Let User Pick

Query the available models, present the free ones to the user, and let them choose. If the user doesn't choose, fall back to the priority order.

bash
opencode models 2>/dev/null

Free model priority list (default order if user defers)

PriorityModel IDNotes
1opencode/deepseek-v4-flash-freeStrong recent free coding model — preferred default
2opencode/minimax-m2.5-freeMiniMax free tier — good general-purpose
3opencode/nemotron-3-super-freeNVIDIA Nemotron free tier
4opencode/big-pickleFree fallback
5opencode/gpt-5-nanoSmall, low-cost fallback (verify pricing)

Model IDs evolve. When parsing opencode models output, treat any opencode/* model whose ID ends in -free (or is explicitly priced $0) as free-tier eligible. Match by suffix, not by exact ID.

Selection logic

  1. Run opencode models and collect all entries.

  2. Filter out all non-opencode/* models — ignore anything from ollama/*, lmstudio/*, nvidia/*, or any other namespace. Only cloud-hosted opencode/* models qualify.

  3. Among the remaining list, identify the free candidates (suffix -free or known-free IDs from the priority list).

  4. Present the free models to the user as numbered options, in priority order, with priority 1 marked as the default. Use the <options> format if possible. Example:

    I found these free cloud models available via opencode. Pick one, or accept the default.

    1. opencode/deepseek-v4-flash-free (default — priority 1)
    2. opencode/minimax-m2.5-free
    3. opencode/nemotron-3-super-free
    4. opencode/big-pickle
  5. If the user names a model, use that one. If the user says "default", "you pick", "any", or doesn't specify, use priority 1 (the highest-priority available free model).

  6. If no free cloud models exist at all, inform the user and stop — do not fall back to local models, paid models, or doing the task yourself.

Privacy note (always show this with the model list): Free models on OpenCode Zen may use collected data for model improvement.

Phase 3: Confirm Before Executing

Before invoking opencode, show the user a one-screen summary and get explicit confirmation. This catches wrong-model or wrong-prompt mistakes before any tokens are burned.

Present this block:

Ready to delegate to opencode

  • Model: opencode/deepseek-v4-flash-free (free tier)
  • Working directory: /Users/.../current-project
  • Context files: path/to/foo.py, path/to/bar.py (or "none")
  • Prompt: (quote the prompt verbatim, multi-line OK)
  • Estimated duration: unknown — opencode is non-deterministic; cleanup runs even on timeout

Confirm to proceed, or tell me what to change (model, prompt, files).

Then offer the user two <options>: "Proceed" and "Change something". Wait for confirmation. Do not invoke opencode run until the user confirms.

If the user asks to change anything (different model, edit prompt, add/remove context files), loop back: update the field, re-show the summary, and ask again.

Phase 4: Execute the Task

Run the coding task with the confirmed model. Always run in the background with output redirected to a log file — this is required for the low-token monitoring strategy in Phase 5.

bash
RUN=/tmp/opencode-run-$(date +%s)
opencode run -m "[confirmed-model-id]" "[confirmed prompt]" > "$RUN.log" 2>&1 &
echo $! > "$RUN.pid"
echo "opencode started: run=$RUN pid=$(cat "$RUN.pid")"

Record the run= value this prints and substitute it literally in Phases 5 and 6. Every Bash call is a new shell: $$ resolves to a different number each time and OPENCODE_PID is unset, so a re-derived path would poll a log that does not exist and kill nothing while still reporting success. The .pid file is what carries the process id between calls.

Handling multi-line or complex prompts

For tasks that reference files or need detailed context, use the --file flag:

bash
RUN=/tmp/opencode-run-$(date +%s)
opencode run -m "[confirmed-model-id]" --file path/to/relevant-file.py "[task description]" > "$RUN.log" 2>&1 &
echo $! > "$RUN.pid"
echo "opencode started: run=$RUN pid=$(cat "$RUN.pid")"

Foreground execution is discouraged — streaming the full opencode output back into your context wastes tokens. The Phase 5 monitor reads only the log tail.

Phase 5: Monitor with Minimum Tokens

opencode output is verbose. Streaming the full log back into your context is expensive — a single long run can easily push past 10k tokens of stream chatter. Use the lightweight polling protocol below instead.

Polling protocol

Run one tiny status command per check. It returns at most ~200 bytes — enough to know status, elapsed time, and the latest activity line — without ingesting the whole log.

bash
RUN=/tmp/opencode-run-1234567890   # paste the run= value Phase 4 printed
status() {
  pid=$(cat "$RUN.pid" 2>/dev/null)
  if [ -n "$pid" ] && kill -0 "$pid" 2>/dev/null; then s=running; else s=done; fi
  bytes=$(wc -c < "$RUN.log" 2>/dev/null || echo 0)
  last=$(tail -n 1 "$RUN.log" 2>/dev/null | tr -d '\r' | cut -c1-160)
  printf 'status=%s pid=%s bytes=%s last=%q\n' "$s" "${pid:-none}" "$bytes" "$last"
}
status

That single line is your full progress sample. Do not tail -n 50, do not cat $LOG, do not stream stdout — those defeat the purpose.

Cadence (mandatory)

  • Wait at least 30 seconds between polls for short tasks, 60–120s for longer ones.
  • Hard cap: 6 polls total per run. If still running after that, ask the user whether to keep waiting or kill the process. Do not silently loop.
  • Detect stalls: if bytes= is unchanged for two consecutive polls (i.e., ≥60s of no output growth), treat the run as stalled — confirm with the user before killing.
  • Detect timeout: if no completion after ~5 minutes with no bytes growth, kill and report (then run Phase 6).

What to report between polls

One short line per check, derived from the status() output:

Poll 2 (t+60s): running, 4.2 KB written, last: "Editing src/foo.py …"

Do not paste the raw log. Do not summarize what opencode is "thinking" — you can't tell from a tail line. Stick to: status, elapsed, byte growth, last line.

On completion

When status=done:

  1. Read the tail only, not the whole log: tail -n 40 "$LOG". That's the summary opencode prints at the end (files changed, tokens used, errors).
  2. Report: final status (success/fail), files mentioned in the tail, and token count if opencode printed one.
  3. If the user wants the full output, point them to $LOG — do not paste it.
  4. If the task failed, suggest retrying with the next free model from the Phase 2 list.
  5. Run Phase 6 cleanup — mandatory, even on success.

On error, stall, or timeout

  1. Report the error or stall to the user (one line, derived from the last poll).
  2. Suggest retrying with the next free cloud model.
  3. If all free models have been tried, suggest the user run opencode auth list to check provider auth.
  4. Never attempt the task yourself as a fallback.
  5. Run Phase 6 cleanup — always.

Phase 6: Cleanup (mandatory)

Every execution — success, failure, error, or timeout — must end with cleanup. opencode spawns child processes (LSP servers, MCP servers, node workers) that persist after the main process exits. Without cleanup, these orphaned processes accumulate and drain system resources.

Step 1: Kill the opencode process tree

If you launched opencode in the background, read its pid back from the run's pidfile — $OPENCODE_PID from Phase 4 is gone by now:

bash
RUN=/tmp/opencode-run-1234567890   # paste the run= value Phase 4 printed
pid=$(cat "$RUN.pid" 2>/dev/null)
# Kill the main process and its children
[ -n "$pid" ] && kill "$pid" 2>/dev/null
# Wait briefly for graceful shutdown
sleep 2
# Force kill if still running
[ -n "$pid" ] && kill -9 "$pid" 2>/dev/null

Step 2: Find and kill orphaned opencode processes

After the task completes, scan for any lingering opencode processes from this session:

bash
# List any remaining opencode processes
ps aux | grep '[o]pencode' | grep -v grep

If orphaned processes are found, kill them:

bash
# Kill all opencode run processes (be specific to avoid killing the user's TUI)
pkill -f "opencode run" 2>/dev/null

Be careful to only kill opencode run processes, not the user's interactive TUI session (opencode without subcommand). If the user has an interactive opencode session open, leave it alone.

Step 3: Clean up temp files

bash
rm -f "$RUN.log" "$RUN.pid" 2>/dev/null

Step 4: Confirm cleanup

Report to the user:

Cleanup complete — all opencode processes from this task have been terminated.

If you couldn't kill some processes (permission denied, etc.), warn the user:

Warning: Some opencode processes may still be running. Run pkill -f "opencode run" manually to clean up.

Expected Output

See references/expected-output.md for the full set of example blocks the user should see at each phase (model picker, confirmation summary, low-token progress polls, cleanup confirmation). On error or timeout, the cleanup confirmation still runs.


Edge Cases

  • opencode not installed — see Phase 1, Step 1 (install instructions, then stop).
  • opencode upgrade fails — see Phase 1, Step 2 (report and stop, don't continue on a broken binary).
  • No free cloud models available — see Phase 2, Selection logic step 6 (inform user, stop; no fallback to local/paid models).
  • All priority free models tried and all fail — see Phase 5, "On error, stall, or timeout" (suggest opencode auth list, stop).
  • Task timeout (>5 minutes with no output growth) — see Phase 5, Cadence and "On error, stall, or timeout" (confirm, kill, retry suggestion, Phase 6 cleanup).
  • User rejects the Phase 3 confirmation — see Phase 3, final paragraph (loop back to Phase 2 or 3; never invoke opencode run unconfirmed).
  • User has an interactive opencode TUI session open — see Phase 6, Step 2 (kill only opencode run children, leave the TUI alone).
  • Task prompt contains multi-line content or file references — see Phase 4, "Handling multi-line or complex prompts" (use --file).
  • opencode produces output but exits non-zero — Report the exit code and last lines of output to the user, run cleanup, and suggest verifying the task result manually before relying on it.

Acceptance Criteria

The skill run is considered successful when all of the following are verifiable:

  • Installation verified — Phase 1 confirms opencode is on PATH and reports its version before any other action.
  • Only cloud opencode/* models considered — Filter step rejects ollama/*, lmstudio/*, nvidia/*, and any other namespace. No local model is ever selected.
  • Free models presented to the user — Phase 2 lists every available free opencode/* model with priority 1 as default, plus the privacy note. The user may pick one; if they defer, priority 1 is used.
  • Confirmation captured before execution — Phase 3 shows model + cwd + context files + prompt, and waits for explicit user confirmation before invoking opencode run.
  • Task delegated to opencode — The coding task is executed via opencode run, not by the skill editing files directly or writing code itself.
  • Low-token monitoring used — Phase 5 polls via the single-line status() helper. The raw log is never streamed back; only the last line, byte count, and status are reported per poll. Max 6 polls per run.
  • Stall/timeout handled — No byte growth across two consecutive polls or no completion after ~5 min triggers a confirmation with the user and (if approved) a kill + cleanup.
  • Completion summary delivered — On status=done, the skill reads only tail -n 40 "$LOG" and summarizes files changed and token usage.
  • Cleanup runs on every exit path — Phase 6 runs whether the task succeeded, failed, errored, stalled, or timed out. No orphaned opencode run processes remain.
  • Temp files removed — $LOG (and any other temp files created) are deleted during cleanup.
  • No fallback to self — If opencode is unavailable, the user rejects the confirmation, or all free models fail, the skill stops. It never falls back to editing files or writing code itself.

Step Completion Reports

After each phase, emit a compact status block so pass/fail is scannable:

◆ [Step Name] ([step N of M] — [context])
··································································
  [Check 1]:          √ pass
  [Check 2]:          × fail — [reason]
  [Criteria]:         √ N/M met
  ____________________________
  Result:             PASS | FAIL | PARTIAL

Use √ for pass, × for fail, and — to add brief context. Per-phase example blocks (Installation, Model Discovery, Confirmation, Execution, Monitor, Cleanup) are in references/expected-output.md.

Quick Reference

CommandPurpose
opencode --versionCheck installed version
opencode upgradeUpdate to latest
opencode modelsList available models
opencode run -m MODEL "prompt"Run task with specific model
opencode statsView usage statistics
opencode auth listCheck authenticated providers
pkill -f "opencode run"Kill orphaned run processes
ps aux | grep opencodeFind running opencode processes

附带文件

技能加载后,模型会按需读取这些文件。它们仅作为可读文件提供,绝不会被执行。

常见问题

Opencode Runner AI 技能有什么作用?

Run coding tasks via opencode using free cloud models. Use when asked to offload work to opencode.ai or run a free model. Don't use for local models (Ollama, LM Studio), Claude/OpenAI calls, or when Claude should do the work itself.

为什么在 TypingMind 中使用 Opencode Runner?

因为您只需安装一次,就能搭配任何模型使用。Opencode Runner 采用纯 Markdown 格式,而非特定提供商专用的代码,因此同一技能可用于 GPT-5、Claude、Gemini、Grok 或本地模型。您甚至可以在聊天中途切换模型,而不会影响技能的正常使用。TypingMind 使用您自己的 API 密钥,因此您直接向提供商付费,而不是按席位订阅;您的技能和聊天记录也都保留在您自己的存储空间中。

如何在 TypingMind 中安装 Opencode Runner?

在 TypingMind 中打开“插件 → 技能 → 从 GitHub 安装”,然后粘贴 https://github.com/luongnv89/skills/tree/main/skills/opencode-runner。TypingMind 会读取其中的 SKILL.md,打包相关文件,并将其安装为技能,供您在各个聊天中按需启用。

哪些 AI 模型可以使用 Opencode Runner?

您在 TypingMind 中连接的任何模型都可以。AI 技能采用纯 Markdown 指令,而非特定提供商专用的代码,因此 GPT、Claude、Gemini、Grok 和本地模型都能在请求匹配时加载此技能。

Opencode Runner 可以搭配多少个 AI 模型使用?

数量不限。只要模型支持技能,您就可以将它与 Opencode Runner 搭配使用。GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llama 等模型都可以通过您自己的 API 密钥接入 TypingMind。

Opencode Runner AI 技能免费吗?

是的。luongnv89 已在 GitHub 上根据 MIT 许可证发布了该技能。您只需向自己的 AI 提供商支付所用 Token 的费用。

什么是 AI 技能?

AI 技能是一组可复用的指令,用于教会 AI 模型完成某项特定任务。它遵循开放的 Agent Skills 格式:包含名称和描述的 SKILL.md 文件,以及模型可能需要的脚本、模板或参考文件。模型仅在您的请求与技能匹配时才会读取这些指令,因此已安装的技能在使用前不会产生任何费用。

AI 技能与插件或 MCP 服务器有何不同?

插件或 MCP 服务器为模型提供可调用的新工具,也就是在某处运行并返回结果的代码。AI 技能则为模型提供知识和流程:如何处理任务、遵循哪些步骤,以及怎样的输出才算优质。技能采用纯 Markdown 格式,因此不需要服务器、API 密钥或运行时环境,并且适用于任何模型。

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇