← All guides

Guide · Agent · ★★☆☆☆

How to create a Claude Code agent

An agent is a helper Claude hands a job to. You make one with a single Markdown file, and Claude decides when to call it.

By Arthur Hsiao · Last updated · 4 min read

The idea. A subagent is a second Claude with its own instructions and its own context window. The main Claude sends it a job, it works, and only its final answer comes back. Long reading and searching stays out of your main chat, so it stays short and cheap.

1Pick a job that is worth an agent

Good jobs are ones you repeat and that need a different mindset from your normal chat:

  • Planning and hard debugging, where you want the strongest model.
  • Reviewing code, where you want a fresh pair of eyes with no memory of writing it.
  • Searching a big codebase, where you only want the conclusion.

For a one-line change, an agent is overkill. Just ask Claude.

2Create the file

An agent is a Markdown file. Put it in ~/.claude/agents/ to use it in every project, or .claude/agents/ in a repo for that project only. The file name is the agent name. Here is the start of my deep-think-master.md:

---
name: deep-think-master
description: Use for complex or planning-heavy tasks: multi-step implementation plans,
  architecture decisions, hard debugging, or changes spanning 5+ files. Do NOT use for
  simple edits, quick questions or lookups.
model: claude-opus-5-5
---

You are deep-think-master, a senior engineer brought in for complex problems and planning.

How you work:
1. Restate the goal and the constraints in 2-3 lines.
2. Read the relevant code before deciding anything. Don't guess about files you haven't opened.
3. For planning: produce a numbered plan. For each step give the files, what changes, and how to verify it.

The part between the --- lines is the front matter. The text below it is the agent's system prompt.

3The three fields that matter

FieldWhat it does
nameThe agent's name. Lower case with dashes.
descriptionTells Claude when to call the agent. This is the most important line in the file.
modelWhich model the agent runs on. Leave it out to use the same model as your chat.

You can also add a tools field to limit what the agent may use. A reviewer that can only read files cannot break anything.

Write the description like a rule. Claude reads it to decide whether to hand over a job. Say what the agent is for, and also what it is not for. My description ends with "Do NOT use for simple edits, quick questions, lookups", so Claude stops sending it small jobs.

4Or let Claude write it

Type /agents in Claude Code to see, create and edit your agents. You can also describe it in plain words:

Create an agent called code-reviewer in ~/.claude/agents. It reviews a diff for bugs and
unclear code, and never edits files. Only give it read tools. Use it when I ask for a review.

Read the file it writes. The system prompt below the front matter is your agent's whole personality, so edit it until it sounds right.

5Make Claude use it

Claude calls an agent when the task matches its description. You can also ask by name:

Use the deep-think-master agent to plan this change before you touch any files.

If Claude never calls it, the description is too vague. Make it more specific, or add a line to your CLAUDE.md such as "For any review, use the code-reviewer agent".

6Test it

Give it a job you know the answer to, and check three things: it picked the right job, its answer comes back short, and it did not do more than you allowed. Then use it for a week and fix the prompt each time it surprises you.

An agent can still make mistakes. It has its own context, so it only knows what you wrote in its prompt and what Claude tells it. Give it a clear task each time, and do not give it write tools unless it needs them.

To run your own code on events instead, see Claude Code hooks. To add a panel that shows your agents working, see Claude Code mods.

Not sure which of the four to use? See skills vs subagents vs hooks vs slash commands.

Three agents splitting one design job: design a landing page with Claude Code. Giving an agent its own model: which Claude Code model to use.