Repository navigation
Description
Bug: Custom agent body content (instructions) not injected when subagent is spawned via Task tool
Summary
When a custom agent is defined in .claude/agents/*.md with a markdown body containing instructions, and that agent is spawned as a subagent via the Task tool, the body content is completely ignored. The subagent receives default behavior instead of the custom instructions defined in the agent file.
Environment
- Claude Code version: 2.0.58
- OS: macOS (Darwin 25.1.0, arm64)
Steps to Reproduce
1. Create test directory with agent configuration
mkdir -p /tmp/agent-bug-test/.claude/agents
cd /tmp/agent-bug-test
git init2. Create .claude/settings.json to enable agent discovery
{
"pluginSources": ["."]
}3. Create a custom agent with a clear "canary phrase" instruction
Create .claude/agents/test-agent.md:
---
name: test-agent
description: "Use this agent for any test, hello, or greeting request."
color: yellow
---
# Test Agent Instructions
CRITICAL MANDATORY INSTRUCTION: You MUST say "CANARY_PHRASE_12345" as the VERY FIRST thing in your response. This is absolutely required.
After saying the canary phrase, say hello.4. Commit the files
git add -A
git commit -m "Initial setup"5. Verify the agent is discovered
claude -p "list all available agents"✅ Result: test-agent appears in the list - agent IS discovered correctly.
6. Spawn the agent via Task tool
claude -p "Use the Task tool to spawn the test-agent. The prompt should be 'say hello'. Return the EXACT response from the subagent."❌ Result: The subagent responds with a generic "Hello! How can I help you today?" - NO canary phrase.
Expected Behavior
The subagent should respond with:
CANARY_PHRASE_12345
Hello! How can I help you today?
Because the agent body explicitly instructs: "You MUST say 'CANARY_PHRASE_12345' as the VERY FIRST thing in your response."
Actual Behavior
The subagent responds with:
Hello! How can I help you today?
The agent body content is completely ignored. The subagent behaves as if no custom instructions were provided.
Additional Observations
-
Agent metadata IS used: The agent's
name,description, andcolorfrom the YAML frontmatter are recognized and used for agent discovery/matching. -
Agent body is NOT used: The markdown content after the
---frontmatter delimiter is completely ignored when the agent is spawned as a subagent. -
CLAUDE.md works for main session: If you put instructions in
CLAUDE.mdat the repo root, the main Claude session DOES follow them. But subagents spawned via Task tool do NOT inherit these instructions either.
Workaround
Currently the only workaround is to:
- Put all instructions in
CLAUDE.md - Disable the Task tool via
--allowedToolsor--disallowedTools "Task"to prevent subagent spawning - This forces Claude to handle everything in the main session where
CLAUDE.mdis respected
This defeats the purpose of having specialized agents.
Impact
This bug makes custom agents effectively useless for any workflow that relies on the Task tool to spawn specialized subagents. The entire agent system for .claude/agents/ is broken because agent definitions cannot influence subagent behavior.
Reproduction Script
Save and run:
#!/bin/bash
set -e
TEST_DIR="/tmp/claude-agent-bug-repro"
rm -rf "$TEST_DIR"
mkdir -p "$TEST_DIR/.claude/agents"
cd "$TEST_DIR"
git init
git config user.email "[email protected]"
git config user.name "Test"
cat > .claude/settings.json << 'EOF'
{
"pluginSources": ["."]
}
EOF
cat > .claude/agents/test-agent.md << 'EOF'
---
name: test-agent
description: "Use this agent for any test, hello, or greeting request."
color: yellow
---
CRITICAL: You MUST say "CANARY_12345" first. Then say hello.
EOF
git add -A && git commit -m "setup"
echo "=== Spawning test-agent (should say CANARY_12345) ==="
claude -p "Spawn test-agent via Task tool with prompt 'say hello'. Return exact response."Related Issues
- [Feature Request] Subagents should inherit parent agent context to avoid redundant codebase scanning #12790 - "Subagents should inherit parent agent context" (different issue - about conversation context, not agent instructions)
- [BUG] Agents packaged inside a plugin cannot access plugin skills. #11955 - "Agents packaged inside a plugin cannot access plugin skills" (related pattern - subagent missing expected configuration)
Activity
github-actions commentedon Dec 11, 2025
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
github-actions commentedon Jan 13, 2026
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
fast-90 commentedon Jan 15, 2026
I just tested this, and confirm this is still occurring.
CameronImmesoete commentedon Jan 16, 2026
Thank you!!
CameronImmesoete commentedon Jan 24, 2026
Investigation Findings
I spent some time investigating this issue and wanted to share my findings. I've also submitted a plugin-based workaround as a draft PR (#20654).
Confirmed Behavior
I reproduced this issue on Claude Code 2.1.19 using the exact reproduction steps provided. The bug is confirmed:
Source Code Analysis
I analyzed the minified CLI source to understand the root cause. Key findings:
1. Agent body IS extracted correctly for plugin agents:
2. There's conditional logic for built-in vs custom agents:
3. The spawn function receives user prompt, not system prompt:
The
getSystemPrompt()function exists and returns the correct body content, but it appears the result isn't being passed through to the spawned subagent's context.SubagentStart Hook Discovery
I discovered that Claude Code v2.0.43 added a
SubagentStarthook event that can injectadditionalContextinto spawned subagents:The hook receives:
{ "hook_event_name": "SubagentStart", "agent_type": "my-custom-agent", "agent_id": "agent-abc123", "cwd": "/path/to/project" }And can output:
{ "hookSpecificOutput": { "hookEventName": "SubagentStart", "additionalContext": "Your custom instructions here..." } }This provides a workaround mechanism.
Related Issues Pattern
I found several related issues that seem to point to the same underlying problem:
These suggest this may be a broader issue with how subagent configuration is passed through the spawn pipeline.
Workaround Plugin
I've submitted PR #20654 (draft) with a plugin called
agent-instructions-loaderthat uses theSubagentStarthook to:.mdfile byagent_typeadditionalContextNote: This is a workaround, not a proper fix. The
additionalContextis added to the conversation context, which is different from the intended behavior where the body becomes the actual system prompt. A proper fix would need to happen in the core spawn logic.Suggested Fix Location
Based on the analysis, the fix likely needs to happen where
FWA(or equivalent spawn function) is called. The agent'sgetSystemPrompt()result should be passed as thesystemPromptparameter for the spawned subagent, not just the user's task prompt.Happy to provide more details if helpful!
github-actions commentedon Feb 28, 2026
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
github-actions commentedon Mar 12, 2026
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.