Skip to content

[FEATURE] User-Level Agent Rules and Rule Propagation #8395

@baslogic

Description

@baslogic

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

The Problem

As a Claude Code user working with multiple subagents, I need a way to define user-level rules and preferences that can be consistently applied across my primary agent and optionally propagated to subagents. Currently, there is no documented mechanism to:

  1. Define user-level rules that apply specifically to the primary Claude Code agent
  2. Propagate user-level rules or instructions down to subagents
  3. Control which rules should apply to which agents in the hierarchy

Why This Is Needed

Workflow Context:

I'm building a "subagent army" - multiple specialized subagents for different tasks (documentation, testing, code review, etc.). I need certain rules to apply consistently across all agents, while other rules should only apply to the primary agent.

Current Pain Points:

  1. No centralized rule management: I must manually copy rules into every subagent's configuration file
  2. Inconsistent behavior: Each subagent operates in isolation without awareness of my preferences
  3. Maintenance nightmare: When I want to change a rule, I need to update 10+ subagent files
  4. No separation of concerns: Can't differentiate between UI-specific rules (primary only) and behavioral rules (all agents)

Real-World Impact:

When the primary agent delegates to a subagent, the subagent doesn't follow my coding style preferences, response format rules, or proactive behavior guidelines. This breaks my workflow and requires constant manual intervention to maintain consistency.

Discovery of the Gap

I attempted to create ~/.claude/primary-agent-rules.md expecting it to work like CLAUDE.md but at the user level. The file was never loaded. Investigation of the official documentation revealed:

  • No mechanism exists for user-level agent instruction files
  • Subagents operate in isolated contexts with their own system prompts
  • No documented way to inherit or propagate rules from primary to subagents
  • Official configuration is limited to project-level (CLAUDE.md) or settings (settings.json)

This isn't just a documentation gap - the feature doesn't exist.

Proposed Solution

2. Proposed Solution

Ideal User Experience

Step 1: Create User-Level Rules File

I create ~/.claude/primary-agent-rules.md in my home directory:

# Primary Agent Rules

**SCOPE: These rules apply to the primary Claude Code agent.**

## Response Format Rules
- Append 🔵 at end of every response (for UI tracking)
- Always use Oxford commas in lists

## Proactive Behavior Rules
- Use hello-world-agent when user says "hi cc"
- Use documentation-specialist for any .md file creation

What happens: Claude Code automatically loads this file when the primary agent starts.

Step 2: Define Shared Rules for All Agents

I create ~/.claude/agent-rules.md for rules that should propagate:

# Shared Agent Rules

**SCOPE: These rules apply to ALL agents (primary and subagents).**

## Code Style
- Use single quotes for strings in JavaScript
- Maximum line length: 100 characters
- Always include JSDoc comments for functions

## Git Commit Style
- Use conventional commits format
- First line max 50 characters
- Include ticket number in commit message

What happens: All subagents automatically receive these rules when invoked.

Step 3: Configure Rule Propagation (Optional)

If I need fine-grained control, I can configure in ~/.claude/settings.json:

{
  "agentRules": {
    "primaryRulesFile": "~/.claude/primary-agent-rules.md",
    "sharedRulesFile": "~/.claude/agent-rules.md",
    "propagateToSubagents": true,
    "allowSubagentOverride": false
  }
}

Step 4: Subagent-Specific Overrides (Optional)

For specific subagents that need different rules, I can configure in the subagent's YAML frontmatter:

---
name: code-reviewer
description: Reviews code for quality
inherit_rules: true              # Inherit from agent-rules.md
custom_rules: ~/.claude/reviewer-specific-rules.md  # Additional rules
---

You are a code reviewer specializing in security vulnerabilities.

How I'd Interact With This Feature

Daily workflow:

  1. Start working on a project
  2. Primary agent loads my primary-agent-rules.md automatically - I see the 🔵 marker at the end of responses
  3. I ask primary agent to create documentation - it automatically uses documentation-specialist subagent
  4. The subagent follows my code style rules from agent-rules.md without me specifying them
  5. When subagent reports back, it doesn't include the 🔵 marker (primary-only rule)

When I need to change a rule:

  1. Edit ~/.claude/agent-rules.md once
  2. All future subagents automatically use the new rule
  3. No need to update 10+ individual subagent configurations

Alternative Solutions

3. Alternative Solutions

Workarounds Tried

Workaround 1: Manual System Prompt Instructions

Approach: Add instruction to each subagent's system prompt to read the rules file:

---
name: my-subagent
description: Does something
---

IMPORTANT: Before responding, read and follow rules in ~/.claude/primary-agent-rules.md

[Rest of system prompt...]

Limitations:

  • ❌ Must manually add to every subagent (currently 12 subagents, growing)
  • ❌ No guarantee subagents actually read the file
  • ❌ Requires File Read tool access for every subagent
  • ❌ If I forget to add this instruction, rules aren't followed
  • ❌ Can't differentiate primary-only vs shared rules

Why this doesn't work: Not scalable, error-prone, and relies on subagent cooperation rather than system enforcement.

Workaround 2: Project-Level CLAUDE.md

Approach: Add conditional instructions in CLAUDE.md:

# Agent Rules

If you are a subagent, follow these rules:
- Rule 1
- Rule 2

Limitations:

  • ❌ CLAUDE.md is project-level, not user-level (doesn't work across all my projects)
  • ❌ Unknown if CLAUDE.md content is even available to subagents (undocumented)
  • ❌ Mixes project-specific instructions with user-level preferences
  • ❌ Each project needs its own copy of my user preferences

Why this doesn't work: I need user-level rules that apply across all projects I work on, not per-project configuration.

Workaround 3: Settings.json with JSON-Encoded Rules

Approach: Store rules as strings in settings.json:

{
  "customInstructions": {
    "primary": "Append 🔵 at end of responses",
    "shared": "Use single quotes for JavaScript strings"
  }
}

Limitations:

  • ❌ Not documented as a supported feature (doesn't actually work)
  • ❌ JSON is terrible for long-form instructions
  • ❌ No Markdown formatting support
  • ❌ Harder to read and maintain than dedicated .md files

Why this doesn't work: JSON isn't designed for long-form instructions, and this isn't a documented feature anyway.

Current Working Solution (Painful)

I maintain a template file and manually copy-paste rules into each subagent configuration when I create it. When rules change, I use find/replace across all files. This is error-prone and doesn't scale.

Priority

Critical - Blocking my work

Feature Category

CLI commands and flags

Use Case Example

4. Use Case Example

Scenario: Managing Code Style Consistency Across Multiple Agents

Context: I'm working on a large TypeScript project with strict coding standards. I use multiple specialized subagents:

  • code-reviewer: Reviews PRs for quality issues
  • test-writer: Writes unit tests
  • documentation-specialist: Creates/updates documentation
  • refactoring-agent: Refactors code for better architecture
  • bug-fixer: Fixes reported bugs

The Problem: Each subagent generates code in slightly different styles because they don't share my coding preferences.

Step-by-Step Walkthrough

Step 1: Initial State (Current Behavior)

I ask primary agent: "Review this PR, add tests, and update docs"

Primary agent delegates to 3 subagents:

  1. code-reviewer reviews code (✅ works fine, just analysis)
  2. test-writer creates tests with double quotes: expect("result").toBe("expected")
  3. documentation-specialist creates docs with different code style

Problem: Test code and docs don't match my style guide (single quotes, specific comment format).

Step 2: With Proposed Feature

I create ~/.claude/agent-rules.md:

# Shared Agent Rules

## TypeScript Code Style
- Use single quotes for strings
- Use 2-space indentation
- Always include JSDoc comments with @param and @returns
- Prefer const over let
- Use arrow functions for callbacks

## Git Commits
- Use conventional commits: feat:, fix:, docs:, refactor:
- Include JIRA ticket number: [PROJ-123]
- First line max 50 chars, body max 72 chars per line

## Documentation Style
- Use TypeScript code examples, not JavaScript
- Include "Example" and "Returns" sections
- Cross-reference related functions with links

I configure ~/.claude/settings.json:

{
  "agentRules": {
    "sharedRulesFile": "~/.claude/agent-rules.md",
    "propagateToSubagents": true
  }
}

Step 3: New Behavior

I ask primary agent: "Review this PR, add tests, and update docs"

Primary agent delegates to 3 subagents, ALL of which automatically receive my agent-rules.md:

  1. code-reviewer analyzes code (no code generation, rules not needed but harmless)
  2. test-writer creates tests with single quotes: expect('result').toBe('expected')
  3. documentation-specialist creates docs with TypeScript examples and proper formatting

Result: All generated code follows my style guide automatically. No manual intervention needed.

Step 4: Making Changes

Two weeks later, team decides to switch to Prettier with 4-space indentation.

Old way (current): Edit 5 subagent config files manually, risk missing one, inconsistent behavior until all updated.

New way (with feature): Edit ~/.claude/agent-rules.md once, change "2-space" to "4-space". All future subagent invocations use new rule immediately.

Scenario Impact

Time saved:

  • Setup: 5 minutes once vs. 5 minutes × 5 agents = 25 minutes
  • Updates: 1 minute once vs. 5 minutes × 5 agents = 25 minutes per update

Error reduction:

  • No risk of forgetting to update a subagent
  • No inconsistencies between subagents
  • No manual review needed to check style compliance

Cognitive load:

  • One source of truth for rules
  • Don't need to remember which agents have which rules
  • Can focus on work instead of configuration management

Additional Context

Similar Features in Other Tools

Cursor IDE:

  • Has .cursorrules file that applies AI coding rules globally
  • All AI-generated code follows these rules automatically
  • Located in project root or user home directory

GitHub Copilot:

  • Can configure style preferences in IDE settings
  • Suggestions follow configured style guides
  • Applies consistently across all code generation

Claude Code Missing Equivalent:

  • Has CLAUDE.md but it's project-level only
  • No user-level equivalent for cross-project rules
  • No propagation mechanism for subagents

Technical Considerations

File Loading:

  • Files should be loaded at startup (similar to CLAUDE.md)
  • Should support hot-reload on file changes (like IDE settings)
  • Precedence should follow existing hierarchy (enterprise > local > user)

Security:

  • Respect existing file permission checks
  • Validate file paths to prevent directory traversal attacks
  • Document that rules in these files have full agent permissions

Performance:

  • Parse and cache rules at startup
  • Don't re-read on every subagent invocation
  • Use file watchers for change detection
  • Minimal overhead (one-time parsing per session)

Backward Compatibility:

  • Feature is opt-in (files don't exist by default)
  • No changes to existing behavior if files not present
  • Existing subagent configurations continue working unchanged

Configuration File Structure Proposal

Minimal viable implementation:

~/.claude/
  ├── settings.json              # Existing: general settings
  ├── primary-agent-rules.md     # NEW: Primary agent only rules
  ├── agent-rules.md             # NEW: All agents (shared rules)
  └── agents/                    # Existing: subagent definitions
      ├── code-reviewer.md
      └── test-writer.md

Optional enhanced implementation:

~/.claude/
  ├── settings.json
  ├── rules/                     # NEW: Rules directory
  │   ├── primary.md            # Primary agent only
  │   ├── shared.md             # All agents
  │   └── templates/            # Reusable rule templates
  │       ├── typescript.md
  │       └── python.md
  └── agents/
      └── code-reviewer.md

Settings.json Configuration Schema

{
  "$schema": "https://claude.ai/schemas/settings.json",
  "agentRules": {
    "primaryRulesFile": "~/.claude/primary-agent-rules.md",
    "sharedRulesFile": "~/.claude/agent-rules.md",
    "propagateToSubagents": true,
    "allowSubagentOverride": true,
    "loadOnStartup": true,
    "watchForChanges": true
  }
}

Documentation Gaps Discovered

During investigation, we found these related documentation gaps:

  1. No documentation on whether CLAUDE.md content is available to subagents
  2. No documentation on subagent context isolation details
  3. No documentation on instruction inheritance patterns (because feature doesn't exist)
  4. No best practices guide for managing multiple subagents
  5. No examples of user-level vs project-level configuration trade-offs

These gaps made it harder to understand current behavior and discover that the feature is missing entirely.

Visual Example: Rule Propagation Flow

User creates: ~/.claude/agent-rules.md
                     ↓
          Claude Code loads at startup
                     ↓
         ┌───────────┴───────────┐
         ↓                       ↓
   Primary Agent          Subagent (code-reviewer)
   (gets shared rules)    (gets shared rules automatically)
         ↓                       ↓
   Responds to user       Generates code following rules
   with 🔵 marker         (no 🔵 marker - primary-only rule)

Related GitHub Issues / Discussions

  • Unknown - unable to find existing issues about this feature
  • May relate to general subagent configuration discussions
  • Possibly ties into "context management" feature discussions

Implementation Priority Suggestion

Phase 1 (MVP):

  • Support ~/.claude/primary-agent-rules.md (primary agent only)
  • Support ~/.claude/agent-rules.md (all agents)
  • Simple propagation: all subagents get shared rules automatically
  • Basic settings.json configuration

Phase 2 (Enhanced):

  • Per-rule scoping (primary-only, all-agents, subagents-only)
  • Subagent override capabilities in frontmatter
  • Rule templates and includes
  • Hot-reload support

Phase 3 (Advanced):

  • Rule validation and linting
  • Rule conflict detection and resolution
  • Enterprise policy enforcement
  • Cloud-synced rules for teams

Meta Information:

  • Discovered through user experimentation: September 29, 2025
  • Affects: Users with multiple subagents (growing use case)
  • Current workaround: Manual copy-paste (not scalable)
  • Urgency: High for users building "subagent armies"

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreautocloseIssue will be closed automaticallyenhancementNew feature or requesthas reproHas detailed reproduction steps

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions