Agents Architecture
Relevant source files
The following files were used as context for generating this wiki page:
- cli-tool/docs_to_claude/SUBAGENTS_GUIDE.md
- cli-tool/components/skills/development/agent-development/SKILL.md
- cli-tool/components/agents/documentation/arch.md
- cli-tool/components/agents/expert-advisors/custom-agent-foundry.md
- cli-tool/components/skills/development/agent-development/references/system-prompt-design.md
- cli-tool/components/skills/development/agent-development/examples/complete-agent-examples.md
Agents in Claude Code are specialized, autonomous sub-processes designed to handle complex, multi-step tasks independently. Each agent operates within its own context, separate from the main conversation, and is fine-tuned with specific instructions and toolsets to act as a domain expert (e.g., security auditor, code reviewer, or architect).
Sources: cli-tool/docs_to_claude/SUBAGENTS_GUIDE.md:6-14, cli-tool/components/skills/development/agent-development/SKILL.md:10-15
The architecture relies on a Progressive Disclosure principle, where high-level orchestration is handled at the root, while deep technical domain knowledge is encapsulated within specialized agent files. This structure prevents context contamination and allows for reusable, shareable expertise across different projects.
Sources: cli-tool/docs_to_claude/SUBAGENTS_GUIDE.md:17-25, cli-tool/components/skills/development/agent-md-refactor/SKILL.md:12-14
Core Component Structure
Agents are defined as Markdown files containing two primary sections: a YAML frontmatter for configuration and a Markdown body for the system prompt.
1. Configuration (YAML Frontmatter)
The frontmatter defines the agent's identity, its triggering conditions for the LLM, and its technical constraints (model and tools).
| Field | Requirement | Description |
|---|---|---|
name | Required | Unique identifier (lowercase, hyphens only). |
description | Required | Natural language description defining when the agent should be invoked. |
tools | Optional | Comma-separated list or array of permitted tools (e.g., Read, Write, Bash). |
model | Optional | The specific Claude model to use (sonnet, opus, haiku, or inherit). |
color | Required* | Visual identifier for the UI (e.g., blue, green, red). |
Sources: cli-tool/docs_to_claude/SUBAGENTS_GUIDE.md:46-77, cli-tool/components/skills/development/agent-development/SKILL.md:44-98
2. System Prompt (Markdown Body)
The body of the file serves as the agent's operational logic, defining its role, responsibilities, and step-by-step processes. Effective prompts follow a structured pattern:
- Identity: "You are a [Role] specialized in [Domain]."
- Core Responsibilities: A prioritized list of tasks.
- Process/Workflow: Concrete steps the agent takes when invoked.
- Quality Standards: Measurable criteria for success.
- Output Format: Explicitly defined structure for responses.
Sources: cli-tool/components/skills/development/agent-development/references/system-prompt-design.md:5-30, cli-tool/components/skills/development/agent-development/SKILL.md:106-135
Agent Lifecycle and Workflow
The following diagram illustrates how an agent is triggered and executes a task within the Claude Code environment.
The "Orchestrator" matches the user's intent against agent description fields, often looking for keywords like "Use PROACTIVELY" to automate the invocation.
Sources: cli-tool/docs_to_claude/SUBAGENTS_GUIDE.md:58-61, cli-tool/components/skills/development/agent-development/SKILL.md:13-15
Specialized Archetypes
Agents are typically designed around specific architectural roles to ensure clear boundaries and "least privilege" tool access.
Planner vs. Implementation Agents
- Planner Agents: Focus on research and analysis. They typically have read-only tools (
search,grep,read_file) and output structured implementation plans. - Implementation Agents: Focus on applying changes. They are granted editing tools (
replace_string_in_file,create_file,run_in_terminal).
Sources: cli-tool/components/agents/expert-advisors/custom-agent-foundry.md:46-60
Handoff Mechanisms
Complex workflows utilize a "handoff" architecture where one agent completes a phase and suggests the next.
File System Organization
Agents are prioritized based on their location in the file system, allowing for project-specific overrides of global settings.
| Type | Path | Priority |
|---|---|---|
| Project Agents | .claude/agents/ | High (Project-specific expertise) |
| User Agents | ~/.claude/agents/ | Low (Global reusable expertise) |
Sources: cli-tool/docs_to_claude/SUBAGENTS_GUIDE.md:31-38
Design Patterns for System Prompts
To ensure high-quality autonomous operation, agents utilize specific prompt patterns based on their functional type:
- Analysis Pattern: Uses a "Gather Context -> Scan -> Deep Analysis -> Prioritize" workflow.
- Generation Pattern: Follows "Understand -> Gather Context -> Design -> Generate -> Validate".
- Validation Pattern: Operates via "Load Criteria -> Scan Target -> Check Rules -> Determine Result".
Sources: cli-tool/components/skills/development/agent-development/references/system-prompt-design.md:32-110
Example: Resource Constraints (Tools)
Agents should follow the principle of least privilege by restricting tools to only what is necessary for their role:
# Security Auditor (Read-only for safety)
tools: [Read, Bash, Grep, Glob]
# Test Runner (Requires execution)
tools: [Read, Edit, Bash, Write]
Sources: cli-tool/docs_to_claude/SUBAGENTS_GUIDE.md:131-133, cli-tool/docs_to_claude/SUBAGENTS_GUIDE.md:204-206
Summary
The Agents Architecture provides a modular, domain-driven framework for extending Claude Code's capabilities. By separating configuration (triggers and tools) from logic (system prompts), the system enables specialized AI assistants to operate autonomously within controlled boundaries. This ensures that complex tasks like architectural review, security auditing, and feature development are handled by "experts" with the appropriate context and authority.
Sources: cli-tool/docs_to_claude/SUBAGENTS_GUIDE.md:316-324, cli-tool/components/agents/expert-advisors/custom-agent-foundry.md:164-175