One of the most powerful features of Claude Code is its agent system. While basic usage involves you typing a request and getting a response, agents take this further by automating multi-step workflows, running specialized analysis, and coordinating parallel tasks. If you have ever wanted to automate your entire code review process, run a security audit across your codebase, or execute a full development pipeline from planning to deployment, agents make that possible.
What Agents Are
An agent in Claude Code is a specialized configuration that defines how Claude approaches a specific type of task. Think of it as a role with specific instructions, tools, and objectives. When you invoke an agent, Claude Code takes on that role and works toward the defined goal.
Each agent has several key properties. It has a model assignment that determines which Claude model it uses, since complex analysis needs Opus while quick checks can use Haiku. It has system instructions that define its expertise and approach. It has tools it can access, such as file reading, command execution, and git operations. And it has an objective that defines what success looks like.
The basic categories of agents cover the entire development lifecycle.
Code quality agents handle reviews, refactoring, and cleanup. An architect-guardian agent reviews code for structural issues. A code-janitor agent cleans up after rapid implementation. A refactor-architect agent identifies files that have grown too large and proposes how to break them down.
Testing agents design test strategies, generate tests, and analyze coverage gaps. A test-architect agent examines your code and determines what tests are missing. A test-runner agent executes tests, analyzes failures, and can iterate on fixes until the suite passes.
Security agents perform specialized security analysis. A chaos-monkey agent stress-tests your implementation for edge cases and vulnerabilities. A dependency-sentinel agent scans your dependencies for known vulnerabilities and outdated packages.
Pipeline agents coordinate multiple steps in sequence. A pipeline-orchestrator agent runs through planning, implementation, testing, review, and deployment in one automated flow.
Using Built-in Agents
Claude Code comes with a set of built-in agents that you can invoke for common tasks. These are pre-configured with appropriate model assignments and instructions.
For code review before creating a pull request:
> Run the pr-reviewer agent on the current branch
The PR reviewer agent examines all changes, checks them against common issues, verifies test coverage, and produces a structured review with actionable findings. For manual reviews, see code review best practices.
For security analysis after implementing a feature:
> Run the chaos-monkey agent against the new authentication module
The chaos-monkey agent thinks adversarially. It tries to find ways to break your code, bypass security measures, and exploit edge cases. It is deliberately aggressive in its testing approach. For comprehensive security guidance, see security best practices.
For test coverage analysis:
> Run the test-architect agent to analyze coverage gaps in the user module
The test-architect agent reads your source code and existing tests, identifies untested code paths, and either generates the missing tests or provides a prioritized list of what to test.
Creating Custom Agents
The built-in agents cover common needs, but the real power comes from creating agents tailored to your specific workflow and project. Learn more about configuration in CLAUDE.md.
Custom agents are defined in configuration files that specify the agent’s behavior:
## Agent: api-validator
### Model
sonnet
### Instructions
You are an API validation specialist. When invoked:
1. Read all API endpoint definitions
2. Check that every endpoint has input validation
3. Verify response schemas are consistent
4. Check error responses follow the standard format
5. Verify authentication is required where appropriate
6. Report any endpoints that deviate from standards
### Success Criteria
- All endpoints validated
- Deviations documented with specific file and line references
- Recommendations provided for each issue
This agent can then be invoked whenever API changes are made, ensuring consistency without manual review.
You can create agents for domain-specific tasks that reflect your project’s unique needs. An e-commerce project might have a checkout-flow-validator agent. A data pipeline project might have an ETL-auditor agent. The specificity of custom agents is what makes them valuable, since they encode your team’s knowledge about what to check.
Parallel Execution with Subagents
For complex workflows, Claude Code supports subagents that run in parallel. This is particularly valuable when independent tasks can be executed simultaneously.
Consider a comprehensive code review workflow. Instead of running checks sequentially, you can define parallel subagents:
> Run a comprehensive review with parallel checks:
> - Security analysis (subagent 1)
> - Performance analysis (subagent 2)
> - Test coverage analysis (subagent 3)
> - Documentation completeness (subagent 4)
Each subagent runs independently, reading the relevant code and producing its analysis. The results are then combined into a unified review. This parallel execution is significantly faster than running each check sequentially.
Subagents also enable divide-and-conquer strategies for large tasks. When refactoring a large module, you might spawn subagents for each sub-module, with each one handling its portion of the refactoring independently.
Agent Pipelines
The most sophisticated use of agents is chaining them into pipelines that handle entire development workflows.
A full development pipeline might look like this:
- Spec-writer agent clarifies requirements if they are ambiguous
- Architecture agent designs the solution approach
- Implementation happens based on the architecture
- Code-evaluator agent reviews the implementation for quality
- Test-runner agent generates and runs tests, iterating until they pass
- PR-reviewer agent performs a pre-review check
- Security agent scans for vulnerabilities on high-risk changes
- Quality-gate agent performs final sign-off checks
Each agent in the pipeline passes context to the next, so the test-runner knows what the implementation agent built, and the reviewer knows what the tests verified. This creates a comprehensive quality process that runs automatically.
Best Practices for Agent Configuration
Match models to complexity. Use Opus for agents that need deep reasoning like security analysis and architecture review. Use Sonnet for balanced tasks like code review and test generation. Use Haiku for quick operations like pre-commit checks and file validation.
Define clear success criteria. Each agent should know what done looks like. Vague objectives produce vague results. Specific criteria like “all endpoints have input validation” or “test coverage is above 80 percent” give the agent a clear target.
Keep agents focused. An agent that tries to do everything does nothing well. A security agent should focus on security. A performance agent should focus on performance. Combine their outputs at the pipeline level rather than overloading a single agent.
Iterate on agent instructions. Like any automation, agents improve over time. If an agent consistently misses a certain type of issue, update its instructions. If it produces false positives, refine its criteria. Your agents should evolve with your project.
Agents transform Claude Code from a conversational tool into an automation platform. The documentation provides detailed guides for configuring agents, defining pipelines, and building custom workflows tailored to your development process.