claude-code - 💡(How to fix) Fix [FEATURE] Subagent Configuration Enhancements: Native `@import` Support and Scope Isolation (Independent Rules/Skills) [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#52767Fetched 2026-04-25 06:21:31
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
1
Author
Timeline (top)
labeled ×2commented ×1

Root Cause

The Current Developer Dilemmas:

  1. No Clean Way to Reuse System Prompts: If multiple subagents need to share the same set of rules, developers must either copy-paste them into every .md file, or instruct the subagent to use the Read tool upon initialization. The latter is slow, wastes tokens, and completely bypasses Prompt Caching benefits. The current community workaround—forcing the Main Agent to load the rules and pass them to the subagent as a User Prompt—is a very dirty hack. It severely pollutes the Main Agent's context window. Furthermore, because the rules are downgraded to a standard User Prompt, the LLM's adherence and stability drop significantly compared to a native System Prompt.
  2. Forced Inheritance of Global Scope (Scope Pollution): Currently, subagents are forced to inherit all project-level rules and skills. This explicitly violates the Principle of Least Privilege. A subagent dedicated strictly to writing unit tests has no business seeing global UI design guidelines in its context window, nor should it possess the permissions or tools to mutate the database.

Fix Action

Fix / Workaround

The Current Developer Dilemmas:

  1. No Clean Way to Reuse System Prompts: If multiple subagents need to share the same set of rules, developers must either copy-paste them into every .md file, or instruct the subagent to use the Read tool upon initialization. The latter is slow, wastes tokens, and completely bypasses Prompt Caching benefits. The current community workaround—forcing the Main Agent to load the rules and pass them to the subagent as a User Prompt—is a very dirty hack. It severely pollutes the Main Agent's context window. Furthermore, because the rules are downgraded to a standard User Prompt, the LLM's adherence and stability drop significantly compared to a native System Prompt.
  2. Forced Inheritance of Global Scope (Scope Pollution): Currently, subagents are forced to inherit all project-level rules and skills. This explicitly violates the Principle of Least Privilege. A subagent dedicated strictly to writing unit tests has no business seeing global UI design guidelines in its context window, nor should it possess the permissions or tools to mutate the database.

Code Example

name: security-reviewer
description: Performs code security audits.
tools: Read, Grep
---
You are a security audit expert.
@./.claude/rules/common-security-guidelines.md
@./.claude/rules/js-specific-rules.md

---

.claude/
  agents/
    security-reviewer/
      AGENT.md          # Main config for this subagent
      rules/            # Local rules exclusively for security-reviewer
      skills/           # Local tools exclusively for security-reviewer

---

name: security-reviewer
inherit_global_rules: false   # Disables global inheritance: ignores project-level .claude/rules/
inherit_global_skills: false  # Disables global inheritance: strictly uses only its own skills directory or explicitly defined tools
---
[System Prompt block here]
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing requests and this feature hasn't been requested yet
  • This is a single feature request (not multiple features)

Problem Statement

📌 Context and Pain Points

Currently, subagents in Claude Code lack robust configuration mechanisms for prompt reuse and scope isolation. This violates the software engineering DRY (Don't Repeat Yourself) principle and causes severe context pollution.

I am raising this issue to propose two core architectural upgrades for subagents. (Note: A similar request for @import was previously raised in #6899 but was closed by the stale bot. I am reopening the discussion with a more comprehensive architectural design).

The Current Developer Dilemmas:

  1. No Clean Way to Reuse System Prompts: If multiple subagents need to share the same set of rules, developers must either copy-paste them into every .md file, or instruct the subagent to use the Read tool upon initialization. The latter is slow, wastes tokens, and completely bypasses Prompt Caching benefits. The current community workaround—forcing the Main Agent to load the rules and pass them to the subagent as a User Prompt—is a very dirty hack. It severely pollutes the Main Agent's context window. Furthermore, because the rules are downgraded to a standard User Prompt, the LLM's adherence and stability drop significantly compared to a native System Prompt.
  2. Forced Inheritance of Global Scope (Scope Pollution): Currently, subagents are forced to inherit all project-level rules and skills. This explicitly violates the Principle of Least Privilege. A subagent dedicated strictly to writing unit tests has no business seeing global UI design guidelines in its context window, nor should it possess the permissions or tools to mutate the database.

Proposed Solution

🚀 Proposed Architecture and Design

Part 1: Native @import Support in Subagent Profiles

Allow the use of the @import syntax directly within subagent configuration files (e.g., agents/{agent}.md), similar to how memory currently works in CLAUDE.md.

Mechanism: When Claude Code instantiates a subagent, the underlying system should statically resolve all @import paths and compile their contents directly into the subagent's System Prompt before executing the API request.

Configuration Example (.claude/agents/security-reviewer.md):

name: security-reviewer
description: Performs code security audits.
tools: Read, Grep
---
You are a security audit expert.
@./.claude/rules/common-security-guidelines.md
@./.claude/rules/js-specific-rules.md

Part 2: Subagent-Specific Directories and Scope Isolation

This is an advanced architectural design. Allow subagents to exist as "directories" rather than just single files, granting them completely independent configurations, rules, and skills to completely eliminate global pollution.

Proposed Directory Structure:

.claude/
  agents/
    security-reviewer/
      AGENT.md          # Main config for this subagent
      rules/            # Local rules exclusively for security-reviewer
      skills/           # Local tools exclusively for security-reviewer

Proposed Isolation Flags in AGENT.md:

name: security-reviewer
inherit_global_rules: false   # Disables global inheritance: ignores project-level .claude/rules/
inherit_global_skills: false  # Disables global inheritance: strictly uses only its own skills directory or explicitly defined tools
---
[System Prompt block here]

💡 Why "Independent Rules & Skills" is Crucial:

  1. Laser-Focused Context (Attention Mechanism): Let the subagent focus only on the rules it needs to see. Stripping away irrelevant global rules not only saves tokens but drastically improves the LLM's instruction adherence.
  2. Converged Tool Selection (Reduced Hallucinations): When a subagent inherits dozens of global tools, its search space for "which tool to use" becomes unnecessarily large, leading to hallucinations or incorrect tool calls. Restricting it to dedicated, domain-specific skills makes its behavior much safer and more predictable (e.g., ensuring a testing agent cannot accidentally trigger deployment tools).
  3. True "Plug-and-Play" Modularity: Developers could simply copy a configured subagent folder (containing its perfectly scoped prompts and tools) and paste it into another project, achieving true, portable agent modularity.

Thank you to the team for considering this architectural upgrade! I strongly believe that combining native @import with Scope Isolation will truly unlock the powerful potential of multi-agent collaboration in Claude Code.

Alternative Solutions

No response

Priority

High - Significant impact on productivity

Feature Category

Configuration and settings

Use Case Example

No response

Additional Context

No response

extent analysis

TL;DR

Implement native @import support in subagent profiles and introduce subagent-specific directories for scope isolation to improve prompt reuse and reduce context pollution.

Guidance

  • Introduce the @import syntax in subagent configuration files to statically resolve and compile imported contents into the subagent's System Prompt.
  • Create subagent-specific directories with independent configurations, rules, and skills to eliminate global pollution.
  • Use isolation flags in AGENT.md to control inheritance of global rules and skills.
  • Test the new architecture with a sample subagent to verify improved context focus and reduced hallucinations.

Example

# .claude/agents/security-reviewer/AGENT.md
name: security-reviewer
inherit_global_rules: false
inherit_global_skills: false
---
You are a security audit expert.
@./rules/common-security-guidelines.md
@./rules/js-specific-rules.md

Notes

The proposed solution requires changes to the Claude Code architecture and may involve updates to the underlying system. It is essential to thoroughly test the new features to ensure they work as expected and do not introduce new issues.

Recommendation

Apply the proposed workaround by implementing native @import support and subagent-specific directories to improve prompt reuse and scope isolation, as this addresses the current limitations and aligns with the Principle of Least Privilege.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING