Skip to main content
NeVibe · guide · 2026-10-24

Claude Code subagents: how to create one, call it and keep context clean

A Claude Code subagent is a Markdown file in .claude/agents/ that defines a role, its tools and its own system prompt. It runs in a separate context window and hands only the result back to the main conversation.

What a subagent is and when to use one

The point is isolation. Per the docs, each subagent runs in its own context window with a custom system prompt, its own tool access and independent permissions. A search across a hundred files or a test run with a long log stays inside the subagent; the main thread gets the conclusion.

Three are built in: Explore (fast, read-only codebase search), Plan (gathers context in plan mode) and General-purpose (multi-step work that edits files). Write your own when a role keeps coming back: a reviewer that never touches files, a tester limited to Bash, a docs researcher.

For a one-off task, skip it. If you are describing the same role for the third time, make it a file.

Where subagent files live

  • .claude/agents/*.md in the project (Claude Code searches upward from the working directory), committed with the code;
  • ~/.claude/agents/ for personal subagents across projects;
  • the agents/ folder of a plugin;
  • --agents '<json>' for a single session;
  • organization managed settings.

In current versions /agents just reminds you to edit the files directly or ask Claude. Up to v2.1.197 it opened a wizard with Running and Library tabs.

File format and frontmatter fields

Two fields are required: name (up to 256 characters, no colon) and description. The body becomes the system prompt.

---
name: code-reviewer
description: Reviews changes before commit. Use after edits in src/.
tools: Read, Grep, Glob
model: inherit
---
You are a reviewer. Read the diff, look for logic errors and missing checks.
Do not edit files. Finish with a list of findings with path and line.

This is a sketch; test it on your own repo. Optional fields: tools, disallowedTools, model, permissionMode, maxTurns, skills, mcpServers, hooks, memory, effort, isolation, background, omitClaudeMd, color, initialPrompt.

Leave out tools and the subagent inherits every tool available to subagents, minus a few that are always removed, such as AskUserQuestion. For a reviewer or researcher, list tools explicitly. That is the only way to be sure it will not rewrite anything.

How to invoke a subagent

  • Automatically. Claude Code delegates when a task matches the description, so write the description as a trigger: "use when…".
  • By @-mention in your message.
  • With a flag: claude --agent <name> runs the whole session as that agent.
  • In plain words: "hand the review to the code-reviewer subagent".

Limits and gotchas

  • Up to 20 subagents in parallel, set by CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS.
  • Nesting goes three levels below the main conversation (CLAUDE_CODE_MAX_SUBAGENT_SPAWN_DEPTH; 1 turns nesting off).
  • Claude Code warns when custom subagent descriptions exceed 15,000 tokens in total, because descriptions always sit in context.
  • The skills preload takes the first 32 skills.
  • Plugin subagents ignore hooks, mcpServers and permissionMode. If a role needs its own hook, ship it in .claude/agents/, not in a plugin.

Source: Claude Code docs.

Which other agents read Claude Code subagents

AgentWhere it looksFormatCursor.cursor/agents/, plus .claude/agents/ and .codex/agents/Markdown + frontmatter; .cursor/ wins on name clashesVS Code Copilot.claude/agents and ~/.claude/agents"Claude agent format"Codex.codex/agents/, ~/.codex/agents/TOML; name, description, developer_instructions requiredGemini CLI.gemini/agents/*.md, ~/.gemini/agents/Markdown + YAML; name and description required, call with @name

Cursor and VS Code take Claude Code files as they are. Codex needs the role rewritten as TOML (Codex docs); for Gemini CLI, moving the folder and checking the fields is usually enough (Gemini CLI docs). Ready-made roles are in Subagents and the best Claude Code subagents list.

FAQ

How do I use subagents in Claude Code?

Put a Markdown file with name and description in .claude/agents/. Claude Code calls it when a task matches the description, or when you @-mention it or start a session with claude --agent.

How do I create a subagent in Claude Code?

Create .claude/agents/name.md with name and description in the frontmatter, optionally tools and model, and the role prompt in the body. You can also ask Claude to write the file.

What is the difference between a subagent and a skill?

A skill loads instructions into the current conversation. A subagent runs in its own context window with its own tools and permissions and returns only the result.

How many subagents can run in parallel?

Up to 20 per the docs, controlled by CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS. Nesting is limited to three levels.

NeVibe catalog

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor