Skip to content

Feature: Optional orchestrator-only mode - enforce subagent usage for all work #14

@edmondscommerce

Description

@edmondscommerce

Summary

Create an optional set of hooks that enforce a pure orchestration model: the main Claude Code thread becomes a pure orchestrator and is blocked from doing any actual work. All coding, testing, file operations, and other work must be delegated to subagents.

Motivation

Currently, Claude Code can perform work directly in the main thread or delegate to subagents. This leads to:

  • Inconsistent patterns where some work is done inline vs delegated
  • Harder to enforce separation of concerns
  • Difficult to track which agent actually performed work

An orchestrator-only mode would:

  • Force clean separation: orchestration vs execution
  • Enable better telemetry and observability
  • Potentially improve quality by always using specialized subagents
  • Make it easier to reason about agent behavior

Proposed Solution

Hook-Based Enforcement

Create new PreToolUse handlers that intercept "work" tools when in orchestrator mode:

  • Block: Edit, Write, Bash (coding commands), direct code modifications
  • Allow: Task (subagent spawning), Read, Glob, Grep (read-only exploration)
  • Allow: AskUserQuestion, communication tools

The hooks would be optional - users opt-in via config:

handlers:
  pre_tool_use:
    orchestrator_mode:
      enabled: true  # Default: false
      priority: 15   # Run early, block before execution

Research Phase

Use the new debug infrastructure (scripts/debug_hooks.sh) to:

  1. Capture real workflows: Record actual Claude Code sessions doing various tasks
  2. Analyze tool usage patterns: Which tools are "work" vs "orchestration"?
  3. Identify edge cases: When should main thread be allowed to work?
  4. Design handler logic: Precise rules for what gets blocked

Example debug session:

./scripts/debug_hooks.sh start "Coding task analysis"
# User: "Add a login feature"
# Observe: Which tools fire? When? What's delegated vs inline?
./scripts/debug_hooks.sh stop

Implementation Phases

Phase 1: Research & Design

  • Use debug mode to capture 5-10 different workflow types
  • Document tool usage patterns
  • Design exact blocking rules
  • Write design doc with examples

Phase 2: Handler Implementation

  • Create handlers/pre_tool_use/orchestrator_mode.py
  • Implement tool classification logic
  • Add comprehensive tests

Phase 3: Validation

  • Test with real workflows
  • Tune blocking rules based on usability
  • Document best practices

Technical Details

Tools Classification (Initial Draft)

Block (work tools):

  • Edit, Write, NotebookEdit - file modifications
  • Bash with certain patterns - code execution, git commits, etc.
  • Direct code manipulation

Allow (orchestration tools):

  • Task - subagent spawning
  • Read, Glob, Grep - exploration/research
  • AskUserQuestion - user interaction
  • TaskCreate, TaskUpdate, TaskList - task management

Context-Dependent:

  • Bash for read-only operations (git log, ls, etc.) - maybe allow?
  • Need research to determine

Handler Structure

class OrchestratorModeHandler(Handler):
    def __init__(self) -> None:
        super().__init__(
            name="orchestrator-mode",
            priority=15,  # Early, before work happens
            terminal=True
        )
    
    def matches(self, hook_input: dict) -> bool:
        tool_name = hook_input.get("tool_name")
        # Return True if tool is "work" that should be delegated
        return tool_name in ["Edit", "Write", "Bash", ...]
    
    def handle(self, hook_input: dict) -> HookResult:
        return HookResult(
            decision="deny",
            reason="Orchestrator mode: Please use Task tool to spawn subagent for this work",
            context={"blocked_tool": hook_input.get("tool_name")}
        )

Config Schema

Extend .claude/hooks-daemon.yaml:

handlers:
  pre_tool_use:
    orchestrator_mode:
      enabled: false  # Opt-in
      priority: 15
      allow_read_only_bash: true  # Allow safe bash commands?
      custom_allowed_tools: []     # User-defined exceptions

Next Steps

  1. Use scripts/debug_hooks.sh to capture 10+ real workflow sessions
  2. Analyze logs to understand tool usage patterns
  3. Draft precise blocking rules (design doc)
  4. Implement handler with tests
  5. Validate with real usage
  6. Document in CLAUDE/HANDLER_DEVELOPMENT.md

References

  • Debug infrastructure: CLAUDE/DEBUGGING_HOOKS.md
  • Handler development guide: CLAUDE/HANDLER_DEVELOPMENT.md
  • Existing safety handlers: handlers/pre_tool_use/destructive_git.py
  • Hook event types: daemon/events.py

Labels

enhancement, handlers, research-needed

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions