Refactor and optimize CLAUDE.md files in a repository. Analyzes the existing CLAUDE.md setup, explores the repo structure, and proposes splitting or reorganizing CLAUDE.md into a hierarchical directory-scoped structure. Use when: (1) User wants to optimize their CLAUDE.md, (2) Root CLAUDE.md is too large, (3) User wants to split CLAUDE.md into directory-scoped files, (4) User mentions 'refactor CLAUDE.md', 'split CLAUDE.md', or 'organize CLAUDE.md'. Keywords: CLAUDE.md, refactor, split, organize, directory-scoped.
Resources
1Install
npx skillscat add takazudo/claude-resources/claudemd-refactor Install via the SkillsCat registry.
Refactor CLAUDE.md
Analyze and refactor CLAUDE.md files in the current repository to optimize how context is delivered to Claude Code.
Context Loading Reliability Hierarchy
When deciding where to place information, follow this hierarchy (most to least reliable):
| Approach | Reliability | Tradeoff |
|---|---|---|
| Inline in CLAUDE.md | Highest | Larger CLAUDE.md |
| Directory-scoped CLAUDE.md | High | Content must be relevant to that directory |
| Explicit "read before doing X" | Medium | Depends on Claude following the instruction |
| Passive "refer to file" | Low | Claude may or may not read it |
Key principle: Claude Code automatically loads CLAUDE.md files based on the working directory. Root CLAUDE.md is always loaded. Subdirectory CLAUDE.md files are loaded when working on files in that directory. Content in CLAUDE.md is always in context — no tool call needed.
Workflow
Phase 1: Explore and Analyze
Find all existing CLAUDE.md files in the repo
Glob: **/CLAUDE.mdRead the root CLAUDE.md — understand what's currently there, measure its size
Explore the repo structure — understand the directory layout, identify logical boundaries
- What are the major directories? (src/, docs/, scripts/, tests/, etc.)
- What languages/frameworks are used?
- Are there distinct subsystems with their own conventions?
- Categorize the content in the existing root CLAUDE.md into buckets:
- Global: Project-wide info that applies everywhere (project name, tech stack, overall architecture, global conventions)
- Directory-specific: Rules that only apply to certain directories (e.g., "use camelCase in src/", "frontmatter required in docs/")
- Task-specific: Instructions tied to specific operations (e.g., "before modifying API routes, read api-design.md")
- Redundant/outdated: Content that can be removed
Phase 2: Propose a Plan
Present the user with a concrete proposal. Include:
- Current state summary
- Number of CLAUDE.md files found
- Root CLAUDE.md size (lines/sections)
- Content categories identified
Proposed CLAUDE.md structure — show a tree like:
repo/ ├── CLAUDE.md # Global: project overview, tech stack, universal conventions ├── src/ │ └── CLAUDE.md # Code: naming conventions, import rules, architecture patterns ├── docs/ │ └── CLAUDE.md # Docs: writing style, frontmatter, formatting rules └── tests/ └── CLAUDE.md # Tests: testing conventions, fixture locations, coverage rulesFor each proposed CLAUDE.md, list:
- What content moves there (with specific sections/lines from original)
- What stays in root
- Any new content needed (e.g., cross-references)
- Migration of "refer to" patterns — identify any passive references and propose upgrades:
- Passive → Inline (if content is small and critical)
- Passive → Explicit trigger ("Before modifying X, read Y")
- Keep as passive (only if truly optional background info)
Phase 3: Ask for User Approval
IMPORTANT: Do NOT proceed without explicit user approval. Present the plan and ask:
- Does the proposed structure make sense for this repo?
- Should any content stay in root instead of being split?
- Are there directories that should have their own CLAUDE.md that weren't identified?
- Any content that should be removed entirely?
Phase 4: Execute the Refactoring
After approval:
- Create directory-scoped CLAUDE.md files with the approved content
- Trim the root CLAUDE.md — remove content that was moved to subdirectories
- Upgrade passive references — replace "refer to X" with inline content or explicit triggers
- Add cross-references where needed — if root CLAUDE.md needs to mention that subdirectory rules exist
Phase 5: Verify
- Read each created/modified CLAUDE.md to verify correctness
- Ensure no critical information was lost
- Check that the root CLAUDE.md is noticeably smaller but still contains all global info
- Present a summary of changes to the user
Content Placement Rules
Use these rules to decide where content belongs:
Root CLAUDE.md (always loaded)
- Project name and purpose
- Tech stack overview
- Universal coding conventions (applies to ALL code)
- Git/commit conventions
- CI/CD and deployment notes
- Links to key documentation
- Cross-references to subdirectory CLAUDE.md files
Directory-scoped CLAUDE.md (loaded when working in that directory)
- Language/framework-specific conventions for that directory
- File naming and organization rules specific to that area
- Import/export patterns
- Testing patterns specific to that area
- Build/compilation notes for that subsystem
What NOT to put in CLAUDE.md
- Content that changes frequently (use external docs with explicit read triggers)
- Very long reference material (keep in separate .md files, use explicit read triggers)
- Information that's obvious from the code itself
Anti-patterns to Fix
When analyzing existing CLAUDE.md, look for and fix these anti-patterns:
- "Refer to X for details" → Inline the content or use explicit trigger
- Duplicate information across multiple sections → Consolidate
- Outdated instructions referencing files/dirs that don't exist → Remove
- Overly verbose explanations → Condense to actionable rules
- Everything in root when clear directory boundaries exist → Split
- Directory-specific rules in root → Move to appropriate directory CLAUDE.md