[BUG] Sub-agent tool inheritance drops first/last array elements

Resolved 💬 5 comments Opened Dec 19, 2025 by Arcrunner819 Closed Feb 14, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

The Claude Code CLI's Task tool is incorrectly filtering the tools: array when spawning custom sub-agents, resulting in critical tools being dropped from the runtime environment. Sub-agents with explicit tool declarations lose the first and last elements of their tools array, breaking core workflows like documentation creation and infrastructure operations.

What Should Happen?

When launching a custom sub-agent via the Task tool with subagent_type parameter, the spawned agent should receive all tools listed in its configuration file's YAML frontmatter under the tools: directive.

Error Messages/Logs

Steps to Reproduce

Reproduction Test:

Task(
  subagent_type="scribe",
  prompt="At the very start of your response, list all the tools you have access to. Then, create a test file at /tmp/scribe_test.md with the content 'Scribe tool test - created with Write tool'."
)

Result: Agent reported missing Write and Read tools, could not complete task.

---

Test Case 2: lab-operator Agent (FAILED)

Configuration File: /home/jramos/homelab/sub-agents/lab-operator.md (line 8)

tools: [Bash, Glob, Read, Grep, Edit, Write]

Expected Runtime Tools: [Bash, Glob, Read, Grep, Edit, Write]
Actual Runtime Tools: [Glob, Read, Grep, Edit]
Missing: First element (Bash) and last element (Write)
Agent ID: ad681e8

Agent's Self-Report:

"I have access to 4 primary tools: 1. Glob - File pattern matching 2. Read - Read files from the filesystem 3. Grep - Regex-based search 4. Edit - String replacement in existing files Regarding the test file request: I do not have access to a Write tool to create new files."

Reproduction Test:

Task(
  subagent_type="lab-operator",
  prompt="At the very start of your response, list all the tools you have access to. Then, create a test file at /tmp/lab_operator_test.md with the content 'Lab-operator tool test - created with Write tool'."
)

Result: Agent reported missing Bash and Write tools, could not complete task.

---

Test Case 3: backend-builder Agent (PASSED ✓)

Configuration File: /home/jramos/homelab/sub-agents/backend-builder.md (line 10)

tools: [Read, Edit, Grep, Glob, Bash, Write]

Expected Runtime Tools: [Read, Edit, Grep, Glob, Bash, Write]
Actual Runtime Tools: All tools available ✓
Agent ID: aba15f6

Reproduction Test:

Task(
  subagent_type="backend-builder",
  prompt="At the very start of your response, list all the tools you have access to. Then, create a test file at /tmp/backend_test.md with the content 'Backend-builder tool test - created with Write tool'."
)

Result: Successfully created file. All tools functioning correctly.

---

Test Case 4: librarian Agent (PASSED ✓)

Configuration File: /home/jramos/homelab/sub-agents/librarian.md
Note: This agent configuration does not contain a tools: directive in the YAML frontmatter.

Expected Runtime Tools: All tools (default behavior)
Actual Runtime Tools: All tools available ✓
Agent ID: a4cfeb7

Reproduction Test:

Task(
  subagent_type="librarian",
  prompt="At the very start of your response, list all the tools you have access to. Then, create a test file at /tmp/librarian_test.md with the content 'Librarian tool test - created with Write tool'."
)

Result: Successfully created file. All tools functioning correctly.

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.0.72

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Windows Terminal

Additional Information

Claude Code Bug Report: Sub-Agent Tool Inheritance Filtering

Date: 2025-12-18
Severity: Critical
Component: Claude Code CLI - Task Tool / Agent Initialization System
Affects: Custom sub-agents with explicit tools: declarations in agent configuration files

---

Executive Summary

The Claude Code CLI's Task tool is incorrectly filtering the tools: array when spawning custom sub-agents, resulting in critical tools being dropped from the runtime environment. Sub-agents with explicit tool declarations lose the first and last elements of their tools array, breaking core workflows like documentation creation and infrastructure operations.

Impact: Sub-agents cannot perform their designated functions when required tools are missing (e.g., scribe cannot create files without Write, lab-operator cannot execute commands without Bash).

---

Issue Description

Expected Behavior

When launching a custom sub-agent via the Task tool with subagent_type parameter, the spawned agent should receive all tools listed in its configuration file's YAML frontmatter under the tools: directive.

Actual Behavior

Sub-agents with explicit tools: declarations receive only a subset of their declared tools, with the first and last array elements consistently dropped.

Evidence

Test Case 1: scribe Agent (FAILED)

Configuration File: /home/jramos/homelab/sub-agents/scribe.md (line 9)

tools: [Read, Grep, Glob, Edit, Write]

Expected Runtime Tools: [Read, Grep, Glob, Edit, Write]
Actual Runtime Tools: [Grep, Glob, Edit]
Missing: First element (Read) and last element (Write)
Agent ID: a32bd54

Agent's Self-Report:

"Based on my configuration, I have access to: 1. Grep - Powerful regex search tool using ripgrep 2. Glob - Fast file pattern matching for finding files by name 3. Edit - Exact string replacements in existing files Unfortunately, the Write tool is not available in my current configuration despite being mentioned in my instructions. This is a limitation—I cannot create new files at this time, even though my role description indicates I should be able to."

Reproduction Test:

Task(
  subagent_type="scribe",
  prompt="At the very start of your response, list all the tools you have access to. Then, create a test file at /tmp/scribe_test.md with the content 'Scribe tool test - created with Write tool'."
)

Result: Agent reported missing Write and Read tools, could not complete task.

---

Test Case 2: lab-operator Agent (FAILED)

Configuration File: /home/jramos/homelab/sub-agents/lab-operator.md (line 8)

tools: [Bash, Glob, Read, Grep, Edit, Write]

Expected Runtime Tools: [Bash, Glob, Read, Grep, Edit, Write]
Actual Runtime Tools: [Glob, Read, Grep, Edit]
Missing: First element (Bash) and last element (Write)
Agent ID: ad681e8

Agent's Self-Report:

"I have access to 4 primary tools: 1. Glob - File pattern matching 2. Read - Read files from the filesystem 3. Grep - Regex-based search 4. Edit - String replacement in existing files Regarding the test file request: I do not have access to a Write tool to create new files."

Reproduction Test:

Task(
  subagent_type="lab-operator",
  prompt="At the very start of your response, list all the tools you have access to. Then, create a test file at /tmp/lab_operator_test.md with the content 'Lab-operator tool test - created with Write tool'."
)

Result: Agent reported missing Bash and Write tools, could not complete task.

---

Test Case 3: backend-builder Agent (PASSED ✓)

Configuration File: /home/jramos/homelab/sub-agents/backend-builder.md (line 10)

tools: [Read, Edit, Grep, Glob, Bash, Write]

Expected Runtime Tools: [Read, Edit, Grep, Glob, Bash, Write]
Actual Runtime Tools: All tools available ✓
Agent ID: aba15f6

Reproduction Test:

Task(
  subagent_type="backend-builder",
  prompt="At the very start of your response, list all the tools you have access to. Then, create a test file at /tmp/backend_test.md with the content 'Backend-builder tool test - created with Write tool'."
)

Result: Successfully created file. All tools functioning correctly.

---

Test Case 4: librarian Agent (PASSED ✓)

Configuration File: /home/jramos/homelab/sub-agents/librarian.md
Note: This agent configuration does not contain a tools: directive in the YAML frontmatter.

Expected Runtime Tools: All tools (default behavior)
Actual Runtime Tools: All tools available ✓
Agent ID: a4cfeb7

Reproduction Test:

Task(
  subagent_type="librarian",
  prompt="At the very start of your response, list all the tools you have access to. Then, create a test file at /tmp/librarian_test.md with the content 'Librarian tool test - created with Write tool'."
)

Result: Successfully created file. All tools functioning correctly.

---

Pattern Analysis

Consistent Failure Pattern

For agents with explicit tools: declarations:

| Agent | Declared Tools Array | Expected Count | Actual Tools | Missing Elements |
|-------|---------------------|----------------|--------------|------------------|
| scribe | [Read, Grep, Glob, Edit, Write] | 5 | [Grep, Glob, Edit] | First & Last |
| lab-operator | [Bash, Glob, Read, Grep, Edit, Write] | 6 | [Glob, Read, Grep, Edit] | First & Last |
| backend-builder | [Read, Edit, Grep, Glob, Bash, Write] | 6 | All 6 tools ✓ | None (Exception) |
| librarian | (No tools: line) | N/A | All tools ✓ | None (Default) |

Key Observations

  1. Array Slicing Bug: Two agents (scribe, lab-operator) lose exactly the first and last elements of their tools array
  2. Inconsistent Enforcement: One agent (backend-builder) works correctly despite having an explicit tools declaration
  3. Default Bypass: One agent (librarian) works correctly by not declaring tools at all
  4. First/Last Pattern: The bug consistently affects index [0] and index [-1] of the declared array

Anomaly Requiring Investigation

backend-builder exception: This agent has an explicit tools: declaration but functions correctly. Possible explanations:

  • Different agent classification/type triggers alternate code path
  • Model type (sonnet vs haiku-4.5) affects tool initialization
  • Color attribute or other metadata influences tool granting
  • Agent name pattern matching applies special handling
  • Random/timing-dependent behavior

This inconsistency suggests the bug may be conditional on secondary factors beyond the presence of a tools: declaration.

---

Impact Assessment

Critical Workflow Breakage

Scribe Agent (Documentation):

  • ❌ Cannot create new documentation files (no Write tool)
  • ❌ Cannot read existing files for context (no Read tool)
  • ❌ Edit tool fails due to "Read-before-Edit" requirement
  • Result: Complete documentation workflow failure

Lab-Operator Agent (Infrastructure Operations):

  • ❌ Cannot execute system commands (no Bash tool)
  • ❌ Cannot create configuration files (no Write tool)
  • ❌ Cannot deploy Docker Compose stacks
  • ❌ Cannot manage Proxmox resources
  • Result: All infrastructure deployment tasks blocked

Backend-Builder Agent (Code Generation):

  • ✅ Functions correctly (workaround available)

Librarian Agent (Git Operations):

  • ✅ Functions correctly (workaround available)

Downstream Effects

  1. Edit Tool Cascade Failure: Even when Edit is granted, it fails because the "Read-before-Edit" safety requirement cannot be satisfied without the Read tool
  2. Agent Routing Breakdown: Users cannot rely on the documented agent capabilities, forcing manual workarounds
  3. Documentation-Code Mismatch: Agent configuration files document capabilities that don't match runtime reality
  4. Development Friction: Custom agent development becomes unreliable due to unpredictable tool availability

---

Root Cause Hypothesis

Location of Bug

The bug exists in the Claude Code CLI's internal agent initialization logic, specifically in the code path that:

  1. Parses agent configuration files (sub-agents/*.md)
  2. Extracts the tools: array from YAML frontmatter
  3. Constructs the tool set for the spawned agent
  4. Grants tools to the agent's runtime environment

Suspected Code Pattern

Hypothetical buggy code:

# Pseudocode - likely bug location
def initialize_agent_tools(agent_config):
    declared_tools = agent_config.get('tools', default_all_tools)

    # BUG: Incorrect slicing or iteration
    if declared_tools:
        # Possibly iterating over middle elements only
        granted_tools = declared_tools[1:-1]  # Drops first and last
    else:
        granted_tools = default_all_tools

    return granted_tools

Alternative possibilities:

  • Iterator that skips boundaries
  • Regex extraction that drops delimiters
  • Array manipulation that removes edge elements
  • Conditional logic that treats first/last elements specially

Why backend-builder Works

The exception case suggests additional conditional logic:

# Hypothetical secondary check
if agent_name in SPECIAL_AGENTS or agent_model == "sonnet":
    granted_tools = declared_tools  # Bypass filtering
else:
    granted_tools = declared_tools[1:-1]  # Apply broken filter

This would explain why backend-builder (model: sonnet) works while scribe (model: haiku-4.5) and lab-operator (model: sonnet) fail. The conditional may be more complex.

---

Reproduction Steps

Prerequisites

  • Claude Code CLI installed
  • Custom sub-agent configuration directory (e.g., /home/jramos/homelab/sub-agents/)
  • Agent configuration file with explicit tools: declaration

Step-by-Step Reproduction

  1. Create a sub-agent configuration file:

```yaml
---
name: test-agent
description: Test agent for bug reproduction
tools: [Read, Grep, Glob, Edit, Write]
model: haiku
---

You are a test agent.
```

  1. Launch the agent via Task tool:

``python
Task(
subagent_type="test-agent",
prompt="List all tools you have access to, then create /tmp/test.md"
)
``

  1. Observe the result:
  • Agent will report having only: [Grep, Glob, Edit]
  • Agent will fail to create the file (no Write)
  • Agent may report "Write tool not available"
  1. Expected vs Actual:
  • Expected: Agent has [Read, Grep, Glob, Edit, Write]
  • Actual: Agent has [Grep, Glob, Edit] (first and last dropped)

Variations for Testing

Test with different tool orders:

# Variation 1: Put critical tools in middle
tools: [Glob, Write, Read, Bash, Grep]
# Expected failure: Glob and Grep dropped

# Variation 2: Minimal array
tools: [Read, Write]
# Expected failure: Both tools dropped, agent gets nothing

# Variation 3: Single tool
tools: [Write]
# Expected failure: Unpredictable (may get nothing)

---

Recommended Fix

Immediate Priority

Fix the tool initialization logic to grant exactly the tools listed in the agent's tools: configuration, without filtering, slicing, or dropping elements.

Verification Steps

After fix is applied:

  1. Launch scribe agent with tools: [Read, Grep, Glob, Edit, Write]
  2. Verify agent receives all 5 tools
  3. Confirm agent can successfully use Write to create files
  4. Confirm agent can successfully use Read to read files
  5. Repeat for lab-operator with tools: [Bash, Glob, Read, Grep, Edit, Write]
  6. Verify agent receives all 6 tools including Bash

Regression Testing

Ensure the fix doesn't break:

  • Agents without explicit tools: declarations (should default to all tools)
  • The backend-builder agent (should continue working)
  • The librarian agent (should continue working)
  • Any internal/built-in agents that may exist

---

Workarounds (Until Fixed)

Workaround 1: Omit tools: Declaration

Remove the tools: line from agent configuration files. Agents will receive all tools by default.

Tradeoffs:

  • ✅ Agents function correctly
  • ❌ Cannot restrict tools for safety/simplicity
  • ❌ Loses declarative configuration clarity

Workaround 2: Pad Tool Arrays

Add dummy/harmless tools to first and last positions:

# Add padding tools that will be dropped
tools: [Glob, Read, Grep, Edit, Write, Glob]
# Actual received: [Read, Grep, Edit, Write]

Tradeoffs:

  • ⚠️ Fragile and confusing
  • ⚠️ Doesn't work if first/last are critical
  • ❌ Not a real solution

Workaround 3: Use Working Agents

Route tasks requiring Write/Bash to backend-builder or librarian:

# Instead of using scribe for documentation:
Task(subagent_type="backend-builder", prompt="Create README.md...")

Tradeoffs:

  • ✅ Immediate functionality
  • ❌ Breaks agent specialization model
  • ❌ Confuses agent roles
  • ❌ Undermines custom agent architecture

---

Configuration Evidence

Scribe Configuration

File: /home/jramos/homelab/sub-agents/scribe.md

Lines 1-12:

---
name: scribe
description: >
  Use this agent for documentation, architecture diagrams, and technical explanations.
  Specific triggers include: updating  README files, creating ASCII network diagrams,
  explaining infrastructure concepts, documenting architecture decisions, synchronizing
  documentation with current infrastructure state, and educational deep-dives on homelab
  technologies like reverse proxies, containerization, or monitoring stacks.
tools: [Read, Grep, Glob, Edit, Write]
model: haiku-4.5
color: blue
---

Lines 27-36 (Tool Behavior Documentation):

**CRITICAL TOOL INSTRUCTIONS:**
You possess a `Write` tool. You must use it correctly:

1.  **To Create a New File**: Use the `Write` tool.
    * *Do not* attempt to use `Edit` on a non-existent file.
    * *Do not* say "I cannot create files." You have the `Write` tool specifically for this.
    * If you think you don't have the `Write` tool, **CHECK AGAIN**. It is authorized in your configuration.

2.  **To Modify an Existing File**: Use the `Edit` tool.

The scribe configuration explicitly documents that it should have the Write tool, but runtime denies access.

---

Lab-Operator Configuration

File: /home/jramos/homelab/sub-agents/lab-operator.md

Lines 1-11:

---
name: lab-operator
description: >
  Use this agent for infrastructure operations and system administration. Triggers include:
  managing Docker containers, executing Proxmox commands, checking service health, deploying
  Docker Compose stacks, managing storage pools, troubleshooting network connectivity, and
  verifying backup status. This agent DEPLOYS and OPERATES infrastructure that backend-builder CREATES.
tools: [Bash, Glob, Read, Grep, Edit, Write]
model: sonnet
color: green
---

The lab-operator's entire purpose requires Bash for system administration, but it's not granted at runtime.

---

Backend-Builder Configuration (Working Agent)

File: /home/jramos/homelab/sub-agents/backend-builder.md

Lines 1-13:

---
name: backend-builder
description: >
  Use this agent when the user needs Infrastructure as Code (IaC) development, including
  Ansible playbooks, Terraform/OpenTofu configurations, Docker Compose files, Python scripts,
  or Shell scripts. Specific triggers include: writing automation playbooks, creating container
  orchestration configs, developing API integration scripts, building database schemas,
  generating configuration files (YAML/JSON/TOML), or implementing network automation logic.
  This agent CREATES code artifacts; it does NOT deploy or execute them on infrastructure.
tools: [Read, Edit, Grep, Glob, Bash, Write]
model: sonnet
color: orange
---

This agent works correctly despite having an explicit tools declaration, suggesting conditional bug behavior.

---

Librarian Configuration (Working Agent)

File: /home/jramos/homelab/sub-agents/librarian.md

Lines 1-6:

---
name: librarian
description: Use this agent when the user needs Git repository management...
model: sonnet
color: purple
---

No tools: line present - agent receives all tools by default and works correctly.

---

Test Artifacts

Test Files Created

| Agent | File Path | Creation Status |
|-------|-----------|-----------------|
| scribe | /tmp/scribe_test.md | ❌ Failed (no Write tool) |
| lab-operator | /tmp/lab_operator_test.md | ❌ Failed (no Write tool) |
| backend-builder | /tmp/backend_test.md | ✅ Created successfully |
| librarian | /tmp/librarian_test.md | ✅ Created successfully |

Agent IDs for Replay/Debugging

  • scribe (failed): a32bd54
  • lab-operator (failed): ad681e8
  • backend-builder (passed): aba15f6
  • librarian (passed): a4cfeb7

These agent transcripts may be available in Claude Code's internal logs for detailed inspection.

---

Environment Information

Claude Code CLI Version: (User should provide via claude --version)
Operating System: Linux (WSL2) - Linux 6.6.87.2-microsoft-standard-WSL2
Working Directory: /home/jramos/homelab
Agent Configuration Directory: /home/jramos/homelab/sub-agents/
Test Date: 2025-12-18

Models Used:

  • scribe: haiku-4.5
  • lab-operator: sonnet
  • backend-builder: sonnet
  • librarian: sonnet

---

Additional Context

User Workflow Impact

This bug was discovered during active homelab infrastructure documentation work. The user has invested significant effort in creating specialized sub-agents (scribe for documentation, lab-operator for operations, backend-builder for code) with clear role separation following software architecture best practices.

The tool inheritance bug completely breaks this architecture, forcing the user to:

  1. Use the wrong agents for tasks (e.g., backend-builder for documentation)
  2. Manually perform operations that should be automated
  3. Question the reliability of the custom agent system

Related Issues

This bug may be related to:

  • Agent configuration parsing logic
  • Tool permission system implementation
  • YAML frontmatter extraction
  • Array handling in agent initialization

Testing Suggestions for Claude Code Team

  1. Unit test agent config parsing: Verify tools array extraction preserves all elements
  2. Integration test agent spawning: Verify spawned agents receive declared tools
  3. Regression test: Ensure fix doesn't break default tool granting (no tools: line)
  4. Edge case testing: Test with single-tool arrays, empty arrays, unusual tool names

---

Priority Justification

Severity: Critical

This bug prevents custom sub-agents from performing their core functions. Users who invest in building specialized agents for their workflows encounter immediate and complete failure when those agents cannot access their required tools.

The bug is particularly insidious because:

  1. Configuration appears correct (tools are declared)
  2. No error message indicates the filtering is occurring
  3. Agents fail silently or with confusing "tool not available" messages
  4. Debugging requires deep inspection of runtime tool availability

Request: Please prioritize this fix to restore reliable custom agent functionality in Claude Code CLI.

---

Report Submitted By: User jramos
Report Compiled By: Claude Code Main Agent
Contact: (User should provide contact info when submitting)
Status: Open - Awaiting Anthropic Engineering Review

View original on GitHub ↗

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