When you type “help me build a system” into Claude, the model needs to simultaneously play the roles of architecture design, code writing, quality review, and performance optimization. The community has found that splitting these four roles into a pipeline significantly improves output quality.
Four-Role Division
This workflow splits a Claude conversation into four stages, each with independent role settings and output requirements:
| Role | Responsibility | Output |
|---|---|---|
| Architect | Understand requirements, design system architecture, determine tech stack | Architecture diagram, module division, interface definitions, tech decision records |
| Engineer | Implement code based on architecture, write tests | Complete code, unit tests, integration tests |
| Reviewer | Review code quality, security, maintainability | Code review report, issue list, fix suggestions |
| Optimizer | Performance tuning, refactoring, documentation | Optimized code, performance benchmarks, usage docs |
Why It Works
The core advantage is role isolation reducing cognitive load. When Claude focuses on a single role:
- The Architect doesn’t get bogged down in implementation details and can think more strategically about system design
- The Engineer, with clear architecture documents, implements more efficiently
- The Reviewer, in a “find faults” mindset, catches issues more easily than when the same model “self-reviews”
- The Optimizer works on stable code for performance improvements, avoiding the rework caused by “optimizing while writing”
Step-by-Step Guide
Step 1: Architect Phase
You are a senior system architect. Please design the system architecture based on the following requirements:
Requirements: [describe your project needs]
Please output:
1. System architecture diagram (describe module relationships in text)
2. Technology choices and reasoning
3. Module division and interface definitions
4. Potential risks and mitigation plans
Note: Output design only, no code.
Step 2: Engineer Phase
You are a senior engineer. Here is the system architecture design:
[Paste Architect's output]
Please implement the code based on the architecture design. Requirements:
1. Implement module by module
2. Each module includes unit tests
3. Follow the tech choices defined in the architecture
4. Code comments should be clear
Note: Strictly follow the architecture design. If there are issues, annotate them in code comments.
Step 3: Reviewer Phase
You are a senior code reviewer. Here is the implemented code:
[Paste Engineer's output]
Please review from these dimensions:
1. Code quality and readability
2. Compliance with architecture design
3. Security issues
4. Test coverage
5. Error handling completeness
Output format: Severity + Location + Issue Description + Fix Suggestion
Step 4: Optimizer Phase
You are a performance optimization expert. Here is the reviewed code and review report:
[Paste original code + Reviewer's output]
Please:
1. Fix Critical and Warning level issues
2. Perform performance optimization
3. Improve documentation and comments
4. Output the final version and optimization notes
Cost and Limitations
Cost: Four API calls, token consumption is approximately 2-3x of a single call. With Claude Sonnet, a medium project’s four-round conversation consumes about 50-150K tokens, costing approximately $0.5-5 per session.
Limitations:
- Context window limits: For large codebases, you need to split and pass context between stages
- Role switch “forgetting”: The model may miss details from previous stages during role switches — explicitly reference them in prompts
- Not suitable for small tasks: For simple tasks, a single-role prompt is more cost-effective
Applicable Scenarios
- ✅ Suitable: Medium to large projects, projects requiring multi-stage design, pre-research before team collaboration
- ⚠️ Can use: Small projects but wanting to improve code quality
- ❌ Not suitable: Rapid prototyping, one-off scripts, simple data transformations
Primary sources:
- Anthropic Claude Official: https://www.anthropic.com/claude
- Community developer testing and sharing