Team-spawned agents: agent frontmatter hooks don't fire, MCP servers not inherited, agent_type missing from hook payloads

Resolved 💬 4 comments Opened Mar 11, 2026 by Butanium Closed May 11, 2026

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:

  1. Hooks defined in frontmatter don't fire — PreToolUse hooks in the agent .md file are silently skipped
  2. mcpServers from 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)
  3. agent_type is missing from hook payloads — when hooks are moved to settings.json as a workaround, the hook input JSON has no agent_type field 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/*.md frontmatter should fire for team-spawned agents
  • MCP servers listed in mcpServers: should be started and available to the teammate
  • agent_type in hook payloads should match the subagent_type passed 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.log is never created → frontmatter hook didn't fire
  • /tmp/hook_debug.log entries for the teammate have no agent_type field
  • MCP tools from my-server return "No such tool available"
  • The teammate's transcript JSONL has agentName and teamName but 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

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗