Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "workflow-orchestrator",
"source": "./",
"description": "Delegation system with workflow orchestration, specialized agents, and parallel execution for Claude Code",
"version": "1.15.1",
"version": "1.16.0",
"author": {
"name": "Nadav Barkai"
},
Expand Down
2 changes: 1 addition & 1 deletion .claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "workflow-orchestrator",
"version": "1.15.1",
"version": "1.16.0",
"description": "Delegation system with workflow orchestration, specialized agents, and parallel execution for Claude Code",
"author": {
"name": "Nadav Barkai"
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable changes to this project will be documented in this file.

## [1.16.0] - 2026-04-06

### Fixed
- **Session cost from stdin**: Replaced all daily cost self-calculation (JSONL scanning, background refresh, cost cache) with simple `cost.total_cost_usd` read from stdin JSON -- zero I/O, real-time session cost
- **Delegation hook subagent deadlock**: Expanded subagent bypass to check `CLAUDE_AGENT_ID` and `CLAUDE_SCRATCHPAD_DIR` in addition to `CLAUDE_PARENT_SESSION_ID`; added redundant safety net inside `main()`; normalized `CLAUDE_PROJECT_DIR` path resolution with `Path.resolve()`
- **`/delegate` plugin prefix**: Fixed all references to use full plugin prefix `/workflow-orchestrator:delegate`

### Removed
- **`skills/breadth-reader/`**: Removed breadth-reader skill directory and all references
- `_find_todays_session_files()`, `_sum_session_cost()`, `_cost_from_usage()`, `fetch_costs_raw()`, `spawn_background_refresh()`, `load_cost_cache()`, `save_cost_cache()`, `is_cache_valid()`, `_is_refresh_locked()` -- all replaced by stdin session cost
- Cost cache constants (`COST_CACHE_FILE`, `COST_CACHE_TTL_SECONDS`, `COST_REFRESH_LOCK`) and lock file logic
- `time` import (no longer needed)

## [1.15.1] - 2026-04-04

### Fixed
Expand Down
27 changes: 11 additions & 16 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
When ANY tool is blocked by the delegation policy hook:

1. **DO NOT try alternative approaches** - just delegate immediately
2. **IMMEDIATELY use `/delegate <task>`** on first tool block
2. **IMMEDIATELY use `/workflow-orchestrator:delegate <task>`** on first tool block
3. **The entire user request must be delegated**, not just the blocked tool

### Recognition Pattern
Expand All @@ -21,8 +21,8 @@ Error: PreToolUse:* hook error: [...] Tool blocked by delegation policy
Tool: <ToolName>

STOP: Do NOT try alternative tools.
REQUIRED: Use /delegate command immediately:
/delegate <full task description>
REQUIRED: Use /workflow-orchestrator:delegate command immediately:
/workflow-orchestrator:delegate <full task description>
```

First tool block = immediate delegation. Don't try alternatives, don't explain — just delegate.
Expand Down Expand Up @@ -60,18 +60,17 @@ CI workflow exists (`.github/workflows/ci.yml`) but tests are currently disabled
## Available Commands

```bash
/delegate <task> # Plan and execute task via native plan mode
/ask <question> # Read-only question answering (forked context)
/bypass # Toggle delegation enforcement on/off (persists until toggled)
/add-statusline # Enable workflow status display
/breadth-reader <prompt> # Read-only breadth tasks (explore, review, summarize)
/workflow-orchestrator:delegate <task> # Plan and execute task via native plan mode
/workflow-orchestrator:ask <question> # Read-only question answering (forked context)
/workflow-orchestrator:bypass # Toggle delegation enforcement on/off (persists until toggled)
/workflow-orchestrator:add-statusline # Enable workflow status display
```

**Installation:**
- Plugin: `claude plugin install workflow-orchestrator@barkain-plugins`
- Manual: `./install.sh [--scope=user|project]`

In plugin mode, agent/skill names use prefix `workflow-orchestrator:` (e.g., `workflow-orchestrator:task-completion-verifier`).
In plugin mode, all commands and agent names use the `workflow-orchestrator:` prefix.

---

Expand Down Expand Up @@ -115,7 +114,7 @@ User prompt
| **PreToolUse** (`*`, `Bash`) | `validate_task_graph_compliance.py`, `require_delegation.py`, `token_rewrite_hook.py` (Bash only) | Validate Agent/Task invocations against active task graph; block non-allowed tools (compressed error messages); rewrite Bash commands for token efficiency (cd && pattern, eslint, next, tsc) |
| **PostToolUse** | `python_posttooluse_hook.py` (Edit/Write/MultiEdit), `remind_skill_continuation.py` (ExitPlanMode\|Skill\|SlashCommand), `validate_task_graph_depth.py` + `remind_todo_after_task.py` (Agent/Task) | Python validation (Ruff, Pyright, security), workflow continuation state (triggers on ExitPlanMode for plan mode flows), depth-3 enforcement, task reminders |
| **UserPromptSubmit** | `clear-delegation-sessions.py` | Clear delegation state, record turn start timestamp, clear team state (`team_mode_active`, `team_config.json`), rotate logs |
| **SessionStart** (`startup\|resume\|clear\|compact`) | `inject_workflow_orchestrator.py`, `inject-output-style.py`, `inject_token_efficiency.py` | Inject conditional orchestrator (stub on startup, full on /delegate), output style, token efficiency guidance |
| **SessionStart** (`startup\|resume\|clear\|compact`) | `inject_workflow_orchestrator.py`, `inject-output-style.py`, `inject_token_efficiency.py` | Inject conditional orchestrator (stub on startup, full on /workflow-orchestrator:delegate), output style, token efficiency guidance |
| **SubagentStop** (`*`) | `remind_todo_update.py` (async), `trigger_verification.py` | Remind to update tasks, suggest verification |
| **Stop** | `python_stop_hook.py` | Turn duration, workflow continuation (block stop + inject "continue"), quality analysis |

Expand All @@ -140,15 +139,11 @@ Special cases:
| Mechanism | How | Scope |
|-----------|-----|-------|
| Env var | `DELEGATION_HOOK_DISABLE=1` | Session-wide |
| `/bypass` command | Creates `.claude/state/delegation_disabled` | Persists until toggled |
| `/workflow-orchestrator:bypass` command | Creates `.claude/state/delegation_disabled` | Persists until toggled |
| Subagent auto-bypass | `CLAUDE_PARENT_SESSION_ID` set | Automatic for subagents |
| Delegation active flag | `.claude/state/delegation_active` created on Skill/Agent/Task use | Per-delegation |

### Skills (forked context)

- **breadth-reader** (`skills/breadth-reader/SKILL.md`): Lightweight read-only breadth tasks. Spawns `Explore` subagents (Haiku). Returns summary only.

**Note:** The `task-planner` skill has been removed. Its orchestration and planning functionality is now provided by native plan mode (EnterPlanMode/ExitPlanMode), which handles both planning and execution orchestration directly within the main agent context.
**Note:** The `task-planner` and `breadth-reader` skills have been removed. Planning and orchestration are provided by native plan mode (EnterPlanMode/ExitPlanMode). Read-only breadth tasks are handled by spawning parallel Explore agents or the codebase-context-analyzer directly.

### Specialized Agents (8)

Expand Down
37 changes: 12 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ Temporarily disable delegation enforcement if needed:
export DELEGATION_HOOK_DISABLE=1

# From within a Claude Code session (interactive toggle)
/bypass
/workflow-orchestrator:bypass
```

The `/bypass` command allows toggling delegation enforcement on/off from within a Claude Code session without restarting.
The `/workflow-orchestrator:bypass` command allows toggling delegation enforcement on/off from within a Claude Code session without restarting.

## Environment Variables

Expand Down Expand Up @@ -259,7 +259,7 @@ The `plugin-hooks.json` configures the delegation enforcement hooks using cross-
| **PreToolUse** | `validate_task_graph_compliance.py`, `require_delegation.py`, `token_rewrite_hook.py` (Bash only) | Validate task graph compliance; block non-delegated tools; rewrite Bash commands for token efficiency (cd && pattern, eslint, next, tsc support) |
| **PostToolUse** | `python_posttooluse_hook.py` (Edit/Write), `remind_skill_continuation.py` (ExitPlanMode/Skill/SlashCommand), `validate_task_graph_depth.py` (Agent/Task), `remind_todo_after_task.py` (Agent/Task, async) | Python validation (Ruff/Pyright); workflow continuation state; depth-3 enforcement; task reminders |
| **UserPromptSubmit** | `clear-delegation-sessions.py` | Clear delegation/team state, record turn timestamp |
| **SessionStart** | `inject_workflow_orchestrator.py`, `inject-output-style.py`, `inject_token_efficiency.py` | Inject conditional orchestrator (stub on startup, full on /delegate), output style, token efficiency guidance |
| **SessionStart** | `inject_workflow_orchestrator.py`, `inject-output-style.py`, `inject_token_efficiency.py` | Inject conditional orchestrator (stub on startup, full on /workflow-orchestrator:delegate), output style, token efficiency guidance |
| **SubagentStop** | `remind_todo_update.py` (async), `trigger_verification.py` | Remind to update tasks, suggest verification |
| **Stop** | `python_stop_hook.py` | Turn duration tracking, workflow continuation |

Expand All @@ -270,8 +270,8 @@ Multi-step workflow orchestration requires the workflow_orchestrator system prom
**Automatic (via SessionStart hook):**

The `inject_workflow_orchestrator.py` hook uses conditional injection:
- **On startup/resume:** Injects a lightweight stub that registers `/delegate` and `/bypass` commands without loading the full orchestrator prompt, keeping baseline token overhead minimal.
- **On `/delegate` invocation:** The full `workflow_orchestrator.md` system prompt is loaded on-demand, providing the complete planning and execution logic only when needed.
- **On startup/resume:** Injects a lightweight stub that registers `/workflow-orchestrator:delegate` and `/workflow-orchestrator:bypass` commands without loading the full orchestrator prompt, keeping baseline token overhead minimal.
- **On `/workflow-orchestrator:delegate` invocation:** The full `workflow_orchestrator.md` system prompt is loaded on-demand, providing the complete planning and execution logic only when needed.

**What this enables:**
- Multi-step task detection via pattern matching
Expand All @@ -290,15 +290,15 @@ Blocks most tools and forces delegation to specialized agents. Cross-platform Py
**Allowed tools:**
- `AskUserQuestion` - Ask users for clarification
- `TaskCreate`, `TaskUpdate`, `TaskList`, `TaskGet` - Track task progress with structured metadata
- `Skill`, `SlashCommand` - Execute slash commands (including `/delegate`)
- `Skill`, `SlashCommand` - Execute slash commands (including `/workflow-orchestrator:delegate`)
- `Agent`, `SubagentTask`, `AgentTask` - Spawn subagents

**Note:** `TaskOutput` is prohibited to prevent context exhaustion. Agents write to `$CLAUDE_SCRATCHPAD_DIR` and return `DONE|{path}` only.

**All other tools are blocked** and show:
```
🚫 Tool blocked by delegation policy
✅ REQUIRED: Use /delegate command immediately
✅ REQUIRED: Use /workflow-orchestrator:delegate command immediately
```

### 2. Specialized Agents (`agents/`)
Expand All @@ -316,25 +316,12 @@ Blocks most tools and forces delegation to specialized agents. Cross-platform Py

**Note:** The `delegation-orchestrator` agent has been deprecated. Its orchestration and routing functionality is now provided by native plan mode (EnterPlanMode/ExitPlanMode), which handles both planning and execution orchestration directly within the main agent.

### 3. Breadth Reader Skill (`skills/breadth-reader/`)
### 3. Delegation Command (`commands/delegate.md`)

For read-only breadth tasks (explore, review, summarize), the `breadth-reader` skill provides optimized handling:
The `/workflow-orchestrator:delegate` command provides intelligent task delegation with integrated planning:

```bash
/breadth-reader explore ~/dev/project/
```

- Runs in forked context (isolated from main agent)
- Claude auto-optimizes parallelism internally
- Returns summary only to main agent
- No orchestration overhead

### 4. Delegation Command (`commands/delegate.md`)

The `/delegate` command provides intelligent task delegation with integrated planning:

```bash
/delegate <task description>
/workflow-orchestrator:delegate <task description>
```

**How it works:**
Expand All @@ -346,7 +333,7 @@ The `/delegate` command provides intelligent task delegation with integrated pla
6. Creates task list via TaskCreate
7. Exits plan mode (ExitPlanMode) and executes phases as directed by the plan

### 5. Workflow Orchestration System Prompt (`system-prompts/workflow_orchestrator.md`)
### 4. Workflow Orchestration System Prompt (`system-prompts/workflow_orchestrator.md`)

Enables multi-step workflow detection and preparation for complex tasks. Works in conjunction with native plan mode (EnterPlanMode/ExitPlanMode).

Expand Down Expand Up @@ -508,7 +495,7 @@ The framework minimizes command output to reduce context consumption and preserv

3. **Conditional System Prompt Injection** — The orchestrator is injected conditionally:
- On session startup: Stub version (~200 tokens) provides minimal direction
- On first plan mode entry (via /delegate or detected multi-step): Full version (~11K tokens) for complete planning capability
- On first plan mode entry (via /workflow-orchestrator:delegate or detected multi-step): Full version (~11K tokens) for complete planning capability
- Saves tokens for single-step and read-only tasks

### Disable Token Efficiency
Expand Down
4 changes: 2 additions & 2 deletions commands/delegate.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Multi-step workflow orchestration for Claude Code. Main agent enters plan mode (

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

**If ANY write indicator found -> Continue to Step 2 (don't use breadth-reader)**
**If ANY write indicator found -> Continue to Step 2**

### Step 2: Breadth Task Detection

Expand All @@ -44,7 +44,7 @@ Multi-step workflow orchestration for Claude Code. Main agent enters plan mode (
|---------|-------|---------|
| Breadth + Write (same op x many items, with output) | **DIRECT EXECUTION** (skip plan mode) | "review 16 files, create reports" |
| Multi-phase workflow (create -> test -> deploy) | plan mode (EnterPlanMode) | "create calculator with tests and verify" |
| Read-only breadth (no write indicators) | `/breadth-reader {prompt}` | "explore code in X", "summarize files in X" |
| 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.**
Expand Down
18 changes: 7 additions & 11 deletions docs/ARCHITECTURE_PHILOSOPHY.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ Each specialized agent has a restricted tool set that matches its domain:
| All other tools: BLOCKED |
+-------------------------------------------------------------------+
|
/delegate
/workflow-orchestrator:delegate
|
+-------------------------------------------------------------------+
| DELEGATION BOUNDARY |
Expand Down Expand Up @@ -361,11 +361,11 @@ The system uses a 3-step routing check before planning:
| Step 1: Write Detection |
| - Does task require file modifications (Write/Edit)? |
| - YES → Continue to Step 2 |
| - NO → Route to breadth-reader skill (read-only) |
| - NO → Spawn parallel Explore agents or codebase-context-analyzer|
| |
| Step 2: Breadth Task Detection |
| - Is this a breadth task (analyze many files)? |
| - YES → Route to breadth-reader skill |
| - YES → Spawn parallel Explore agents |
| - NO → Continue to Step 3 |
| |
| Step 3: Route Decision |
Expand Down Expand Up @@ -445,7 +445,6 @@ return max(candidates, key=lambda a: a.match_count)

| Agent | Keywords | Tool Access | Use Case |
|-------|----------|-------------|----------|
| breadth-reader (skill) | analyze, explore, read-only | Read, Glob, Grep | Breadth tasks (many files) |
| codebase-context-analyzer | analyze, understand, explore, architecture | Read, Glob, Grep, Bash | Code exploration |
| tech-lead-architect | design, approach, research, best practices | Read, Write, Edit, Glob, Grep, Bash | Solution design |
| task-completion-verifier | verify, validate, test, check, review | Read, Bash, Glob, Grep | QA and validation |
Expand Down Expand Up @@ -521,7 +520,7 @@ sess_def456
```

**Lifecycle:**
1. Created when first `/delegate` triggers session registration
1. Created when first `/workflow-orchestrator:delegate` triggers session registration
2. Populated with session IDs on each delegation
3. Cleared by UserPromptSubmit hook before each user prompt
4. Cleaned of stale sessions (>1 hour) by Stop hook
Expand Down Expand Up @@ -782,8 +781,9 @@ Delegation privileges automatically decay:

+-------------------------------------------------------------------------+
| USER INTERFACE |
| Commands: /delegate, /ask, /bypass, /add-statusline |
| Skills: breadth-reader | Planning: native plan mode |
| Commands: /workflow-orchestrator:delegate, /workflow-orchestrator:ask, |
| /workflow-orchestrator:bypass, /workflow-orchestrator:add-statusline |
| Planning: native plan mode |
| StatusLine: [MODE] Active: N Wave W | Last: Event |
+-------------------------------------------------------------------------+
|
Expand Down Expand Up @@ -813,10 +813,6 @@ Delegation privileges automatically decay:
| | Intent Parsing -> Decomposition -> Agent Selection -> Waves | |
| +-------------------------------------------------------------------+ |
| +-------------------------------------------------------------------+ |
| | breadth-reader (skill) | |
| | Read-only analysis for breadth tasks (many files) | |
| +-------------------------------------------------------------------+ |
| +-------------------------------------------------------------------+ |
| | workflow_orchestrator (system prompt) | |
| | Batched Execution -> Scratchpad Context -> Verification | |
| +-------------------------------------------------------------------+ |
Expand Down
Loading
Loading