From htmlgraph
Cost-first delegation patterns and decision frameworks for multi-AI coordination
npx claudepluginhub shakestzd/htmlgraphThis skill uses the workspace's default tool permissions.
Use this skill for delegation patterns and decision frameworks in orchestrator mode.
Provides Ktor server patterns for routing DSL, plugins (auth, CORS, serialization), Koin DI, WebSockets, services, and testApplication testing.
Conducts multi-source web research with firecrawl and exa MCPs: searches, scrapes pages, synthesizes cited reports. For deep dives, competitive analysis, tech evaluations, or due diligence.
Provides demand forecasting, safety stock optimization, replenishment planning, and promotional lift estimation for multi-location retailers managing 300-800 SKUs.
Use this skill for delegation patterns and decision frameworks in orchestrator mode.
Trigger keywords: orchestrator, delegation, subagent, task coordination, parallel execution, cost-first, spawner
Delegate tactical work to specialized subagents while you focus on strategic decisions. Save Claude Code context (expensive) by using FREE/CHEAP AIs for appropriate tasks.
Basic pattern:
Task(
subagent_type="gemini", # FREE - use for exploration
description="Find auth patterns",
prompt="Search codebase for authentication patterns..."
)
When to use: ALWAYS use for complex tasks requiring research, code generation, git operations, or any work that could fail and require retries.
For complete guidance: See sections below or run /multi-ai-orchestration for model selection details.
Claude Code is EXPENSIVE. You MUST delegate to FREE/CHEAP AIs first.
Ask these questions IN ORDER:
Can Gemini do this? → Exploration, research, batch ops, file analysis
gemini spawner (FREE - 2M tokens/min)Is this code work? → Implementation, fixes, tests, refactoring
codex spawner (70% cheaper than Claude)Is this git/GitHub? → Commits, PRs, issues, branches
copilot spawner (60% cheaper, GitHub-native)Does this need deep reasoning? → Architecture, complex planning
Is this coordination? → Multi-agent work
ONLY if above fail → Haiku (fallback)
| Task | WRONG (Cost) | CORRECT (Cost) | Savings |
|---|---|---|---|
| Search 100 files | Task() ($15-25) | Gemini spawner (FREE) | 100% |
| Generate code | Task() ($10) | Codex spawner ($3) | 70% |
| Git commit | Task() ($5) | Copilot spawner ($2) | 60% |
| Strategic decision | Direct task ($20) | Claude Opus ($50) | Must pay for quality |
WRONG (wastes Claude quota):
- Code implementation → Task(haiku) # USE Codex spawner
- Git commits → Task(haiku) # USE Copilot spawner
- File search → Task(haiku) # USE Gemini spawner (FREE!)
- Research → Task(haiku) # USE Gemini spawner (FREE!)
CORRECT (cost-optimized):
- Code implementation → Codex spawner # Cheap, sandboxed
- Git commits → Copilot spawner # Cheap, GitHub-native
- File search → Gemini spawner # FREE!
- Research → Gemini spawner # FREE!
- Strategic decisions → Claude Opus # Expensive, but needed
- Haiku → FALLBACK ONLY # When spawners fail
Orchestrator (You):
Executor (Subagent):
Why separation matters:
What looks like "one bash call" becomes many:
Context cost comparison:
Direct execution (fails):
bash call 1 → fails
bash call 2 → fails
bash call 3 → fix code
bash call 4 → bash call 1 retry
bash call 5 → bash call 2 retry
= 5+ tool calls, context consumed
Delegation (cascades isolated):
Task(subagent handles all retries) → 1 tool call
Read result → 1 tool call
= 2 tool calls, clean context
Token savings:
Ask yourself these questions:
Will this likely be ONE tool call?
Does this require error handling?
Could this cascade into multiple operations?
Is this strategic or tactical?
Rule of thumb: When in doubt, ALWAYS DELEGATE. Cascading failures are expensive.
Only these can be executed directly by orchestrator:
Task() - Delegation itself
Task(subagent_type="htmlgraph:gemini-spawner", ...)AskUserQuestion() - Clarifying requirements
AskUserQuestion("Should we use Redis or PostgreSQL?")TodoWrite() - Tracking work items
TodoWrite(todos=[...])HtmlGraph CLI operations (create features, spikes, bugs):
htmlgraph feature create "title"htmlgraph spike create "title"htmlgraph bug create "title"Everything else MUST be delegated.
Decision tree (check each in order):
Is this exploration/research/analysis?
Is this code implementation/testing?
Is this git/GitHub operation?
Does this need deep reasoning?
Is this multi-agent coordination?
All else fails → Task() with Haiku (fallback)
Spawner Subagent Types:
gemini - FREE, 2M tokens/min, exploration & researchcodex - Cheap code specialist, implementation & testingcopilot - Cheap git specialist, GitHub integrationhaiku - Generic Claude Haiku (use as fallback or when spawners fail)Task(
subagent_type="gemini",
description="Analyze authentication patterns",
prompt="""
Analyze codebase for:
- All authentication patterns
- OAuth implementations
- Session management
- JWT usage
"""
)
Best for:
Task(
subagent_type="codex",
description="Implement OAuth middleware",
prompt="""
Implement OAuth authentication:
- Sandbox mode: workspace-write
- Add JWT token generation
- Include error handling
- Write unit tests
"""
)
Best for:
Task(
subagent_type="copilot",
description="Commit and create PR",
prompt="""
Commit changes and create PR:
- Message: "feat: add OAuth authentication"
- Files: src/auth/*.py, tests/test_auth.py
- Create PR with description
"""
)
Best for:
Task(
prompt="Design authentication architecture...",
subagent_type="sonnet" # or "opus" for deep reasoning
)
Sonnet (Mid-tier):
Opus (Expensive):
Simple exploration:
Task(
subagent_type="gemini",
description="Find all auth patterns",
prompt="Search codebase for authentication patterns and summarize findings"
)
Code implementation:
Task(
subagent_type="codex",
description="Implement OAuth endpoint",
prompt="Implement OAuth authentication endpoint with JWT support"
)
Git operations:
Task(
subagent_type="copilot",
description="Commit changes",
prompt="Commit changes with message: 'feat: add OAuth authentication'"
)
MANDATORY: All git write operations must be delegated to the copilot-operator agent.
# For commits, pushes, PRs, and code generation
Agent(
subagent_type="htmlgraph:copilot-operator",
description="Commit and push changes",
prompt="Commit all staged files with message: 'feat: add X'. Then push to origin main.",
)
The copilot-operator agent:
Never run git commit/push directly from the orchestrator. The PreToolUse hook will deny it in strict mode.
For implementation, refactoring, and structured output tasks:
Agent(
subagent_type="htmlgraph:codex-operator",
description="Implement feature X",
prompt="Add OAuth authentication to the login endpoint. Use gpt-4.1-mini.",
)
The codex-operator agent:
-m gpt-4.1-mini (never expensive gpt-5.4 default)For codebase exploration, documentation research, and large-context analysis:
Agent(
subagent_type="htmlgraph:gemini-operator",
description="Research auth patterns",
prompt="Analyze all authentication patterns in this codebase. Find security gaps.",
)
The gemini-operator agent:
MANDATORY: Always analyze parallelizability when 2+ tasks are identified.
Before presenting recommendations or starting multi-task work, ALWAYS:
Decision matrix:
| Dependency? | File Overlap? | Action |
|---|---|---|
| No | No | Parallel worktrees (DEFAULT) |
| No | Yes | Sequential (same files = merge conflicts) |
| Yes | No | Pipeline (parallel where deps allow) |
| Yes | Yes | Sequential |
Pattern: Spawn all at once in isolated worktrees
# Launch parallel agents in worktrees — one per feature
Agent(
subagent_type="htmlgraph:sonnet-coder",
description="Feature A",
prompt="Implement feature A...",
isolation="worktree",
run_in_background=True,
)
Agent(
subagent_type="htmlgraph:sonnet-coder",
description="Feature B",
prompt="Implement feature B...",
isolation="worktree",
run_in_background=True,
)
Agent(
subagent_type="htmlgraph:haiku-coder",
description="Feature C (simple)",
prompt="Implement feature C...",
isolation="worktree",
run_in_background=True,
)
Benefits:
After completion: Merge worktree branches to main, run quality gates, clean up.
Pattern: Chain dependent tasks in sequence
# 1. Research existing patterns
Task(
subagent_type="gemini",
description="Research OAuth patterns",
prompt="Find all OAuth implementations in codebase..."
)
# 2. Wait for research, then implement
# (In next message after reading result)
research_findings = "..." # Read from previous task result
Task(
subagent_type="codex",
description="Implement OAuth based on research",
prompt=f"""
Implement OAuth using discovered patterns:
{research_findings}
"""
)
# 3. Wait for implementation, then commit
Task(
subagent_type="copilot",
description="Commit implementation",
prompt="Commit OAuth implementation..."
)
When to use: When later tasks depend on earlier results
Subagents report findings automatically:
When a Task() completes, findings are available via CLI:
# Check recent spikes
htmlgraph spike list
# View specific spike
htmlgraph spike show <id>
Pattern: Read findings after Task completes
# 1. Delegate exploration
Task(
subagent_type="htmlgraph:gemini-operator",
description="Analyze auth patterns",
prompt="Find all authentication patterns..."
)
# 2. The subagent creates a spike with findings
# Read findings via: htmlgraph spike list (then spike show <id>)
# 3. Use findings in next delegation
Task(
subagent_type="htmlgraph:codex-operator",
description="Implement based on findings",
prompt="Implement authentication based on auth pattern research findings..."
)
Let subagents handle retries:
# WRONG - Don't retry directly as orchestrator
bash_result = Bash(command="git commit -m 'feat: new'")
if failed:
# Retry directly (context pollution)
Bash(command="git pull && git commit") # More context used
# CORRECT - Subagent handles retries
Task(
subagent_type="copilot",
description="Commit changes with retry",
prompt="""
Commit changes:
Message: "feat: new feature"
If commit fails:
1. Pull latest changes
2. Resolve conflicts if any
3. Retry commit
4. Handle pre-commit hooks
Report final status: success or failure
"""
)
Benefits:
How it works:
CLAUDE_ORCHESTRATOR_ACTIVE=trueWhy: Preserve orchestration discipline after context compact
What you see:
To manually trigger:
/orchestrator-directives
Environment variable:
CLAUDE_ORCHESTRATOR_ACTIVE=true # Set by SDK
Features preserved across compact:
What's lost:
Re-activation pattern:
Before compact:
- Work on features, track in HtmlGraph
- Delegate with clear prompts
- Use SDK to save progress
After compact:
- Orchestrator Skill auto-activates
- Re-read recent spikes for context
- Continue delegations
- Use Task IDs for parallel coordination
When delegating to ANY coder agent, include these requirements in the prompt:
pyproject.toml before adding new dependenciessrc/python/htmlgraph/utils/ for existing utilities before writing new onesuv run ruff check --fix && uv run ruff format && uv run mypy src/ && uv run pytest
Never commit with unresolved type errors, lint warnings, or test failures.
Principle 1: Delegation > Direct Execution
Principle 2: Cost-First > Capability-First
Principle 3: You Don't Know the Outcome
Principle 4: Parallel > Sequential
Principle 5: Track Everything
Delegation > Direct Execution. Cascading failures consume exponentially more context than structured delegation.
Cost-First > Capability-First. Use FREE/cheap AIs before expensive Claude models.
| Operation | MUST Use | Cost | Fallback |
|---|---|---|---|
| Search files | Gemini spawner | FREE | Haiku |
| Pattern analysis | Gemini spawner | FREE | Haiku |
| Documentation research | Gemini spawner | FREE | Haiku |
| Code generation | Codex spawner | $ (70% off) | Sonnet |
| Bug fixes | Codex spawner | $ (70% off) | Haiku |
| Write tests | Codex spawner | $ (70% off) | Haiku |
| Git commits | Copilot spawner | $ (60% off) | Haiku |
| Create PRs | Copilot spawner | $ (60% off) | Haiku |
| Architecture | Claude Opus | $$$$ | Sonnet |
| Strategic decisions | Claude Opus | $$$$ | Task() |
Key: FREE = No cost | $ = Cheap | $$$$ = Expensive (but necessary)
htmlgraph --helpCost-First Orchestration:
Orchestrator Rule: Only execute: Task(), AskUserQuestion(), TodoWrite(), SDK operations
Everything else → Delegate to appropriate spawner
When in doubt → DELEGATE