Recursively initialize AGENTS.md in all important subdirectories with smart detection
Recursively initializes AGENTS.md files across subdirectories with smart detection and hierarchy linking.
/plugin marketplace add v1truv1us/ai-eng-system/plugin install ai-eng-system@ai-eng-marketplaceRecursively initialize AGENTS.md in all important subdirectories with smart detection. Each AGENTS.md file guides AI agents for months across thousands of interactions. Execute this multi-phase operation systematically.
Take a deep breath and approach this initialization systematically. Scan directory structure, identify important subdirectories, and create AGENTS.md files with proper hierarchy linking.
AGENTS.md files guide AI agents across months and thousands of interactions. Poor initialization leads to agent confusion, wasted tokens, and inconsistent behavior. Missing hierarchy links break context flow between directories. This initialization task is critical for building maintainable, efficient agent context system.
I bet you can't create comprehensive yet concise AGENTS.md files for all subdirectories efficiently. The challenge is identifying the most important directories, extracting relevant context, and creating files that provide clear guidance without overwhelming token budgets. Success means every important directory has useful AGENTS.md with proper hierarchy linking.
/recursive-init [path] [options]
First, gather intelligence before any analysis:
# Detect project types and score directories
find . -maxdepth 3 -name "package.json" -o -name "go.mod" -o -name "Cargo.toml" -o -name "pyproject.toml" -o -name "pom.xml" 2>/dev/null | grep -v node_modules | head -30
# Identify monorepo patterns
ls -d */packages 2>/dev/null || ls -d */apps 2>/dev/null || ls -d */services 2>/dev/null || echo "No standard monorepo structure detected"
| Indicator | Score |
|---|---|
| package.json, go.mod, Cargo.toml, pyproject.toml, pom.xml | +10 |
| src/, lib/, components/ directory | +5 |
| .cursorrules, .github/copilot-instructions.md | +3 |
| >10 source files (.ts, .js, .py, .go, .rs) | +3 |
| README.md or docs/ present | +2 |
Only analyze directories scoring > 5 (configurable via --min-score).
Run standard init at project root. Create comprehensive overview AGENTS.md.
Scan and score all subdirectories. Report findings before proceeding.
Process directories in groups of 3. For EACH directory:
**Hierarchy Level:** — Role in system (e.g., "Frontend components", "API services", "Build utilities")**Parent:** — Link to parent AGENTS.md with path (e.g., [../AGENTS.md](../AGENTS.md))**Philosophy:** — Link to CLAUDE.md (e.g., [CLAUDE.md](../../CLAUDE.md))Update root AGENTS.md with:
Example section:
## Directory Context Index
| Directory | Hierarchy Level | Purpose | Key Files |
|-----------|-----------------|---------|-----------|
| `packages/api` | API Services | REST API backend | `src/routes/`, `src/models/` |
| `packages/web` | Frontend Components | React UI | `src/components/`, `src/pages/` |
Each subdirectory's AGENTS.md includes hierarchy metadata linking to:
- **Parent:** This AGENTS.md for agent coordination
- **Philosophy:** CLAUDE.md for project guiding principles
Ensure root CLAUDE.md is properly linked to AGENTS.md structure:
Example CLAUDE.md structure:
# Project Philosophy
[Project mission and guiding principles...]
## Agent Coordination
See **[AGENTS.md](./AGENTS.md)** for:
- Available agents and their modes
- Specialized subagents and capabilities
- Commands and skills available
This CLAUDE.md defines the **philosophy**. AGENTS.md documents the **agents and tools**.
## Agent Contexts
Specialized agent contexts are defined in subdirectories:
| Directory | AGENTS.md | Purpose |
|-----------|-----------|---------|
| `.claude/` | [.claude/AGENTS.md](./.claude/AGENTS.md) | Command implementation details |
| `skills/` | [skills/AGENTS.md](./skills/AGENTS.md) | Reusable skill definitions |
| `packages/api` | [packages/api/AGENTS.md](./packages/api/AGENTS.md) | API services context |
| `packages/web` | [packages/web/AGENTS.md](./packages/web/AGENTS.md) | Frontend context |
Each subdirectory maintains its own AGENTS.md with hierarchy metadata linking back to this CLAUDE.md philosophy.
| Flag | Description | Default |
|---|---|---|
--depth N | Maximum recursion depth | 2 |
--dry-run | Preview without changes | false |
--preserve | Keep existing AGENTS.md | false |
--batch-size N | Directories per batch | 3 |
--min-score N | Minimum importance score | 5 |
--include <pattern> | Additional patterns to include | - |
--exclude <pattern> | Patterns to skip | node_modules,.git,dist |
--estimate-cost | Show cost estimate first | false |
node_modules, .git, dist, build, pycache, .venv, target, coverage, .next, .nuxt
🔍 Scanning directory structure...
📊 Found X directories above threshold (score > 5)
📁 Root (/)
✓ AGENTS.md created (monorepo overview, 8 packages detected)
📦 Batch 1/N: [packages/api, packages/web, packages/shared]
✓ packages/api: AGENTS.md (Express REST API, TypeScript, Prisma)
✓ packages/web: AGENTS.md (Next.js 14, App Router, Tailwind)
✓ packages/shared: AGENTS.md (TypeScript utilities, Zod schemas)
📋 Root AGENTS.md updated with directory index
✅ Summary: 1 root + X directories initialized
💰 Estimated cost: ~$X.XX
🕐 Time saved: ~X minutes vs manual setup
Before completing, verify:
For each created AGENTS.md file:
@ import syntax if in .claude/)For Root AGENTS.md:
For Root CLAUDE.md (Bidirectional Linking):
Rate your confidence in the completeness of this initialization (0-1) and note any directories that may need manual review.
| Scenario | Directories | Estimated Cost | Time Saved |
|---|---|---|---|
| Standard /init | 1 | $0.01-0.02 | 2-3 min |
| Small monorepo | 3-5 | $0.06-0.15 | 10-15 min |
| Medium monorepo | 5-10 | $0.10-0.40 | 20-30 min |
| Large monorepo | 10-20 | $0.20-0.80 | 45-60 min |
This command uses incentive-based prompting techniques: