Spec-Driven Delegation

Description

Spec-driven delegation is the principle that agent prompts must be self-contained briefings containing exact files, expected signatures, and output formats rather than vague directives. In the Claude Code source, the coordinator system prompt (in coordinatorMode.ts) and the agent prompt module (tools/AgentTool/prompt.ts) enforce this at the prompt-engineering level: the coordinator is told to "synthesize findings into a specific prompt" and to "never write 'based on your findings, fix the bug'" because such phrases delegate understanding to the worker instead of doing it.

The pattern manifests across three layers. First, the coordinator prompt in coordinatorMode.ts provides explicit anti-patterns (lazy delegation examples like "fix the bug we discussed") alongside good examples that include file paths, line numbers, and the exact behavioral change required. Second, the fork-subagent prompt in forkSubagent.ts enforces a rigid output contract on forked children: output must begin with "Scope:", followed by "Result:", "Key files:", "Files changed:", and "Issues:" sections. Third, agent definitions in loadAgentsDir.ts structurally constrain each agent type with tools, disallowedTools, permissionMode, and omitClaudeMd fields, ensuring the delegation boundary is enforced at the tool-access level, not just by prompt wording.

The anti-pattern this addresses is the "handle the frontend" class of vague delegation. Without spec-driven prompts, an agent with full tool access might rewrite routing, refactor components, or add unwanted libraries. Claude Code's architecture prevents this through both prompt guidance ("Brief the agent like a smart colleague who just walked into the room") and structural constraints (read-only agents literally lack the Edit and Write tools).

Key claims

Relations

Sources

src-20260410-spec-delegation-a: src/coordinator/coordinatorMode.ts, src/tools/AgentTool/prompt.ts, src/tools/AgentTool/forkSubagent.ts, src/tools/AgentTool/loadAgentsDir.ts