Imagine the frontmatter as the spec sheet of a collaborator: name, available tools, cognitive model, memory, and general behavior pattern. Claude Code reads frontmatter only to decide whether to call this agent — the full body is loaded only when the agent is actually invoked. Every field you omit becomes a default value; every field you fill in becomes a deliberate decision.
↑ Anatomy of a file .md: frontmatter (YAML) + body (Markdown). Claude Code reads the frontmatter to decide; the body defines the behavior.
Detailed content
🏷️ name — the agent’s identity
The field name defines the unique identifier of your
subagent. This is the name the conductor uses to call it — and the name that appears in the status line while the agent is running.
Think of it as the professional nickname from the collaborator.
📐 Format rules
- •Lowercase letters e hyphens — never spaces, underscores, or uppercase letters.
- •Must be unique within the project or global folder
~/.claude/agents/. - •Must be role description, not the technology — prefer
code-revieweratypescript-checker. - •Practical maximum: 30–40 characters — appears in the UI and needs to be readable.
# BOM — papel claro, minúsculas, hífens
name: code-reviewer
name: doc-writer
name: sql-optimizer
name: security-auditor
# RUIM — espaço, maiúscula, underscore
name: Code Reviewer # espaço + maiúscula
name: code_reviewer # underscore
name: TypescriptChecker # camelCase
unique agent identifier — lowercase and hyphens, no spaces.
a wrong name makes Claude Code ignore the file or fail silently when loading the agent.
kebab-case · uniqueness by scope · readability in the UI · role > technology.
🎯 description — the invocation trigger
A description is the field more strategic from
the frontmatter. It's the text the conductor reads to decide whether to call this agent. Think of it as the
consulting room entrance sign: "cardiologist — chest pain, cardiac checkup".
Without the right sign, the orchestrator walks through the door and doesn't know what's inside.
How the conductor uses the description
You make a request
"Review the code I just wrote and point out bugs."
The conductor reads the name + description of all agents
Doesn't read the body — only the header. It's fast and cheap in tokens.
Does the semantic matching
If the description of the code-reviewer says "review the diff for bugs," the request matches. The agent is called.
Only then load the entire body
The body’s token cost only exists when the agent is invoked — not during the “selection process.”
💡 Tip: explicitly include “when to use”
The most effective description names the trigger: "Use after any code change" or "Use when the user asks to optimize an SQL query". This direct instruction removes ambiguity from the orchestrator's match.
the text the conductor reads to decide whether to call this agent — the invocation trigger.
a vague description means the agent is never called; a specific description ensures it's invoked at the right moment.
semantic matching · explicit “when to use” · zero selection cost · progressive disclosure.
🔧 tools — declared permissions
The field tools é a tool allowlist
that the subagent can use. If you don't declare anything, it inherits all the orchestrator's tools — which may be
too many. Restricting tools is a security and focus: a reviewer
who only reads cannot accidentally write files.
✓ Principle of least privilege
- ✓
code-reviewer: onlyRead, Grep, Glob - ✓
doc-writer:Read, Write(without Bash access) - ✓
sql-runner: onlyBash(for psql) - ✓Declare only what the task actually requires
✗ Common pitfalls
- ✗Leave without
tools(inherits everything from the orchestrator) - ✗Give
Bashto an agent that only reads files - ✗Give
Writeto a reviewer (can overwrite code) - ✗List tools the agent never uses (noise)
📊 Most-used built-in tools
Readreads project files
Writecreates / edits files
Editedits specific sections
Bashruns shell commands
Grepsearch files
Globlists files by default
WebFetchweb search
Agentlaunches nested subagents
Taskcreates long-running tasks
list of tools the subagent can use during execution.
limits what can go wrong; a reviewer without Write permission can't accidentally delete code.
least privilege · allowlist · native tools · conductor inheritance (when omitted).
🧠 model — which Claude runs the task
The field model defines which language model will run the agent.
This is the cost and quality decision: simple, repetitive tasks go
to fast, inexpensive models; deep analysis goes to Opus. The topic of models by task
is the Track 3 entire — here we learn the field syntax.
model: haiku # rápido, barato — triagem, classificação
model: sonnet # equilibrado — maioria dos casos
model: opus # profundo e caro — análises complexas
# IDs completos (mais estáveis em produção)
model: claude-haiku-4-5
model: claude-sonnet-4-5
model: claude-opus-4-5
# omitido: herda o modelo do maestro (padrão seguro)
💡 Practical rule for getting started
Always start with model: sonnet. If the agent handles simple triage, switch to haiku. If it does complex reasoning (architecture, auditing), switch to opus. T3 will give you the exact criteria for each case.
field that determines which Claude model runs this agent — controls cost and depth.
without this field, all agents run on the most expensive model by default—unnecessary spending.
haiku/sonnet/opus · full IDs vs. aliases · inheritance from the orchestrator · cost × quality.
🎨 color e 🧠 memory — identity and persistence
Two fields that complete the basic configuration: color defines the
visual highlight color from the agent in the UI, and
memory defines which memory files it accesses—controlling what
it "knows" before the task even begins.
🎨 color
Hex color or color name displayed in the terminal’s status line next to the agent’s name.
color: "#34d399" # verde
color: "#60a5fa" # azul
color: "red" # nome CSS
Optional — visual only. If omitted, Claude Code uses a default color.
🧠 memory
Controls which CLAUDE.md files the agent loads into context when it starts. Four possible values:
project— Project CLAUDE.mduser— global ~/.claude/CLAUDE.mdlocal— CLAUDE.local.md (private)none— with no preloaded memory
📊 When to use memory: none
Triage or impartial analysis agents benefit from memory: none — they shouldn't be influenced by project preferences. A documentation agent, on the other hand, needs memory: project to learn the repository conventions.
color = visual identity; memory = CLAUDE.md files that the agent loads at startup.
incorrect memory causes the agent to ignore project conventions or load irrelevant and costly context.
color (visual) · memory: project/user/local/none · preloaded context · unbiased vs. context-aware agent.
🚫 disallowed-tools — the explicit blocking
While tools is an allowlist (only what's on it can be used),
disallowed-tools is a explicit blocklist:
"the agent can use everything except these". Use when you want to inherit most of the orchestrator's tools but
specifically block one or two dangerous ones.
---
name: code-analyzer
description: Analisa a base de código. Nunca modifica arquivos.
model: sonnet
disallowed-tools:
- Write # não pode criar / sobrescrever
- Edit # não pode editar trechos
- Bash # não pode rodar comandos
---
⚖️ tools vs. disallowed-tools — when to use each one
Use tools when…
- • The agent needs a set small and well-defined of tools
- • You want to explicitly state what the agent can do
- • The agent is new and you want full control
Use disallowed-tools when…
- • The agent needs many tools but wants to block only a few
- • You want to automatically inherit future tool expansions
- • You only need to remove destructive tools from a generic agent
tool blocklist — the agent can use everything except what's listed here.
alternative to tools when the allowlist would be huge — blocking is more concise than listing everything.
blocklist · inheritance with exception · blocklist vs. allowlist · selective security.
🔌 Advanced fields — MCP and others
Beyond the basic fields, the frontmatter supports advanced settings for integrating MCP servers (Model Context Protocol) — which expand the available tools with external APIs, databases, services, and much more. These fields are optional and generally appear in production agents.
---
name: db-analyst
description: Analisa dados no PostgreSQL. Use quando pedir
insights de banco ou queries de análise.
model: sonnet
tools: mcp__postgres # ferramenta via MCP
mcp_servers: # servidores MCP disponíveis
- postgres # nome definido em .claude/mcp.json
---
✓ What MCP expands
- ✓Direct database queries
- ✓Integration with third-party APIs (Slack, GitHub, Jira)
- ✓Your company's custom tools
- ✓Remote file systems and S3
📌 Prerequisite
The MCP server needs to be configured in .claude/mcp.json before referencing in the frontmatter.
// .claude/mcp.json
{
"postgres": {
"command": "mcp-postgres",
"args": ["postgresql://…"]
}
}
advanced fields that connect the agent to MCP servers — expanding beyond native tools.
MCP is the bridge for integrating subagents with real production systems (databases, APIs, services).
MCP · mcp_servers · external tools · .claude/mcp.json · production integration.
Real example: fully commented frontmatter
One security-auditor.md of production using all the fields we've covered —
with comments explaining each design decision. This is the reference point you can copy and adapt.
---
name: security-auditor # kebab-case, papel claro
description: | # bloco multiline para descrições longas
Audita o código em busca de vulnerabilidades de segurança:
SQL injection, XSS, dependências desatualizadas, segredos
expostos e falhas de autenticação.
Use quando o usuário pedir revisão de segurança, antes
de qualquer PR para produção, ou após mudanças em auth.
# ↑ "quando usar" explícito = gatilho preciso
tools: Read, Grep, Glob # só leitura — auditor nunca modifica
model: claude-opus-4-5 # análise crítica → modelo mais capaz
color: "#f87171" # vermelho = segurança (visual na UI)
memory: project # carrega CLAUDE.md do projeto
# → conhece as convenções de segurança do repo
disallowed-tools: # bloqueio explícito de ferramentas destrutivas
- Write # não pode alterar arquivos
- Edit # não pode editar trechos
- Bash # não pode executar scripts
---
# Corpo do agente (cérebro) — carregado só quando invocado
You are a senior application security engineer.
Your role is to audit code for vulnerabilities — never to fix them.
When invoked:
1. Run Grep to find patterns: SQL queries, eval(), innerHTML, passwords, tokens.
2. Read each flagged file in full context.
3. Classify each finding by severity: CRITICAL / HIGH / MEDIUM / LOW.
Output format:
- One table: Severity | File | Line | Issue | Recommendation
- Summary paragraph with the 3 most critical risks
- Do NOT rewrite code — only report.
🔒 tools + disallowed
Uses tools for allowlist and disallowed-tools redundantly for clarity — a defense-in-depth approach.
🧠 model: opus
Security auditing is critical — this is where the most expensive model is worth it. Simple triage agents can use haiku.
📝 multiline description
The pipe | in YAML, you can use multiple lines. Use it for long descriptions with explicit triggers.
Ready-made prompts (copy and paste)
Three prompts to use in Claude Code now: create an agent via /agents,
inspect an existing agent and generate a custom frontmatter for a specific role.
Crie um subagente chamado "doc-writer" que escreve
documentação técnica em Markdown. Ele deve usar apenas
Read e Write, rodar em sonnet, e ter memória do projeto.
Escreva o frontmatter completo e um corpo de 5 linhas.
Leia o frontmatter de todos os arquivos .md em
.claude/agents/ e me diga: quais modelos estão sendo
usados, quais ferramentas cada agente tem, e se algum
agente tem description vaga que pode atrapalhar o match.
Quero um agente que otimize queries SQL pesadas.
Escreva o frontmatter completo incluindo: name kebab-case,
description com o gatilho "quando usar", tools mínimas,
model adequado ao tipo de análise, e color de destaque.
Depois explique cada campo escolhido e por quê.
Simulated screen: /agents and the loaded frontmatter
This is how Claude Code displays your agents after loading the files .md. The UI shows the
name, a brief description,
the tools e o model of each agent.
The field color appears as the colored dot next to the name.
↑ Illustrative recreation of the panel /agents. O color appears as a dot; the description is truncated but sufficient for the semantic match.
Exercise
Write the complete frontmatter for a subagent named
test-writer — an agent that reads source code and writes unit tests
in vitest/jest. Use all required fields and at least one advanced field.
How to do it
- Decide the
name: must be kebab-case, and describe the role. - Write the
description: include “when to use” and trigger situations. - List the
toolsminimums: what does a test writer actually need? - Choose the
model: Is writing tests simple or complex? Explain. - Add
colorememorywith a justification for each.
✅ Verification criteria — how to know you got it right
- →
nameis in kebab-case, with no spaces or uppercase letters. - →
descriptioncontains at least one sentence of the type "Use when…" or "Use after…". - →
toolsincludesReadeWrite, and you justified why those two. - →
modelchosen with a cost × quality justification. - →The frontmatter opens and closes with
---and is valid YAML (with no mixing of tabs and spaces).
Solved example
---
name: test-writer
description: |
Lê código-fonte e escreve testes unitários em vitest/jest.
Use quando pedir "escreva testes para este arquivo" ou
após implementar uma nova função ou classe.
tools: Read, Write, Glob # lê fonte, escreve teste, lista arquivos
model: sonnet # escrever testes exige raciocínio médio
color: "#4ade80" # verde = "passou nos testes"
memory: project # precisa conhecer o framework do projeto
---
✅ Module summary
name — kebab-case, unique, descriptive of the role. It's the identifier in the UI and in the orchestrator's matching.description — the trigger: the orchestrator reads only this to decide whether to call the agent. Include "Use when…".tools — permission allowlist. Minimum necessary; a read-only agent doesn't need Write.model — haiku/sonnet/opus according to the task's complexity. Omitting it inherits the orchestrator's model.color + memory — visual identity and preloaded context (project/user/local/none).disallowed-tools — denylist when you want to inherit everything but block a few specific tools.mcp_servers connects the agent to databases, APIs, and services via the Model Context Protocol.Next module:
2.2 — The description is the trigger. How to write descriptions the orchestrator recognizes and invokes accurately.