Automated, iterative development workflows with persistent project memory
A complete, production-ready task execution system for Claude Code guardrailed by the Agent Envelope Protocol (AEP) and JSONL-based project memories. It implements structured workflows with TDD enforcement, code review loops, and automatic knowledge capture so every task leaves your codebase smarter than before.
This repository provides a copy/paste workflow system for Claude Code that manages:
- ✅ Task execution - Research → Clarification → Plan → Implement ↔ Review → Validation
- ✅ Systematic debugging - 5 Whys root cause analysis with hypothesis testing
- ✅ Code reviews - Comprehensive PR reviews with GitHub-style output
- ✅ Project memory - Persistent JSONL-based knowledge base that learns from every task
Key benefit: Every task makes the next one easier through automatic knowledge capture.
What this repo includes:
- The
.claude/workflow system that plugs into your own projects
- Quick Start
- Directory Structure
- Workflow Overview
- Core Workflows
- Key Features
- Architecture
- Memory System (JSONL Format)
- Configuration
- Customization
- Examples
- Troubleshooting
- Best Practices
- Claude Code installed
- Git repository (recommended)
-
Clone this repository:
git clone https://github.com/yourusername/claude-code-aep-prompt-workflow.git cd claude-code-aep-prompt-workflow -
Copy the
.claude/directory to your project:cp -r .claude /path/to/your/project/
-
(Optional) Install recommended MCP servers:
# Sequential thinking for systematic analysis claude mcp add --transport stdio sequential-thinking -- npx -y @modelcontextprotocol/server-sequential-thinking # Context7 for documentation lookup (requires setup) # See: https://github.com/context7/mcp-server
cd /path/to/your/project
claude
# Inside Claude Code:
/task "Add a simple hello world function with tests"What happens:
- Memory structure initializes automatically
- Research agent analyzes your codebase
- Plan agent creates a technical todo list (
.claude/TODO.md) - Implement agent follows TDD (Red-Green-Refactor)
- Review agent performs systematic code review
- Validation agent verifies completion and saves learnings to memory
The .claude/ directory that powers this workflow looks like:
.claude/
├── README.md # Internal workflow documentation
├── CLAUDE.md # Main memory (auto-imported by Claude Code)
├── settings.local.json # Local settings (optional)
│
├── commands/
│ ├── task.md # /task workflow entry point
│ ├── debug.md # /debug workflow entry point
│ └── code-review.md # /code-review workflow entry point
│
├── agents/
│ ├── research-agent.md # Codebase analysis
│ ├── clarification-agent.md # Critical questions
│ ├── plan-agent.md # Todo list creation
│ ├── implement-agent.md # TDD implementation
│ ├── review-agent.md # Code review
│ ├── validation-agent.md # Final validation & memory updates
│ ├── debug-agent.md # Root cause analysis & debugging
│ └── code-review-agent.md # PR code review specialist
│
├── skills/ # Reusable Claude Code skills (optional)
│ ...
│
└── memories/
├── architecture.jsonl # System design decisions
├── patterns.jsonl # Proven code patterns
├── libraries.jsonl # Library knowledge & gotchas
├── review-standards.jsonl # Quality standards
└── workflow-history.jsonl # Task execution history
At a high level, each /task runs the same end-to-end pipeline:
user → research → clarification → plan → implement ↔ review → validation → user
- research: Understands the codebase and checks existing memories.
- clarification: Asks only critical blocking questions when needed.
- plan: Produces a concrete, test-first technical todo list.
- implement ↔ review: TDD implementation with up to 3 review iterations.
- validation: Verifies the work, updates JSONL memories, and summarizes results back to you.
For a deeper, agent-by-agent breakdown, see .claude/README.md.
Complete TDD workflow with automatic code review:
/task "Add user authentication with JWT tokens"Process: research → clarification → plan → [implement ↔ review] → validation
Output:
- Fully implemented feature with tests
- Updated project memory with patterns and learnings
.claude/TODO.mdwith completed task breakdown
Evidence-based debugging using root cause analysis:
/debug "Database queries timing out in production"Process: symptom analysis → 5 Whys → hypothesis testing → implement fix → validation
Output:
- Root cause identified with evidence
- Fix implemented and tested
- Debug notes saved to memory
Comprehensive technical review with GitHub-style output:
/code-review 123Process: fetch PR diff → 6-category review → generate markdown → save to memory
Output:
temp-123-review.mdwith detailed findings- Severity-based issue classification (🚫 blocking,
⚠️ major, ℹ️ minor) - Actionable fix recommendations
Analyze existing codebase and populate memory:
/memory-initProcess: discover architecture → extract patterns → document libraries → save to memory
Output:
- Populated
.claude/memories/*.jsonlfiles - Architecture decisions documented
- Code patterns identified
The system builds a knowledge base that persists across sessions:
.claude/memories/
├── architecture.jsonl # System design decisions
├── patterns.jsonl # Proven code patterns
├── libraries.jsonl # Third-party library gotchas
├── review-standards.jsonl # Quality standards
└── workflow-history.jsonl # Task execution history
Benefits:
- Research agent checks memory before searching codebase
- Patterns are automatically reused in new implementations
- Past mistakes inform future reviews
- Team knowledge is captured and shared
Every implementation follows Red-Green-Refactor:
- RED - Write failing test first
- GREEN - Implement minimum code to pass
- REFACTOR - Clean up while keeping tests green
No shortcuts. Tests must pass before moving forward.
Systematic 6-point review with automatic iteration:
- Code Quality (naming, clarity, responsibility)
- Type Safety (no
any/Anytypes) - Testing (coverage, edge cases)
- Performance (optimizations)
- Security (no secrets, validation)
- Best Practices (conventions)
Max 3 iterations before escalating to user.
Agents route automatically using the Agent Envelope Protocol (AEP):
user → research → clarification → plan → implement ↔ review → validation → user
No permission requests between stages. Fully automated pipeline.
| Agent | Responsibility | Tools |
|---|---|---|
| research-agent | Checks memory, analyzes codebase | Read, Grep, Glob, sequential-thinking, context7 |
| clarification-agent | Asks critical questions only | Read, sequential-thinking |
| plan-agent | Creates technical todo list | Read, Grep, sequential-thinking, context7 |
| implement-agent | TDD implementation | Read, Edit, Bash, context7 |
| review-agent | Systematic code review | Read, Grep, Glob, Bash, sequential-thinking |
| validation-agent | Verifies completion, updates memory | Read, Edit, Bash, sequential-thinking |
- debug-agent - 5 Whys root cause analysis, hypothesis testing
- code-review-agent - PR-specific review with tech stack expertise
Memory files use JSONL (JSON Lines) for efficient updates:
- ✅ Append-only without parsing entire file
- ✅ Better git diffs (line-by-line changes)
- ✅ Automatic compaction at 100KB or 200 entries
{"id":"auth-system","type":"architecture","name":"JWT Authentication","when":"2025-11-05","decision":"Centralized JWT auth service","rationale":"Stateless validation across services","files":["auth/jwt.ts"],"tradeoffs":"Benefits: scalable. Limitations: token revocation requires blacklist","dependencies":["jsonwebtoken"],"related":["session-mgmt"],"updated":"2025-11-05"}The workflow dynamically discovers and uses available MCP servers:
# Check what's available
claude mcp listRecommended MCPs:
- sequential-thinking - Systematic analysis (all agents)
- context7 - Documentation lookup (research, plan, implement)
Not required - Workflow works without MCPs, but they enhance quality.
- Create
.claude/agents/your-agent.md - Add to workflow chain in
commands/task.md - Update routing in adjacent agents
See .claude/README.md for details.
- Create
.claude/memories/your-category.jsonl - Add import to
.claude/CLAUDE.md - Update validation-agent to append to it
- Update research-agent to check it
Edit .claude/memories/review-standards.jsonl to add project-specific rules.
/task "Add logout button to header"Result:
- Button component created
- Logout handler implemented
- Unit tests passing
- Memory updated with logout pattern
Time: ~2-3 minutes (depends on codebase size)
/task "Implement real-time notifications with WebSocket"Workflow:
- Research: No WebSocket in memory, searches codebase
- Clarification: Asks about connection strategy, fallback options
- Plan: 8 todos sequenced for TDD
- Implement: Uses context7 to look up WebSocket best practices
- Review: 2 iterations (adds error handling, improves reconnection)
- Validation: Saves WebSocket pattern, library knowledge, architecture
Memory Created:
patterns.jsonl- WebSocket connection patternlibraries.jsonl- ws library usage and gotchasarchitecture.jsonl- Real-time system designworkflow-history.jsonl- Complete implementation record
Time: ~10-15 minutes
/debug "Users getting 500 errors on form submission"Process:
- Symptom Analysis: Reproduce error, check logs
- 5 Whys Analysis:
- Why 500 error? → Missing validation
- Why missing? → Refactor removed it
- Why not caught? → Missing test coverage
- Why no coverage? → Test file not updated
- Root Cause: Incomplete refactor, missing tests
- Hypothesis: Add validation + tests (95% confidence)
- Fix: Implements validation with TDD
- Validation: Confirms error resolved, updates memory
Memory Created:
- Debug investigation notes
- Validation pattern documented
- Test coverage requirement reinforced
Time: ~5-10 minutes
/code-review 456Output: temp-456-review.md
# Code Review: PR #456
**Overall Status**: CHANGES_REQUESTED
## Files Reviewed
- `auth.py` (+34, -12)
- `auth.ts` (+45, -20)
## Detailed Findings
### 🚫 [blocking] Silent Fallback for SECRET_KEY
**File**: `config.py:15`
SECRET_KEY = os.getenv("SECRET_KEY", "default-secret")
**Issue:** Silent fallback compromises security...
**Fix:** Fail fast with explicit error...
### ⚠️ [major] Missing Test Coverage
...
## Action Items
1. 🚫 **2 Blocking Issues** - Must fix before merge
2. ⚠️ **1 Major Issue** - Should fix before mergeTime: ~3-5 minutes
Symptoms: Agent completes but doesn't route to next agent
Solution:
- Check agent files have
<<<AGENT:COMPLETE>>>blocks - Verify
route_to:field is set correctly - Ensure no text after
<<<END:COMPLETE>>>marker
Symptoms: Multiple test/build processes accumulating
Solution:
- Check for orphaned background processes:
ps aux | grep -E "npm|node|vite|webpack" | grep -v grep
- Kill manually:
pkill -f "npm.*test"
Prevention: Workflow now has strict process management (max 1-2 background tasks per agent).
Symptoms: Research agent doesn't find past patterns
Solution:
- Verify
.claude/CLAUDE.mdimports all memory files - Check memory files use
.jsonlextension - Re-run
/taskto reinitialize structure
Good: /task "Add JWT-based authentication with refresh tokens to the API"
Bad: /task "Add auth"
More detail = better research and planning.
git add .claude/memories/
git commit -m "docs: update project memory"Benefits:
- Team shares knowledge
- Track memory evolution
- Onboard new developers faster
After a few executions, the system will:
- Recognize similar tasks
- Apply proven patterns automatically
- Avoid past gotchas
- Speed up implementation
Check .claude/memories/*.jsonl files to:
- Ensure accuracy
- Consolidate duplicate patterns
- Update outdated information
Automatic compaction happens at 100KB or 200 entries.