Summary
Implement Claude Code hooks to monitor and orchestrate subagent completion. The "shepherd" pattern uses SubagentStop hooks to validate subagent work, enforce quality gates, and suggest follow-up actions.
Motivation
DevFlow spawns many subagents (Coder, Explore, Review-*, Synthesize). Currently there's no automatic validation that:
- Coder agents actually made changes
- Review agents provided thorough analysis (not rubber-stamp)
- Explore agents found actionable results
- Synthesize didn't lose critical findings
Hooks provide deterministic enforcement vs skills (AI-judged) or commands (user-invoked).
Technical Approach
SubagentStop Hook Mechanics
- Input: Minimal -
session_id, transcript_path, cwd, stop_hook_active
- Output:
{"decision": "approve"|"block", "reason": "...", "systemMessage": "..."}
- Subagent identification: Must parse transcript file (JSONL) to identify which agent completed
- Two types:
command (fast, deterministic) or prompt (LLM-evaluated, context-aware)
Proposed Shepherd Patterns
Pattern 1: Post-Coder Review Gate
Block Coder completion for security-sensitive or large changes without review:
{
"type": "prompt",
"prompt": "If Coder agent completed code changes touching auth/crypto/keys OR >50 lines without tests: block and require SecurityReview"
}
Pattern 2: Review Quality Gate
Prevent shallow "looks good" reviews:
{
"type": "prompt",
"prompt": "If Review agent completed: verify it analyzed actual files, provided file:line references, checked multiple concerns. Block if rubber-stamp."
}
Pattern 3: Explore Completeness
Ensure exploration returned useful results:
{
"type": "prompt",
"prompt": "If Explore agent completed: verify it found relevant files/patterns with concrete paths. Block if inconclusive."
}
Pattern 4: Chain Trigger (Non-blocking)
Suggest logical next steps without blocking:
{
"type": "prompt",
"prompt": "Analyze completed subagent. Approve but suggest next step in systemMessage: Coder→review, Explore→plan, Review→fix"
}
Implementation Options
| Approach |
Speed |
Intelligence |
Maintenance |
type: "prompt" |
Slow (API) |
High |
Low |
type: "command" |
Fast |
Rules-based |
Higher |
| Hybrid |
Medium |
Best of both |
Medium |
Proposed File Structure
.claude/
├── settings.json # Hook configuration
└── hooks/
├── shepherd.py # Main shepherd logic
└── transcript-parser.py # Utility for reading JSONL transcripts
Or ship hooks via DevFlow install to ~/.devflow/hooks/.
Acceptance Criteria
Open Questions
- Ship hooks via
devflow init or keep as opt-in configuration?
- Default to
command (fast) or prompt (smart) hooks?
- How aggressive should blocking be? (strict vs suggestive)
- Should hooks write to
.docs/ for audit trail?
References
- Claude Code Hooks Guide
- SubagentStop receives:
session_id, transcript_path, cwd, stop_hook_active, hook_event_name
- Transcript format: JSONL with
type, role, content, id, timestamp per message
Summary
Implement Claude Code hooks to monitor and orchestrate subagent completion. The "shepherd" pattern uses
SubagentStophooks to validate subagent work, enforce quality gates, and suggest follow-up actions.Motivation
DevFlow spawns many subagents (Coder, Explore, Review-*, Synthesize). Currently there's no automatic validation that:
Hooks provide deterministic enforcement vs skills (AI-judged) or commands (user-invoked).
Technical Approach
SubagentStop Hook Mechanics
session_id,transcript_path,cwd,stop_hook_active{"decision": "approve"|"block", "reason": "...", "systemMessage": "..."}command(fast, deterministic) orprompt(LLM-evaluated, context-aware)Proposed Shepherd Patterns
Pattern 1: Post-Coder Review Gate
Block Coder completion for security-sensitive or large changes without review:
{ "type": "prompt", "prompt": "If Coder agent completed code changes touching auth/crypto/keys OR >50 lines without tests: block and require SecurityReview" }Pattern 2: Review Quality Gate
Prevent shallow "looks good" reviews:
{ "type": "prompt", "prompt": "If Review agent completed: verify it analyzed actual files, provided file:line references, checked multiple concerns. Block if rubber-stamp." }Pattern 3: Explore Completeness
Ensure exploration returned useful results:
{ "type": "prompt", "prompt": "If Explore agent completed: verify it found relevant files/patterns with concrete paths. Block if inconclusive." }Pattern 4: Chain Trigger (Non-blocking)
Suggest logical next steps without blocking:
{ "type": "prompt", "prompt": "Analyze completed subagent. Approve but suggest next step in systemMessage: Coder→review, Explore→plan, Review→fix" }Implementation Options
type: "prompt"type: "command"Proposed File Structure
Or ship hooks via DevFlow install to
~/.devflow/hooks/.Acceptance Criteria
stop_hook_activecheck to prevent infinite loopsOpen Questions
devflow initor keep as opt-in configuration?command(fast) orprompt(smart) hooks?.docs/for audit trail?References
session_id,transcript_path,cwd,stop_hook_active,hook_event_nametype,role,content,id,timestampper message