Skip to content

Custom Agents

Define persistent, specialized agents with custom tools, models, and system prompts — checked into your codebase and shared with your team.

Custom agents are persistent subagent definitions stored as Markdown files in .claude/agents/. The official documentation calls all of these “subagents” — we use “custom agents” here to distinguish file-based, reusable definitions from the temporary subagents Claude spawns dynamically for one-off tasks. Both are configured the same way; the difference is persistence and intent.

Each agent gets its own system prompt, tool set, model selection, and permission mode. When you or Claude invokes an agent, it runs in its own context with only the capabilities you’ve defined.

Creating an agent

Run /agents in Claude Code to create, edit, and manage agents interactively. Choose “Create new agent” → select scope (Personal or Project) → describe what the agent should do. Claude generates the configuration.

Manual file creation

Create a Markdown file in .claude/agents/ (project) or ~/.claude/agents/ (personal):

---
name: code-reviewer
description: Reviews code for quality and best practices. Use proactively after code changes.
tools: Read, Glob, Grep
model: sonnet
---

You are a senior code reviewer. Analyze code for:
- Security vulnerabilities
- Performance issues  
- Readability and maintainability
- Test coverage gaps

Provide specific, actionable feedback with code examples.

Supported frontmatter fields

FieldRequiredDescription
nameYesUnique identifier (lowercase, hyphens)
descriptionYesWhen Claude should delegate to this agent
toolsNoTools the agent can use (inherits all if omitted)
disallowedToolsNoTools to deny
modelNosonnet, opus, haiku, or inherit
permissionModeNodefault, acceptEdits, plan, auto, dontAsk, bypassPermissions
maxTurnsNoMaximum agentic turns before stopping
isolationNoSet to worktree for isolated file system
colorNoBackground color in the UI
memoryNouser, project, or local for persistent memory
skillsNoSkills loaded into the agent’s context
mcpServersNoMCP servers available to this agent
hooksNoLifecycle hooks scoped to this agent
effortNoThinking effort level: low, medium, high, max
backgroundNoRun the agent in the background
initialPromptNoFirst prompt sent automatically when the agent starts

Agent scope and priority

LocationScopePriority
Managed settingsOrganization-wideHighest
--agents CLI flagCurrent session onlyHigh
.claude/agents/Current projectMedium
~/.claude/agents/All your projectsLower
Plugin agents/Where plugin is enabledLowest

When multiple agents share the same name, the higher-priority location wins.

Launching agents

From the CLI:

claude --agent code-reviewer

During a session, run /agents to see available agents or ask Claude directly — it delegates based on the agent’s description.

For one-off agent definitions without saving files:

claude --agents '{"reviewer": {"description": "Code reviewer", "prompt": "You review code.", "tools": ["Read", "Grep"], "model": "sonnet"}}'

Custom agents vs subagents

Custom AgentsSubagents
Defined in.claude/agents/*.md filesSpawned dynamically by Claude
PersistencePermanent, version-controlledTemporary, single-task
ConfigurationFull frontmatter (tools, model, hooks, MCP)Inherited from parent with optional overrides
Use caseRecurring roles (reviewer, debugger, architect)One-off parallel investigations

Example agents

Read-only analyst

---
name: analyst
description: Analyzes code patterns and architecture without making changes
tools: Read, Glob, Grep, Bash
model: haiku
---

You are a read-only code analyst. Never suggest edits directly.
Analyze patterns, dependencies, and architecture. Report findings clearly.

Build validator

---
name: build-validator
description: Validates that the project builds and tests pass
tools: Bash, Read
model: sonnet
---

Run the build and test suite. Report any failures with file paths and line numbers.
Do not fix issues — only report them.
Commands to run:
1. npm run build
2. npm test

Security auditor

---
name: security-auditor
description: Scans code for security vulnerabilities
tools: Read, Glob, Grep
model: opus
permissionMode: plan
---

You are a security auditor. Scan for OWASP Top 10 vulnerabilities:
- SQL injection, XSS, CSRF
- Hardcoded secrets and credentials
- Insecure dependencies
- Missing input validation

Report severity (Critical/High/Medium/Low) with specific file locations.

Tips

  • Start with read-only agents (restrict tools to Read, Glob, Grep) for safety.
  • Use model: haiku for fast agents that don’t need deep reasoning.
  • Set isolation: worktree when agents need to make experimental changes.
  • Check project agents into version control so the whole team benefits.
  • Write clear descriptions — Claude uses them to decide when to delegate.