.agents/skills/agent-md-refactor/README.md
A Claude Code skill that transforms bloated agent instruction files into clean, organized documentation using progressive disclosure principles.
Based on https://x.com/mattpocockuk/status/2012906065856270504 (Matt Pocock's Prompt Idea)
Over time, agent instruction files like CLAUDE.md, AGENTS.md, or COPILOT.md tend to grow into unwieldy documents containing hundreds of lines of mixed instructions. This creates several problems:
This skill solves these problems by applying progressive disclosure - keeping only essential, universal instructions in the root file while organizing everything else into focused, linked documentation files.
Use this skill when you need to clean up agent instruction files. Common trigger phrases include:
Good candidates for refactoring:
The skill follows a systematic 5-phase process:
Before restructuring, the skill identifies conflicting instructions that need resolution. Examples include contradictory style guidelines ("use semicolons" vs "no semicolons") or incompatible workflow instructions. Each contradiction is surfaced with a question for the user to resolve.
Extracts only what truly belongs in the root file - information that applies to every single task:
| Keep in Root | Move Out |
|---|---|
| One-sentence project description | Language-specific conventions |
| Non-standard package manager | Testing guidelines |
| Custom build/test commands | Code style details |
| Critical overrides | Framework patterns |
| Universal rules (100% of tasks) | Documentation standards |
Organizes remaining instructions into logical categories like:
typescript.md - Type patterns, strict mode rulestesting.md - Test frameworks, coverage, mockingcode-style.md - Formatting, naming, structuregit-workflow.md - Commits, branches, PRsarchitecture.md - Patterns, folder structureGenerates the new file hierarchy with properly linked documentation:
project-root/
├── CLAUDE.md # Minimal root with links
└── .claude/ # Categorized instructions
├── typescript.md
├── testing.md
├── code-style.md
└── architecture.md
Identifies instructions that should be removed entirely:
User: refactor my CLAUDE.md
Claude: I'll analyze your CLAUDE.md file and refactor it using progressive
disclosure principles...
User: my AGENTS.md is too long, can you split it up?
Claude: I'll review your AGENTS.md and organize it into focused, linked files...
User: organize my agent config - it's gotten out of control
Claude: I'll apply the 5-phase refactoring process to clean up your
agent instructions...
After running the skill, you get:
Minimal root file (~50 lines or less):
# Project Name
One-sentence description of the project.
## Quick Reference
- **Package Manager:** pnpm
- **Build:** `pnpm build`
- **Test:** `pnpm test`
## Detailed Instructions
- [TypeScript Conventions](.claude/typescript.md)
- [Testing Guidelines](.claude/testing.md)
- [Code Style](.claude/code-style.md)
Organized linked files with consistent structure:
# Testing Guidelines
## Overview
Brief context for when these guidelines apply.
## Rules
### Unit Tests
- Specific, actionable instruction
- Another specific instruction
## Examples
### Good
[code example]
### Avoid
[code example]
Deletion report:
## Flagged for Deletion
| Instruction | Reason |
|-------------|--------|
| "Write clean, maintainable code" | Too vague to be actionable |
| "Use TypeScript" | Redundant - project is already TS |
| Avoid | Why | Instead |
|---|---|---|
| Keeping everything in root | Bloated, hard to maintain | Split into linked files |
| Too many categories | Fragmentation, navigation overhead | Consolidate related topics |
| Vague instructions | Wastes tokens, no value | Be specific or delete |
| Duplicating defaults | Agent already knows | Only override when needed |
| Deep nesting | Hard to navigate | Flat structure with links |
After refactoring, verify:
MIT