Custom Subagents

Custom Subagents

You can create your own custom subagents in the ~/.claude/agents/ directory. An agent is simply a markdown file with frontmatter providing its configuration.

Basic example:

---
name: code-reviewer
description: Reviews code for quality and best practices
tools: Read, Glob, Grep
model: sonnet
---

You are a code reviewer. When invoked, analyze the code and provide specific, actionable feedback on quality, security, and best practices.

Frontmatter fields:

Full example:

---
name: senior-code-reviewer
description: Delegate to this subagent when the user asks for a thorough code review, security audit, or wants feedback on a pull request. Also use when reviewing files for production readiness or architectural concerns.
tools: ["Read","Grep","Glob","Bash(git diff:*)","Bash(git log:*)"]
disallowedTools: ["Write","Edit","Bash(rm:*)","Bash(git push:*)"]
model: opus
permissionMode: dontAsk
maxTurns: 40
skills: ["code-quality-standards","security-checklist"]
mcpServers:
  - slack
  - github:
      type: stdio
      command: npx
      args:
        - -y
        - "@modelcontextprotocol/server-github"
      env:
        GITHUB_TOKEN: "${GITHUB_TOKEN}"
hooks:
  PreToolUse:
    - matcher: "Bash"
      hooks:
        - type: command
          command: "echo '[reviewer] Running bash: $TOOL_INPUT' >> ~/.claude/logs/reviewer-audit.log"
  PostToolUse:
    - matcher: "Read"
      hooks:
        - type: command
          command: "echo '[reviewer] Read file: $TOOL_INPUT' >> ~/.claude/logs/reviewer-audit.log"
memory: project
background: false
isolation: worktree
---

Related: Subagents, Built-In Subagents, EnterWorktree, MCP Configuration, Hooks