Anatomy of an Agent Definition

Claude Code Agents: Fundamentals

Chapter 2 · Anatomy of an Agent Definition

Chapter 1 established that every agent type has its own restricted set of tools, and explained why that restriction matters. This chapter covers exactly where that restriction — and everything else about how an agent behaves — actually gets defined: a small, structured file with a specific set of fields, each controlling one aspect of the agent's identity and behavior.

Where an Agent Is Defined

A custom agent is typically defined as a markdown file with a block of structured metadata — frontmatter — at the top, followed by ordinary written instructions in the body. The frontmatter is machine-readable configuration; the body is the agent's own system prompt, written in plain language exactly the way you'd brief a new colleague. Both parts matter, and they do genuinely different jobs.

The Frontmatter Fields

  • name — a short, unique identifier for the agent.
  • description — a summary of what the agent does and, critically, when it should be used. This field is what a routing decision (or a person choosing between several available agents) actually reads to decide whether this agent fits a given task — a vague description makes the agent hard to select correctly, even if the agent itself is well built.
  • tools — an explicit allowlist of which tools this agent may use. Omitting a tool from this list means the agent cannot use it at all, regardless of what its instructions say — this is where Chapter 1's isolation principle is actually enforced.
  • model (optional) — pins the agent to a specific model rather than inheriting whatever model the parent conversation is using, letting a simple, high-volume task use a smaller/faster model while a genuinely difficult one uses the most capable model available.

The System Prompt Body

Below the frontmatter, the body is the agent's actual briefing — written instructions describing its role, how it should approach a task, and any conventions it should follow. Because Chapter 1 established that an agent starts with no memory of anything outside what it's given, the system prompt has to stand on its own: it should read like documentation for someone who's never seen this project before, not like a note assuming shared context that only exists in your own head.

--- name: changelog-writer description: Use this agent after a feature or fix is finished and ready to record in CHANGELOG.md. Do not use it for in-progress or exploratory work. tools: Read, Edit, Grep model: haiku --- # Changelog Writer You write concise, user-facing changelog entries. Read the relevant diff or summary provided to you, then add one entry to CHANGELOG.md under the "Unreleased" heading. Rules: - One line per change, present tense ("Add", not "Added") - No implementation detail — describe the user-visible effect only - Never remove or reorder existing entries

Tool Allowlists in Practice

The effect of the tools field is concrete, not theoretical. A dedicated read-only search agent might be granted every tool except the ones that edit or create files, making it structurally unable to change anything no matter what it's asked. A narrowly-scoped configuration agent, built for one specific settings task, might be granted only two tools — enough to read a file and edit it — and nothing else. Neither restriction is arbitrary: each one is sized to exactly what that agent's own job actually requires.

Model Selection: Matching Capability to the Task

Not every agent needs the most capable model available. A changelog-writer agent (as in the example above) is doing a small, well-defined formatting task — a faster, lighter model handles it perfectly well, at lower cost and higher speed. A code-review agent reasoning carefully about subtle correctness issues across an unfamiliar codebase genuinely benefits from the most capable model available. Choosing a model isn't just a cost setting — it's part of matching the agent's design to the actual difficulty of its job.

Agent ProfileTypical ToolsTypical Model Choice
Read-only search agentRead, Grep, Glob (no Edit/Write)Fast/lightweight — task is retrieval, not deep reasoning
Code-review agentRead, Grep, Glob (no Edit/Write — reviews, doesn't fix)Most capable available — subtle correctness judgment
Narrow config agentRead, Edit onlyFast/lightweight — task is small and well-defined
Write the description field around "when," not just "what"
A description like "reviews code" is far less useful than "use this agent after implementation is finished and before merging, to check for bugs and style issues — not for architecture decisions." The second version tells whoever's choosing an agent exactly which situation it fits, which is what the description field actually needs to communicate.
More tools isn't automatically more useful
Granting an agent every available tool "just in case" doesn't make it more capable at its actual job — it only widens what could go wrong if it misinterprets an instruction or the task drifts. The discipline worth building here is the same one Chapter 1 introduced: match the tool allowlist tightly to what the agent's job genuinely requires, not to the maximum available, even when it would be more convenient to just grant everything upfront.

Hands-On Exercises

Exercise 1

Explain the difference in purpose between an agent's frontmatter and its system-prompt body, using this chapter's own terms.

📄 View solution
Exercise 2

An agent's description field reads simply "helps with code." Explain why this is a poorly written description, and rewrite it to be genuinely useful, following this chapter's own tip box.

📄 View solution
Exercise 3

A colleague grants a new documentation-formatting agent every available tool, including Edit and Bash, reasoning "it's simpler to just give it everything." Using this chapter's own warning box, explain why this reasoning is flawed.

📄 View solution

Chapter 2 Quick Reference

  • An agent definition has two parts: frontmatter (structured config) and a system-prompt body (written instructions)
  • Frontmatter fields: name, description (what AND when to use it), tools (the allowlist), model (optional)
  • Omitting a tool from the allowlist means the agent structurally cannot use it — this is where isolation (Ch.1) is actually enforced
  • The system-prompt body should stand alone, like documentation for someone with no shared context
  • Model choice should match task difficulty — a lightweight model for simple, well-defined work; the most capable model for subtle judgment
  • Granting more tools than a job needs doesn't add useful capability — it only widens the blast radius of a mistake