Team-spawned agents: agent frontmatter hooks don't fire, MCP servers not inherited, agent_type missing from hook payloads
Bug Description
When spawning teammates via the Agent tool with team_name and a custom subagent_type pointing to a .claude/agents/*.md definition, the agent frontmatter is largely ignored:
- Hooks defined in frontmatter don't fire — PreToolUse hooks in the agent
.mdfile are silently skipped mcpServersfrom frontmatter are not available — MCP servers listed in the agent definition are not started for the teammate, even though they work for the parent session (launched with--mcp-config)agent_typeis missing from hook payloads — when hooks are moved tosettings.jsonas a workaround, the hook input JSON has noagent_typefield for teammates, making it impossible to scope restrictions by agent type
Note: direct subagents (without team_name) do get agent_type in hook payloads correctly. This bug is specific to team-spawned agents.
Expected Behavior
- Hooks defined in
.claude/agents/*.mdfrontmatter should fire for team-spawned agents - MCP servers listed in
mcpServers:should be started and available to the teammate agent_typein hook payloads should match thesubagent_typepassed to the Agent tool, for both direct subagents and teammates
Minimal Reproduction
1. Create an agent definition .claude/agents/restricted.md:
---
name: restricted
description: Agent with restrictions
tools: Read, Bash
mcpServers:
- my-server
hooks:
PreToolUse:
- matcher: "Bash"
hooks:
- type: command
command: 'echo "HOOK FIRED" >> /tmp/agent_hook.log'
---
You are a restricted agent.
2. Add a debug hook to .claude/settings.json:
{
"hooks": {
"PreToolUse": [{
"matcher": ".*",
"hooks": [{
"type": "command",
"command": "python3 -c \"import json,sys; open('/tmp/hook_debug.log','a').write(json.dumps(json.load(sys.stdin))+chr(10))\""
}]
}]
}
}
3. Spawn as a teammate:
TeamCreate(team_name="test")
Agent(name="test-agent", subagent_type="restricted", team_name="test")
4. Have the teammate run echo hello via Bash
Observed
/tmp/agent_hook.logis never created → frontmatter hook didn't fire/tmp/hook_debug.logentries for the teammate have noagent_typefield- MCP tools from
my-serverreturn "No such tool available" - The teammate's transcript JSONL has
agentNameandteamNamebut these are not passed to hooks
Contrast with direct subagent (no team):
Agent(name="test-agent", subagent_type="restricted") # no team_name
In this case, agent_type: "restricted" does appear in hook payloads from settings.json. (Frontmatter hooks still don't fire though — see #30260.)
Impact
This makes it impossible to enforce per-agent-type security restrictions via hooks for team-spawned agents, since there's no way to identify the agent type in the hook script.
Workaround
None fully working. Moving hooks to settings.json works for execution, but without agent_type in the payload, restrictions can't be scoped to specific agent types.
Related Issues
- #30260 — Agent-level hooks in frontmatter don't fire from CLI
- #30703 — Custom agent definitions silently ignored for team agents
Environment
- Claude Code v2.1.72
- Linux
- Tested with
defaultMode: "dontAsk"
🤖 Generated with Claude Code
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗