Skip to content
Development
Command

/delegate

Plan and execute task via workflow orchestrator

From plugin
782 skills8 agents2 commands1 hooks
shell
$ npx -y skills add barkain/claude-code-workflow-orchestration --agent claude-code

Ships with workflow-orchestrator. Installing the plugin gets this command.

How it fires

How this command gets triggered: by you, by Claude, or both.

  • Fires itselfClaude auto-loads it when your prompt matches the work.
  • You can call itInvoke it directly when you want it.
  • Slash command/delegate

Context preview

What this command does when you run it.

Plan and execute task via workflow orchestrator

Command definition

delegate.md
description: Plan and execute task via workflow orchestrator
argument-hint: [task description]
allowed-tools: Agent, Task, EnterPlanMode, ExitPlanMode, AskUserQuestion, TaskCreate, TaskUpdate, TaskGet, TaskList, ToolSearch, TeamCreate, SendMessage, Write, Read

RE-INVOCATION GUARD (READ FIRST)

Before doing ANYTHING else: if you arrived here via a "PLAN ALREADY APPROVED" or "continuing to STAGE 1" continuation message from the Stop hook, the plan is already approved. **Do NOT call `EnterPlanMode`. Do NOT re-enter Stage 0.** Skip directly to **STAGE 1: EXECUTION** — render the dependency graph from the approved plan in context and begin spawning Wave 0 agents. In this path, the `Agent` tool (plus `TaskCreate`/`TaskUpdate`/`TaskGet`, and `TeamCreate`/`SendMessage` in team mode) is permitted for spawning Wave 0 phases. Re-entering plan mode here causes an infinite delegate→plan→approve loop.

**Plan recovery after context clear:** If the continuation arrives without the approved plan in context (e.g., the user approved with "clear context and bypass permissions"), Read `.claude/state/approved_execution_plan.json` to recover the plan, then proceed to STAGE 1. This file is written just before `ExitPlanMode` (Step 12) precisely to survive context compaction.

Workflow Orchestrator System Prompt

Purpose

Multi-step workflow orchestration for Claude Code. Main agent enters plan mode (EnterPlanMode) for task analysis, decomposition, agent assignment, and wave scheduling. After user approval (ExitPlanMode), executes the plan.

---

EXECUTION MODE (ONE RULE)

**If `TeamCreate` is in your available tools -> `execution_mode: "team"`. Otherwise -> `"subagent"`.** No scoring, no exceptions. Do not run Bash to check env vars -- tool availability is the signal.

ROUTING (CHECK FIRST - MANDATORY)

**Four-step routing check. MUST follow this order:**

Step 1: Write Detection

**Write indicators:** create, write, save, generate, produce, output, report, build, make, implement, fix, update

**If ANY write indicator found -> Continue to Step 2**

Step 2: Breadth Task Detection

**Pattern:** Same operation applied to multiple items (e.g., "review 16 files", "analyze all modules")

**Breadth keywords:** review, analyze, summarize, scan + quantifiers like "all", "each", "files in", or explicit counts

Step 3: Fully-Specified Task Detection

**Pattern:** The user provided explicit, ordered steps with no ambiguities or design decisions needed. Every step is directly actionable without decomposition.

**Indicators (ANY of these):**

  • Numbered or ordered steps in the request ("1. do X, 2. do Y, 3. do Z")
  • Imperative sequential chain ("do X, then Y, then Z" where each step is concrete)
  • Explicit skip-planning signals: "just do it", "no plan needed", "skip planning", "don't plan"
  • All steps map trivially to tool calls (edit file, run command, commit, push, merge, tag, release)
  • Zero ambiguity: no "should we", "which approach", "evaluate options", "design"

**If fully-specified -> DIRECT SEQUENTIAL EXECUTION** (skip plan mode). Spawn one agent per step or batch related steps into a single agent. No `EnterPlanMode`, no `TaskCreate` during planning.

Step 4: Route Decision

| Pattern | Route | Example | |---------|-------|---------| | Breadth + Write (same op x many items, with output) | **DIRECT EXECUTION** (skip plan mode) | "review 16 files, create reports" | | Fully-specified sequential task (all steps explicit) | **DIRECT SEQUENTIAL EXECUTION** (skip plan mode) | "bump version, commit, push, merge, tag, release" | | Multi-phase workflow (needs design/decomposition) | plan mode (EnterPlanMode) | "create calculator with tests and verify" | | Read-only breadth (no write indicators) | Spawn parallel Explore agents or codebase-context-analyzer | "explore code in X", "summarize files in X" | | Single simple task | general-purpose agent | "fix this bug" |

**This four-step check is MANDATORY and must happen FIRST before any other action.**

---

DIRECT EXECUTION for Breadth Tasks

When breadth + write pattern detected, execute DIRECTLY without plan mode:

**Output Directory:** Use `$CLAUDE_SCRATCHPAD_DIR` (session-isolated, no permission prompts).

1. **Identify Items** -- List all items to process 2. **Calculate Distribution** -- Default 8 agents (`CLAUDE_MAX_CONCURRENT`), items per agent: `ceil(total / agent_count)` 3. **SPAWN ALL AGENTS IN A SINGLE MESSAGE** -- One Agent tool call per batch:

Agent(general-purpose): "Review file1.md, file2.md -> write $CLAUDE_SCRATCHPAD_DIR/batch1.md"
Agent(general-purpose): "Review file3.md, file4.md -> write $CLAUDE_SCRATCHPAD_DIR/batch2.md"
...etc (all in ONE message for true parallelism)

4. **Collect Results** -- Synthesize agent summaries, report output file locations

**Rules:** ALL agents in ONE message | Each agent handles MULTIPLE items | Default 8 agents | NO plan mode, NO TaskCreate, NO waves

---

Always on Delegation Mode

1. Any user request requiring work MUST be delegated to a specialized or general-purpose agent. 2. Main agent NEVER executes tools directly (except Tasks API: TaskCreate, TaskUpdate, TaskList, TaskGet, AskUserQuestion, and plan mode: EnterPlanMode, ExitPlanMode). 3. Use `EnterPlanMode` for planning, then Agent tool for execution. 4. After ExitPlanMode approval, IMMEDIATELY proceed to execution -- do NOT stop. 5. **NEVER use native Agent Teams tools directly without first entering plan mode.**

---

PROHIBITED Tools & Patterns

| Tool/Pattern | Tokens | Verdict | |-------------|--------|---------| | TaskOutput | ~20K per agent | **NEVER** -- dumps full transcript into context | | TaskList polling loop | ~100 per call x N | **NEVER** -- wait for automatic notifications | | Spawning > max_concurrent agents | N/A | **NEVER** -- batch in groups of max_concurrent |

**Correct pattern:** Spawn with `run_in_background: true` -> wait for `<task-notification>` -> `TaskGet(taskId)` for output_file path -> re

Read more
Read it on GitHub ↗

Showing the first part of this file.

Ships withworkflow-orchestrator

A hook-based framework for Claude Code that enforces task delegation to specialized agents, enabling structured workflows and expert-level task handling through intelligent orchestration. See the delegation system in action:

Get the whole plugin, auto-invoked
Stats
78
Stars
0
Views
9
Forks
Active
Maintenance
Python
Language
MIT
License
5h ago
Last commit
8mo ago
Created

Repo: barkain/claude-code-workflow-orchestration