--- topic: agent-definition source_keys: - context7-websites-code-claude - claude-code-plugins-docs - claude-code-subagents-docs --- ## File Format Agent definitions are Markdown files with YAML frontmatter. Place them in an `agents/` directory at the plugin root (for plugin-distributed agents) or in `.claude/agents/` (project scope) or `~/.claude/agents/` (user scope). ```markdown --- name: code-reviewer description: Reviews code for correctness, security, and maintainability. Use proactively after code changes. tools: Read, Grep, Glob, Bash model: sonnet effort: medium maxTurns: 20 --- You are a senior code reviewer. When invoked, analyze the changed code and provide specific, actionable feedback on quality, security, and best practices. ``` The frontmatter block configures the agent's identity and constraints. The body is the system prompt. ## Required Fields **`name`** — Unique identifier. Lowercase letters and hyphens only. Hooks receive this as `agent_type`. The filename does not need to match the name field. Duplicate names within the same scope level: Claude Code silently keeps one and discards the other without warning. **`description`** — Tells Claude when to delegate to this agent. This is the most important field for autonomous delegation. Include "use proactively" to trigger automatic invocation without explicit user direction. Be specific about the triggering condition and the agent's expertise. ## Optional Fields **`tools`** — Allowlist of tool names the agent can use. Omit to inherit all tools from the parent. Comma-separated or YAML list. Use `Agent(type1,type2)` to restrict which subagent types this agent can spawn; `Agent` without parens allows spawning any subagent; omitting `Agent` entirely prevents spawning. **`disallowedTools`** — Denylist applied before `tools`. Supports `mcp__` (one server's tools), `mcp____*` (glob), and `mcp__*` (removes all MCP tools). Takes precedence over `tools`. **`model`** — Model to use. Accepts aliases (`sonnet`, `opus`, `haiku`, `fable`), full model IDs (`claude-opus-4-8`), or `inherit` (default). Resolution order: `CLAUDE_CODE_SUBAGENT_MODEL` env var → per-invocation model parameter → frontmatter model → main conversation model. If the resolved model is excluded by `availableModels` policy, falls back to the inherited model. **`effort`** — Reasoning level: `low`, `medium`, `high`, `xhigh`, `max`, or a numeric value. Overrides the session effort level for this agent. **`maxTurns`** — Integer cap on agentic turns. Prevents runaway agents. **`permissionMode`** — One of `default`, `acceptEdits`, `auto`, `dontAsk`, `bypassPermissions`, `plan`. Silently ignored for plugin subagents — only works for `.claude/agents/` and `~/.claude/agents/`. Parent `bypassPermissions` or `acceptEdits` overrides child; parent `auto` mode overrides child permissionMode entirely. **`skills`** — List of skill names to preload into the agent's context at startup (full skill body injected). Enables the agent to invoke skills by name. **`mcpServers`** — Inline MCP server definitions (stdio/http/sse/ws schema keyed by server name) or string references to already-configured servers. Silently ignored for plugin subagents. **`hooks`** — Per-agent `PreToolUse`/`PostToolUse`/`Stop` event handlers scoped to this agent's context. `Stop` auto-converts to `SubagentStop` when used as a subagent. Silently ignored for plugin subagents. **`memory`** — Persistent cross-session memory: `user` (stored at `~/.claude/agent-memory//`), `project` (`.claude/agent-memory//`), or `local` (`.claude/agent-memory-local//`). Enables MEMORY.md (first 200 lines/25KB loaded at startup). Auto-enables Read/Write/Edit tools. **`background`** — Boolean. Forces background execution when `true` (default `false`). **`isolation`** — Set to `worktree` to run the agent in an isolated temporary git worktree branched from the default branch. Auto-cleaned if no changes are made. **`color`** — UI color for this agent: `red`, `blue`, `green`, `yellow`, `purple`, `orange`, `pink`, `cyan`. **`initialPrompt`** — Auto-submitted as the first user turn when the agent runs as the main session (via `--agent` flag or `agent` setting in `settings.json`). Supports commands and skills. Prepended to the user's own prompt. ## TypeScript AgentDefinition Shape ```typescript type AgentDefinition = { description: string; tools?: string[]; disallowedTools?: string[]; prompt: string; // equivalent to the markdown body model?: string; mcpServers?: AgentMcpServerSpec[]; skills?: string[]; initialPrompt?: string; maxTurns?: number; background?: boolean; memory?: "user" | "project" | "local"; effort?: "low" | "medium" | "high" | "xhigh" | "max" | number; permissionMode?: PermissionMode; criticalSystemReminder_EXPERIMENTAL?: string; }; ``` When passing agents via the `--agents` CLI flag, use `prompt` instead of the markdown body. ## Tools Always Unavailable to Subagents Regardless of the `tools` field, these tools are never available to any subagent: - `AskUserQuestion` - `EnterPlanMode` - `ExitPlanMode` (unless `permissionMode` is `plan`) - `ScheduleWakeup` - `WaitForMcpServers` ## Plugin Subagent Restrictions Plugin agents (in a plugin's `agents/` directory) silently ignore: `hooks`, `mcpServers`, and `permissionMode`. To use those features, copy the agent file into `.claude/agents/` or `~/.claude/agents/`. ## Scoped Identifiers for Plugin Agents Unlike project/user scope agents where subdirectory path doesn't affect identity, plugin agents in subfolders get scoped identifiers: ``` plugins/my-plugin/agents/review/security.md → my-plugin:review:security ``` Users invoke these via `@agent-my-plugin:review:security` or the `/agents` UI.