Build This Now
Build This Now
What Is Claude Code?Claude Code InstallationClaude Code Native InstallerYour First Claude Code Project
Agent FundamentalsBackground Agents in Claude CodeSub-Agent RoutingSub-Agent Design in Claude CodeClaude Code Task DistributionBuilder-Validator Agent TeamsClaude Code Agent TeamsAgent Teams ControlsAgent Teams Prompt TemplatesAgent Teams Best PracticesAgent Teams WorkflowCustom AgentsAgent PatternsHuman-like Agents
Get Build This Now
speedy_devvkoen_salo
Blog/Handbook/Agents/Agent Fundamentals

Agent Fundamentals

Five ways to build specialized agents in Claude Code, from sub-agents to .claude/agents/ definitions to perspective prompts.

Problem: A real project usually wants more than one head on the work. A security pair of eyes. A performance pair. Someone keeping the docs honest. Holding all those roles in one chat burns focus and time.

Quick Win: Hand a parallel job to a sub-agent. It runs on its own, then drops what it found back into your main session.

Understanding: Claude Code gives you several ways to get agent-style behavior, from built-in sub-agents to your own slash commands. Each earns its keep on different jobs. Get the basics down before reaching for the fancier patterns.

Here are the five paths Claude Code offers, side by side:

ApproachBest ForPersistence
Task Tool (Sub-agents)Parallel execution, isolated workSession only
.claude/agents/ DefinitionsPersistent specialist sub-agentsPermanent
Custom Slash CommandsReusable workflows, team sharingPermanent
CLAUDE.md PersonasProject-wide behavior rulesPermanent
Perspective PromptingQuick context switchesSingle request

Every path has a trade-off. Sub-agents win on parallel work. .claude/agents/ definitions hand sub-agents a name that sticks. Slash commands shine on reusability.

The Task Tool

Inside your session, the Task tool spins up small Claude Code instances. Every sub-agent gets a fresh context window, runs independently, and ships results back to the orchestrator.

Why sub-agents matter:

  • Isolated context keeps work on one task from leaking into the next
  • Parallel runs cut the wall-clock time on multi-file analysis
  • A sub-agent that fails does not take your main session down with it
  • Background mode lets you keep working while they run (press Ctrl+B)

New: Sub-agents Claude spawns can now sit in the background. Hit Ctrl+B, and the main agent stays free for other chat. Results pop back up the moment they finish. Full walkthrough in the async workflows guide.

For deeper orchestration patterns, see the sub-agent design notes.

Custom Sub-Agent Definitions

Sub-agents can also live on disk. Drop a Markdown file into a dedicated agents/ directory, YAML frontmatter at the top, and you have a custom sub-agent definition. These are not slash commands. Slash commands are prompts you call by hand. An agent definition sets up a persistent sub-agent that Claude's orchestrator picks up on its own when the task fits.

Two scopes for agent definitions:

  • Project agents (.claude/agents/) - Specific to your repository, shareable with your team via git
  • User agents (~/.claude/agents/) - Available across all your projects, personal to your machine

A sub-agent declared in .claude/agents/ reads your project's CLAUDE.md just like the main session does. Coding standards, conventions, project rules all carry over without extra wiring.

Controlling the sub-agent model: Set CLAUDE_CODE_SUBAGENT_MODEL in your environment to point sub-agents at a specific model. Useful for cost trims (a lighter model for sub-agents), or for tasks that benefit from heavier reasoning.

Restricting Sub-Agent Access with Permission Rules

Claude can be told which sub-agents it is allowed to call, using Task(AgentName) permission rules. Drop them into the deny array of your settings.json, or pass them at the command line through --disallowedTools.

That keeps the Explore sub-agent from being spawned. Built-in agent names cover Explore, Plan, and Verify. Agents can also be turned off at launch.

Reach for this in sensitive environments where you want a tighter leash on agent behavior, or when autonomous exploration is eating too many tokens.

Custom Slash Commands

Reusable slash commands live as Markdown files in .claude/commands/. Run /project:security-review src/auth/ and your specialist gets to work.

Command locations:

  • .claude/commands/ - Project-specific, shareable via git
  • ~/.claude/commands/ - Personal, available everywhere

CLAUDE.md Personas

Every interaction in your project runs through whatever sits in CLAUDE.md. The file ends up shaping how Claude shows up by default. Agent-style consistency, without ever calling the agent by name.

Perspective Prompting: Quick Context Switches

For a one-off look, ask Claude to put on a specific perspective. Zero setup. Specialized analysis right away.

When to Use Each

Use sub-agents when: You want parallel runs, or you need isolated context across several tasks.

Use .claude/agents/ when: You want named specialist agents that stick around, and Claude's orchestrator picks them up by task type on its own.

Use slash commands when: The same workflow keeps coming back across sessions, or you want to share it with the team.

Use CLAUDE.md when: The behavior should apply everywhere, on every interaction, automatically.

Use perspective prompting when: You want a quick, one-time take from a different angle.

In practice, well-developed Claude Code setups run all five at once. Persistent definitions for specialist roles. Slash commands for repeat workflows. CLAUDE.md for project-wide standards. Sub-agents for parallel jobs. The ClaudeFast Code Kit ships 18 pre-configured agents (security auditor through frontend specialist), plus the slash commands and routing rules already in place, so the patterns are visible before you build your own.

Next Action: Pick a workflow you run often, and turn it into a slash command under .claude/commands/. From there, dig into the distribution strategies the harder orchestration work needs.

Explore More Agent Concepts:

  • Sub-Agent Best Practices - When to use parallel, sequential, or background execution
  • Sub-Agent Design - Architecture patterns for orchestrating multiple agents
  • Custom Agents - Build specialized agents with slash commands
  • Agent Patterns - Proven design patterns for agent systems
  • Human-Like Agents - Create agents with distinct personalities

More in this guide

  • Agent Patterns
    Orchestrator, fan-out, validation chain, specialist routing, progressive refinement, and watchdog. Six ways to wire sub-agents in Claude Code.
  • Agent Teams Best Practices
    Battle-tested patterns for Claude Code agent teams. Troubleshooting, limitations, plan mode quirks, and fixes shipped from v2.1.33 through v2.1.45.
  • Agent Teams Controls
    Stop your agent team lead from grabbing implementation work. Configure delegate mode, plan approval, hooks, and CLAUDE.md for teams.
  • Agent Teams Prompt Templates
    Ten tested Agent Teams prompts for Claude Code. Code review, debugging, feature builds, architecture calls, and campaign research. Paste and go.
  • Agent Teams Workflow
    The full Claude Code agent teams workflow. Structured planning, contract chains, and wave execution that ships production code from parallel agents.

Stop configuring. Start building.

SaaS builder templates with AI orchestration.

Get Build This Now

Efficiency Patterns

Permutation frameworks let Claude Code turn 10 manual builds into a template that generates variations 11, 12, and 13 on demand.

Background Agents in Claude Code

Push sub-agents to the background with Ctrl+B and keep working while they run.

On this page

The Task Tool
Custom Sub-Agent Definitions
Restricting Sub-Agent Access with Permission Rules
Custom Slash Commands
CLAUDE.md Personas
Perspective Prompting: Quick Context Switches
When to Use Each

Stop configuring. Start building.

SaaS builder templates with AI orchestration.

Get Build This Now