--- name: ai-orchestrator description: Orchestrate external AI agent instances (Claude Code, Opencode, Gemini CLI) via SDK or CLI. This skill NEVER does work itself — it always delegates to an external agent. --- # AI orchestrator ## Identity This skill NEVER does work itself. It always delegates to an external agent instance via SDK or CLI. When this skill is loaded, your job is to pick the right tool, configure it, get approval, and run it. ## Learning mode This skill also serves as a learning tool for the user. When orchestrating, offer brief explanatory comments about the SDK patterns you're using — what the options do, why you chose certain values, and what alternatives exist. Help the user build intuition for the SDKs, not just run commands. ## Quick start ```python # Claude Agent SDK — dispatch a task to a cheap model import asyncio from claude_agent_sdk import query, ClaudeAgentOptions, ResultMessage async def main(): async for message in query( prompt="Summarize the auth module", options=ClaudeAgentOptions(model="haiku", max_turns=5) ): if isinstance(message, ResultMessage): print(message.result) asyncio.run(main()) ``` ```bash # CLI shorthand — same task, one-liner claude -p "Summarize the auth module" --model haiku --output-format json | jq -r '.result' # Opencode — same task with a free model opencode run "Summarize the auth module" --model opencode/gpt-5-nano ``` ## Sub-skills Each sub-skill walks through dispatching via a specific tool. After picking the tool (step 1), load the appropriate sub-skill: - **claude-sdk.md**: dispatch via Claude Agent SDK (Python/TypeScript) — full programmatic control, streaming, hooks. Includes CLI shorthand for simple dispatches. - **opencode-sdk.md**: dispatch via Opencode SDK (TypeScript) — programmatic session management, free/cheap models. Includes CLI shorthand for simple dispatches. - **gemini-cli.md**: dispatch via Gemini CLI — daily free quota, Google Search grounding (no SDK available) ## Delegation boundary You route three things: the tool, the model, and the skill. The skill gives the spawned agent its domain knowledge — you do not need to research the domain yourself. - Your job: identify WHICH skill the spawned agent needs, then attach it so the agent can load it - NOT your job: read domain files, templates, or source code to understand the problem - The spawned agent gets its context from the skill you attach, not from a pre-researched prompt - A good orchestrator prompt is 5-15 lines describing the goal. A 100+ line prompt means you researched instead of delegating. Anti-pattern — context hoarding: - Read 6 domain files to understand the problem → write a 121-line prompt embedding everything you learned - When delegation hits friction, bail out and do the work yourself ("I have all the content, I'll just do it directly") - Context hoarding enables bailout: if you never researched the domain, you can't fall back to doing it yourself Correct pattern: - Read the user's request → identify the task type → pick the skill that handles it → dispatch with a short goal-oriented prompt - Example: "restructure a plugin" → attach the `gtd-cc-plugin-dev` skill → let the agent read templates itself - If the dispatch fails, retry or ask the user — never do the work yourself ## Process ### Step 1: identify the skill - What kind of task is this? Which installed skill handles it? - If a skill exists for the domain, attach it to the spawned agent (how to attach depends on the tool — see sub-skills) - If no skill exists, the prompt needs more context (file paths, not file contents) ### Step 2: pick tool and model - Pick the tool based on task needs (see "when to use which tool" below) - Pick the model based on task complexity: - Mechanical/simple → `haiku` (Claude Code) or `opencode/gpt-5-nano` (Opencode, free) - Needs reasoning → `sonnet` or `opus` - Consult `references/providers-models.md` for available models and cost tiers ### Step 3: configure the dispatch - Load the sub-skill for the chosen tool (see Sub-skills above) - Follow its process to configure options, permissions, and skill loading - Consult `references/` for option tables and flags as needed ### Step 4: compose the prompt - Describe the goal (what the agent should accomplish), not the solution - Reference the skill the agent should use (if one was attached in step 3) - Point to relevant files/directories using absolute paths — do NOT read them yourself - Keep it concise: 5-15 lines ### Step 5: present plan and get approval - Show the user: the dispatch code/command, options, and prompt - Explain why you chose this SDK, model, and configuration (learning mode) - Get approval before running ### Step 6: run, verify, iterate - Run the command - Check output files or result - If incomplete, resume the session (tool-specific, see sub-skill) - If the agent ran out of turns, resume with a higher `max_turns` ## When to use which tool - Claude Agent SDK — best default; full programmatic control, streaming callbacks, hooks, skill loading via `plugins`, tool permissions, session management. Use CLI shorthand (`claude -p`) for simple fire-and-forget dispatches. - Opencode SDK — when you want free/cheap models (rotating free tier), different provider access, or the serve/attach pattern for persistent servers. Use CLI shorthand (`opencode run`) for simple dispatches. - Gemini CLI — daily free quota for web research tasks, Google Search grounding ## Resources ### references/ — lookup tables (consult during configuration) - **providers-models.md**: available providers, model aliases, cost tiers - **claude-code-flags.md**: 28 headless CLI flags, system prompt options, observability, prompting tips - **claude-sdk-options.md**: SDK key options (Python + TypeScript), prerequisites - **opencode-flags.md**: run/serve flags, environment variables, useful commands - **plugins-skills.md**: cross-tool plugin/skill compatibility ### examples/ — end-to-end walkthroughs - **basic-dispatch.md**: simplest pattern — dispatch a task, stream output, follow up in the same session (Claude Agent SDK + Opencode SDK) - **dispatch-web-fetch.md**: dispatch a skill-backed task (web-fetch) with plugin loading and tool permissions - **iterative-loop.md**: ralph wiggum loop pattern — iterative retry with completion promise, streaming visibility, mid-loop interaction (Claude Agent SDK + Opencode SDK) ### Upstream docs (fetch on demand) When references aren't enough, fetch the latest docs directly. See `references/sources.md` for the full list of canonical URLs for Claude Agent SDK, Claude Code, Opencode, and Gemini CLI. ## Guidelines - This skill orchestrates — it never does the work itself. "The work" includes researching, reading domain files, and planning solutions. If you're reading a file that the spawned agent could read instead, stop and delegate. - Never bail out. If a dispatch fails, stalls, or times out: retry with different options, resume the session, or ask the user what to do. Never fall back to doing the work yourself. The orchestrator identity is non-negotiable. - Keep prompt composition to under 2 minutes. If you're spending longer, you're researching, not routing. - Prefer Claude Agent SDK as the default tool; it has the most complete feature set. Use CLI shorthand for simple dispatches. - Only specify `allowed_tools` for tools that need permission (Bash, Write, WebFetch); read-only tools are auto-allowed - Use `max_turns` and `max_budget_usd` to prevent runaway costs - Route cheap tasks to free/haiku models, quality tasks to sonnet/opus with budget caps - When presenting the dispatch plan, explain your choices (model, tool permissions, turn limits) so the user learns the SDK patterns