Merge all AGENTS.md files into CLAUDE.md for unified agent context
Merges all AGENTS.md files into CLAUDE.md for unified agent context.
/plugin marketplace add jeremylongshore/claude-code-plugins-plus-skills/plugin install ai-commit-gen@claude-code-plugins-plusCommand: /sync-agent-context
Purpose: Permanently merge all AGENTS.md files in the project into CLAUDE.md under a dedicated section, ensuring agent-specific instructions are always loaded alongside project context.
Search the current project for all files named AGENTS.md:
find . -name "AGENTS.md" -type f
Expected output:
./AGENTS.md
./subproject/AGENTS.md
For each found file, read its full content using the Read tool:
File: ./AGENTS.md
Content: [full content of AGENTS.md]
File: ./subproject/AGENTS.md
Content: [full content of subproject AGENTS.md]
if [ -f "./CLAUDE.md" ]; then
echo "CLAUDE.md found - will update"
else
echo "CLAUDE.md not found - will create new file"
fi
cp CLAUDE.md CLAUDE.md.backup.$(date +%Y%m%d-%H%M%S)
Example: CLAUDE.md.backup.20251023-143022
Add or update the following section in CLAUDE.md:
---
## Agent-Specific Instructions
<!-- AUTO-SYNCED from AGENTS.md files - Last updated: 2025-10-23 14:30:22 -->
<!-- Source files: ./AGENTS.md, ./subproject/AGENTS.md -->
### Root Directory Agent Rules (./AGENTS.md)
[Content from ./AGENTS.md]
### Subproject Agent Rules (./subproject/AGENTS.md)
[Content from ./subproject/AGENTS.md]
---
ā
Agent Context Sync Complete!
š Summary:
- Found 2 AGENTS.md files
- Created backup: CLAUDE.md.backup.20251023-143022
- Updated CLAUDE.md with agent-specific instructions
š Synced files:
1. ./AGENTS.md ā CLAUDE.md (Section: Root Directory Agent Rules)
2. ./subproject/AGENTS.md ā CLAUDE.md (Section: Subproject Agent Rules)
ā ļø Note: Original AGENTS.md files remain unchanged (source of truth)
š” Next time you start Claude Code, both CLAUDE.md and AGENTS.md will be loaded automatically.
Use /sync-agent-context when:
Don't use this command if:
Replace the existing section with updated content from all AGENTS.md files.
## Agent-Specific Instructions
<!-- OLD CONTENT - WILL BE REPLACED -->
āāā BECOMES āāā
## Agent-Specific Instructions
<!-- NEW CONTENT FROM AGENTS.MD FILES -->
Append new section to the end of CLAUDE.md.
[Existing CLAUDE.md content]
---
## Agent-Specific Instructions
<!-- NEW SECTION ADDED -->
[Content from AGENTS.md files]
If both CLAUDE.md and AGENTS.md have conflicting rules:
The sync command will:
Example merged output:
# CLAUDE.md
## General Project Instructions
- Use TypeScript for all code (from original CLAUDE.md)
---
## Agent-Specific Instructions
<!-- In case of conflicts, these rules take precedence for agent workflows -->
- Use JavaScript for agent-generated code (from AGENTS.md)
Result: Agent workflows use JavaScript; manual work uses TypeScript
Not currently implemented, but could be added:
// plugin.json future enhancement
{
"hooks": {
"onFileChange": {
"pattern": "**/AGENTS.md",
"action": "run /sync-agent-context automatically"
}
}
}
This would auto-sync whenever AGENTS.md is modified.
Before:
project/
āāā CLAUDE.md (200 lines)
āāā AGENTS.md (50 lines)
Run: /sync-agent-context
After:
project/
āāā CLAUDE.md (250 lines - merged)
āāā CLAUDE.md.backup.20251023-143022 (original)
āāā AGENTS.md (50 lines - unchanged)
Before:
project/
āāā CLAUDE.md
āāā AGENTS.md
āāā packages/
āāā plugin-a/
āāā AGENTS.md
Run: /sync-agent-context
After:
CLAUDE.md now contains:
## Agent-Specific Instructions
### Root Directory Agent Rules
[Content from ./AGENTS.md]
### Package Plugin-A Agent Rules
[Content from ./packages/plugin-a/AGENTS.md]
CLAUDE.md.backup.* files if neededProblem: Sync command not found
Solution: Ensure plugin is installed:
/plugin install agent-context-manager@claude-code-plugins-plus
Problem: CLAUDE.md section duplicated
Solution: Sync command should replace, not duplicate. Check for:
Problem: Backup files accumulating
Solution: Clean old backups periodically:
find . -name "CLAUDE.md.backup.*" -mtime +30 -delete
agent-context-loader - Automatically loads AGENTS.mdcheck-agents-md.sh - Detects AGENTS.md on directory changeStatus: Manual Command
Requires User Action: Yes (type /sync-agent-context)
Permanent: Yes (persists in CLAUDE.md)