Agentic Architecture Patterns
These hooks implement patterns from the "17 Agentic Architectures" to improve how Claude Code works.
Implemented Patterns
1. Reflection (reflection-gate.sh)
Trigger: After Write/Edit of significant code files (50+ lines) What it does: Signals that self-critique should occur before presenting final code Inspired by: Architecture #1 - Reflection Pattern
Generate → Critique → Refine → Present
2. PEV Verification (pev-verification.sh)
Trigger: Before/after Bash commands, especially commits and deployments What it does: Runs verification checks (types, lint, tests, security) Inspired by: Architecture #6 - Plan-Execute-Verify
Plan → Execute → Verify → If Failed: Re-plan
Checks performed:
- TypeScript type errors (
tsc --noEmit) - Lint issues (
npm run lint) - Test failures (
npm test) - Git sanity (merge conflicts, large diffs)
- Security (exposed secrets in staged changes)
3. Metacognitive (metacognitive-check.sh)
Trigger: On user prompt submit What it does: Detects high-stakes or speculative requests, prompts confidence signaling Inspired by: Architecture #17 - Reflexive Metacognitive
Detection keywords:
- High-stakes: production, security, payment, medical, legal, compliance, HIPAA, GDPR
- Speculative: best practice, should I, recommend, opinion, predict
Instructions (in CLAUDE.md)
In addition to hooks, behavioral instructions are added to CLAUDE.md:
- Pattern 1: Reflection - Self-critique significant code before presenting
- Pattern 2: PEV - Verify outcomes before commits
- Pattern 3: Metacognitive - Express confidence levels, say "I don't know"
- Pattern 4: Tree of Thoughts - Multiple approaches for complex problems
- Pattern 5: Ensemble - Multi-perspective analysis for important decisions
Hook Registration
Hooks are registered in ~/.claude/hooks.json:
{
"post-tool": {
"Write": ["agentic/reflection-gate.sh", ...],
"Edit": ["agentic/reflection-gate.sh", ...],
"Bash": ["agentic/pev-verification.sh"]
},
"user-prompt-submit": [
"agentic/metacognitive-check.sh",
...
],
"pre-tool": {
"Bash": ["agentic/pev-verification.sh"]
}
}
Debugging
Logs are written to:
~/.claude/debug/reflection-gate.log~/.claude/debug/pev-verification.log~/.claude/debug/metacognitive.log
Session state files:
~/.claude/session-env/pending-reflection.json~/.claude/session-env/pev-report.json~/.claude/session-env/confidence-context.json
Source Material
These patterns are based on:
- Repository:
~/Development/all-agentic-architectures/ - Notebooks: 01_reflection.ipynb, 06_PEV.ipynb, 17_reflexive_metacognitive.ipynb
- Original author: Fareed Khan