Claude Code Subagents: Best Delegation Guide A developer published a hands-on guide to Claude Code Subagents, showing how to define specialized AI assistants as markdown files with YAML frontmatter that run in isolated context windows with their own toolsets and system prompts. The guide covers loading agents via the --agents CLI flag, project-level .claude/agents/ directories, or user-level ~/.claude/agents/, with a documented priority order of managed, CLI, project, user, then plugin. It also details frontmatter options for restricting tools, selecting models, controlling reasoning depth, and isolating worktrees so subagents can modify code without touching the main working tree. Cross-posted from Iqraa.tech https://iqraa.tech/ai-genai/claude/claude-code-subagents/?utm source=devto&utm medium=referral&utm campaign=claude-code — hands-on tutorials for Claude Code, AI agents, cloud, and system design. Claude Code Subagents enable parallel task delegation through specialized AI assistants with isolated context windows, toolsets, and system prompts. This guide covers creating, configuring, and working with subagents defined as markdown files with YAML frontmatter, which can be managed via CLI flags, project directories, or user directories across different projects. Subagents can also leverage advanced MCP configuration https://iqraa.tech/ai-genai/claude/claude-code-mcp-configuration/ to access external tools and data sources. Subagents maintain clean context during lengthy tasks, enable parallel work, and allow packaging domain expertise into reusable agents. Configuration options include tool restrictions, model selection, reasoning depth control, and isolation settings like worktree separation for safe code modifications without affecting the main working tree. Claude Code Subagents enable parallel task delegation. This guide covers agent isolation, multi-agent workflows, and when to delegate work to subagents. For a side-by-side comparison of when to choose subagents over skills, hooks, or plugins, see our extensibility decision guide https://iqraa.tech/ai-genai/claude/claude-code-extensibility/ . In this guide to Claude Code Subagents , you'll work through practical, hands-on steps with real examples. Claude Code Subagents is explained from the ground up so you can apply it immediately in your own projects. Subagents enable Claude to hand off work to specialized AI assistants, each operating with its own isolated context window, toolset, and system prompt. This approach keeps context clean during lengthy tasks, enables parallel work, and lets you package domain expertise into reusable agents. This lesson walks through creating, configuring, and working with subagents. Subagents are defined as markdown files with YAML frontmatter. You can make them available in several ways: use the --agents CLI flag for a single session, place them in .claude/agents/ for project-wide availability and commit them to git , or put them in ~/.claude/agents/ for personal use across all projects. Plugins can also bundle agents. The priority order is: managed first, then CLI flag, project, user, and finally plugin. Built-in subagents are always present and don’t participate in the name-override system. The /agents command opens an interactive menu to create, edit, and manage your agents. The frontmatter establishes the agent’s identity, while the markdown body serves as its system prompt. Think of it as briefing a specialist: --- name: security-reviewer description: Security-focused code reviewer. Use proactively after writing authentication, authorization, or data handling code. tools: Read, Grep, Glob --- You are a senior security engineer specializing in application security. Review priorities: 1. Authentication and authorization flaws 2. Injection vulnerabilities SQL, XSS, command 3. Data exposure and sensitive information handling 4. Cryptographic weaknesses 5. Insecure direct object references For each finding, provide: severity Critical/High/Medium/Low , location file:line , description, and a concrete fix with code example. When invoked: run git diff HEAD first to focus on changed code. The tools field limits which tools the agent can access. A security reviewer only needs Read , Grep , and Glob . No write permissions required. An implementation agent, on the other hand, needs the complete toolset. Restricting tools makes agents both safer and more predictable. If you leave out the tools field, the agent inherits every available tool. Beyond basic tool access, the frontmatter supports a range of powerful configuration options. The model field selects which model the agent runs on: haiku for quick lightweight tasks, sonnet for balanced workloads, or opus for complex reasoning. Use inherit to take the parent’s model. The effort field controls reasoning depth on supported models, accepting values low , medium , high , xhigh , max , and auto . maxTurns limits how long the agent can run, and permissionMode sets the permission level. Additional fields include disallowedTools , skills to preload specific skills, mcpServers for agent-scoped MCP access, and initialPrompt to automatically submit the first turn. The memory field gives agents persistent storage that survives across sessions. The first 200 lines of a MEMORY.md file in the agent’s memory directory are automatically loaded into its system prompt. Claude writes to this file as it learns: --- name: researcher memory: user description: Long-running research assistant with persistent notes --- You are a research assistant. Check your MEMORY.md at session start to recall previous findings. Update it with new discoveries. Setting isolation: worktree gives the agent its own git worktree and branch, so it can make changes without touching your main working tree. When the agent completes, it returns the worktree path and branch name for you to review and merge. If no changes were made, the worktree is automatically cleaned up. While the agent is running, Claude locks the worktree to prevent concurrent cleanup, releasing the lock once it finishes. The worktree branches from your repository’s default branch origin/HEAD unless you configure worktree.baseRef to head in settings, which makes isolated agents start from your local HEAD and carry along unpushed work. Setting background: true forces the agent to always run as a background task, freeing up the main conversation. You can also press Ctrl+B to background an agent that’s currently running in the foreground. Two CLI flags extend what a session can reach. --add-dir