๐ค Claude Code Teams
Agent Teams is an experimental feature in Claude Code that enables sophisticated multi-agent workflows through subagent orchestration.
๐ Overview
Claude Code Teams allows you to:
- Spawn specialized subagents for specific tasks
- Coordinate multiple agents through hooks and session data
- Build composable workflows with isolated, focused agents
- Maintain context across agent interactions
๐ Getting Started
Enable Agent Teams
The feature is controlled by an environment variable in configs/claude/settings.json:
{
"env": {
"CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
}
}
This is already enabled in this repository.
๐ฏ Agent Configuration
Agent Definition Format
Agents are defined in markdown files with YAML frontmatter:
---
name: agent-name
description: Brief description of what this agent does
mode: subagent
temperature: 0.1
---
# Agent Instructions
Your detailed instructions and guidelines here...
Agent Properties
| Property | Required | Description | Values |
|---|---|---|---|
name |
Yes | Unique identifier for the agent | kebab-case string |
description |
Yes | Brief purpose statement | Plain text |
mode |
Yes | Agent execution mode | subagent, coordinator |
temperature |
No | Creativity level (0-1) | Default: 0.7 |
Directory Structure
configs/claude/
โโโ agents/ # Agent definitions
โ โโโ ai-slop-remover.md # Existing example
โ โโโ code-reviewer.md # Example worker agent
โ โโโ team-coordinator.md # Example coordinator
โโโ hooks/ # Agent coordination hooks
โ โโโ index.ts # Hook implementations
โ โโโ lib.ts # Hook utilities
โ โโโ session.ts # Session data management
โโโ settings.json # Global configuration
๐ง Agent Types
1. Subagent (Worker)
Specialized agents that handle specific tasks:
---
name: code-reviewer
description: Reviews code for quality, style, and potential issues
mode: subagent
temperature: 0.2
---
You are an expert code reviewer...
Use Cases:
- Code quality analysis
- Security scanning
- Test generation
- Documentation writing
- Refactoring tasks
2. Coordinator
Orchestrates multiple subagents:
---
name: team-coordinator
description: Coordinates multiple specialized agents for complex tasks
mode: coordinator
temperature: 0.5
---
You coordinate specialized agents to solve complex problems...
Use Cases:
- Multi-stage workflows
- Parallel task execution
- Result aggregation
- Task delegation
๐จ Team Patterns
Pattern 1: Sequential Specialist Chain
Agents process work in sequence, each adding value:
Coordinator โ Implementer โ Reviewer โ Documenter
Example Workflow:
- Coordinator analyzes requirements and creates plan
- Implementer writes code following the plan
- Reviewer checks code quality and suggests improvements
- Documenter adds comprehensive documentation
Pattern 2: Parallel Workers
Multiple agents work simultaneously on independent tasks:
โโ Frontend Agent
Coordinator โโโโโโผโ Backend Agent
โโ Database Agent
Example Workflow:
- Coordinator breaks feature into frontend/backend/database
- Agents work in parallel on their components
- Coordinator integrates results
Pattern 3: Iterative Refinement
Agent refines work through multiple passes:
Draft Agent โ Review Agent โ Polish Agent โ Review Agent โ Final Agent
Example Workflow:
- Draft Agent creates initial implementation
- Review Agent identifies issues
- Polish Agent addresses feedback
- Repeat until quality threshold met
๐ช Hook Integration
SubagentStop Hook
Triggered when a subagent completes:
// configs/claude/hooks/index.ts
import { SubagentStop } from "./lib";
export const hooks = {
SubagentStop: SubagentStop,
};
Hook Implementation:
// configs/claude/hooks/lib.ts
export function SubagentStop(event: SubagentEvent) {
// Access subagent results
const result = event.result;
// Save data for coordination
saveSessionData({
agentName: event.agentName,
output: result,
timestamp: new Date().toISOString(),
});
// Return modified result if needed
return result;
}
Session Data Management
Share data between agents:
// configs/claude/hooks/session.ts
interface SessionData {
[key: string]: any;
}
export function saveSessionData(data: SessionData): void {
// Save to persistent storage
}
export function getSessionData(key: string): any {
// Retrieve from storage
}
๐ Example: Code Quality Team
Team Structure
configs/claude/agents/
โโโ code-quality-coordinator.md # Orchestrates quality checks
โโโ style-checker.md # Checks code style
โโโ security-scanner.md # Scans for vulnerabilities
โโโ performance-analyzer.md # Analyzes performance
Coordinator Definition
---
name: code-quality-coordinator
description: Orchestrates comprehensive code quality checks
mode: coordinator
temperature: 0.3
---
# Code Quality Coordinator
You coordinate specialized agents to ensure code quality:
1. **Style Checker** - Verifies code adheres to style guidelines
2. **Security Scanner** - Identifies potential security issues
3. **Performance Analyzer** - Detects performance bottlenecks
## Process
1. Analyze the code changes
2. Delegate to appropriate specialists
3. Aggregate findings
4. Prioritize issues by severity
5. Generate comprehensive report
## Output Format
Provide a structured report with:
- Summary of all issues found
- Severity classification (critical/high/medium/low)
- Actionable recommendations
- Priority order for fixes
Worker Agent Example
---
name: security-scanner
description: Scans code for security vulnerabilities and best practices
mode: subagent
temperature: 0.1
---
# Security Scanner
You are an expert security analyst specializing in code security.
## Your Mission
Scan code for:
- SQL injection vulnerabilities
- XSS attack vectors
- Authentication/authorization issues
- Sensitive data exposure
- Insecure dependencies
- Cryptographic weaknesses
## Analysis Process
1. Review all code changes
2. Identify security-relevant code paths
3. Check against OWASP Top 10
4. Validate input sanitization
5. Verify output encoding
## Output Format
Report findings as:
```json
{
"severity": "critical|high|medium|low",
"type": "vulnerability-type",
"location": "file:line",
"description": "Clear explanation",
"recommendation": "Specific fix"
}
```
๐ Best Practices
1. Single Responsibility
Each agent should have a clear, focused purpose:
โ Good:
name: typescript-type-checker
description: Validates TypeScript type safety
โ Bad:
name: code-improver
description: Fixes all code issues
2. Clear Interfaces
Define expected inputs and outputs:
## Inputs
- File path(s) to analyze
- Analysis scope (full/changes only)
## Outputs
- List of issues found
- Confidence score (0-100)
- Suggested fixes
3. Temperature Tuning
- 0.0-0.3: Deterministic tasks (linting, security scanning)
- 0.3-0.5: Balanced tasks (code review, refactoring)
- 0.5-0.7: Creative tasks (architecture, design)
- 0.7-1.0: Exploratory tasks (brainstorming, alternatives)
4. Error Handling
Agents should gracefully handle failures:
## Error Handling
If unable to complete analysis:
1. Report specific error encountered
2. Suggest alternative approaches
3. Indicate which parts succeeded
4. Provide partial results if possible
5. Coordination Protocol
Establish communication patterns:
## Coordination
When delegating to this agent:
- Provide: file paths, context, specific concerns
- Expect: JSON report within 2 minutes
- Handle: timeout with partial results
๐ Troubleshooting
Agent Not Found
Symptom: Error: "Agent 'agent-name' not found"
Solution:
- Verify file exists in
configs/claude/agents/ - Check filename matches agent
nameproperty - Ensure YAML frontmatter is valid
Subagent Not Triggering
Symptom: Subagent doesn't spawn
Solution:
- Verify
CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS: "1"in settings.json - Check agent
mode: subagentis set - Review hook configuration
Hook Not Executing
Symptom: SubagentStop hook doesn't run
Solution:
- Verify hooks directory structure
- Check TypeScript compilation
- Review hook registration in
hooks/index.ts
๐ Additional Resources
- Agent Definition Example
- Agent Teams Usage Examples - Practical examples and workflows
- Hook Implementation
- Session Management
- Claude Code Settings
๐ Next Steps
- Review existing agent - Study
ai-slop-remover.mdfor reference - Try the examples - See agent-teams-examples.md for practical workflows
- Create your first agent - Start with a simple subagent
- Test coordination - Use SubagentStop hook for data sharing
- Build a team - Create complementary agents that work together
Questions? Check Learning Stories for real-world examples of subagent workflows.