Advertise hereReach developers building with AI coding agents. →

Based on Anthropic’s official docs, checked

Claude Code subagents: create, configure and run them

A subagent is a separate Claude Code worker with its own context window, system prompt and tool access. Claude hands it a task, it works through it, and only its result comes back to your main conversation, so long searches and noisy logs don’t fill your context. Claude Code ships with built-in subagents (Explore, Plan and general-purpose) and lets you define your own. This guide follows Anthropic’s subagents documentation, checked November 5, 2026.

  1. 1. Create the agents folder

    Custom subagents are Markdown files with YAML frontmatter. Put project subagents in .claude/agents/ in your repository so your team gets them, or personal ones in ~/.claude/agents/ to use them in every project.

    mkdir -p .claude/agents
  2. 2. Write the agent file

    name and description are the only required fields. The description is what Claude reads to decide when to delegate, so say exactly when to use it. The Markdown body becomes the subagent’s system prompt.

    ---
    name: test-runner
    description: Runs the test suite after code changes and reports failures with file and line.
    tools: Read, Grep, Glob, Bash
    model: sonnet
    ---
    Run the project tests, read the failures and report the smallest fix for each.
  3. 3. Check the file

    Validate the frontmatter of your agent files before you rely on them.

    claude plugin validate .claude/agents
  4. 4. Use it

    Claude delegates on its own when a task matches the description, or you can ask for the subagent by name in your prompt. Run /context to see which custom subagents loaded and where each came from.

Frontmatter fields you can set

Beyond name and description, optional fields include tools and disallowedTools (which tools it may use), model (sonnet, opus, haiku, fable or inherit), permissionMode, maxTurns, skills, mcpServers, hooks, memory, background, isolation: worktree (its own git worktree), effort and color.

Limit tools to what the job needs. A read-only reviewer with Read, Grep and Glob can’t edit files even if its prompt goes wrong.

Where subagents load from

When two definitions share a name, Claude Code uses this order: managed settings first, then the --agents flag, then the project’s .claude/agents/, then your ~/.claude/agents/, then plugins. /doctor flags duplicate subagent names in the same directory.

Subagents that come from plugins ignore the hooks, mcpServers and permissionMode fields, for security.

Background subagents

From v2.1.302, subagents Claude spawns run in the background by default, so you can keep working while they run. Set CLAUDE_CODE_FORK_SUBAGENT=0 if you want Claude to wait for them instead. Press Ctrl+B to send running work to the background, and use /tasks to see what is running.

Background subagents get a reduced set of built-in tools, and their permission prompts appear in your main session.

Limits and usage

By default Claude Code runs up to 20 subagents at once (CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS) and lets them nest 3 levels deep (CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH). Subagents count toward the same usage limits as your main conversation, so many parallel workers use your plan faster.

Each subagent’s transcript is saved under ~/.claude/projects/ in a subagents folder for that session.

Blocking a subagent

To stop Claude using a particular subagent, add a permission deny rule in the form Agent(name) to your settings.

Tips

Next steps

Verified MCP servers for Claude

→

Generate an MCP config for Claude

→

Claude Code hub

→

Claude Code vs OpenAI Codex: documented features compared

→

Cursor vs Claude Code: documented features compared

→

Claude Code vs GitHub Copilot: documented features compared

→

Google Antigravity vs Claude Code: documented features compared

→

How to add an MCP server to Codex

→

How to add an MCP server to Cursor

→

How to add an MCP server to GitHub Copilot in VS Code

→

How to add an MCP server to Google Antigravity

→

How to migrate from Gemini CLI to Antigravity CLI

→

Portable agent skills: one SKILL.md for every coding agent

→

Safe “always allow” rules for Claude Code and Codex CLI

→

GitHub Copilot CLI yolo mode: --allow-all and safer tool rules

→

Codex sandbox modes and approval policies explained

→

How to install Claude Code on macOS, Linux and Windows

→

How to install the OpenAI Codex CLI

→

Claude Code auto mode: what runs, what gets blocked, how to turn it off

→

Agent Skills moves to the Agentic AI Foundation: what changes

→

MCP security: the risks in MCP servers and how to lock them down

→

Claude Code in VS Code: install, shortcuts and CLI differences

→

What is AGENTS.md? The open instruction file for coding agents

→

Claude Code on Windows: native, WSL and common errors

→

Codex skills: create, install and use SKILL.md skills in Codex

→

GitHub Copilot CLI: install, sign in and start using it

→

Cursor Agent SDK: build, test and deploy agents as code

→

GPT-6.1 Terra in Codex and the API: setup, pricing and limits

→

MCP OAuth: connect a remote MCP server in Claude Code, Codex and Cursor

→

Codex config.toml: location, precedence and the settings to change

→

Codex on Windows: native sandbox setup, WSL and fixes

→

Antigravity CLI (agy): install, sign in, modes and commands

→

Google Antigravity on Windows: install, WSL, sandbox and fixes

→

GitHub Copilot coding agent (now cloud agent): how to use it

→

GitHub Copilot agent mode: how to use it in your IDE

→

Claude Code tips from Anthropic’s best practices

→

Claude Code with OpenRouter: setup, models and troubleshooting

→

How to add an MCP server: Claude Code, Codex, Cursor, Copilot and Antigravity

→

Supabase RLS for AI-built apps: grants, policies and tests

→

Antigravity skills: create, store and run SKILL.md skills

→

Claude Code in JetBrains IDEs: install, connect and fix issues

→

GitHub Copilot skills: create, install and use agent skills

→

Check which plugins, hooks and MCP servers your agent loads

→

Cursor rules examples: .mdc files for each rule type

→

Fix spawn npx ENOENT when starting an MCP server

→

Frequently asked questions

In .claude/agents/ in your project, or ~/.claude/agents/ for personal subagents. Each one is a Markdown file with YAML frontmatter.

Sources