agentleFS
jopre0502jopre0502/claude-persist/skills/claude-md-restructure/SKILL.md

claude-md-restructure

Skill1 starsChanged 9 months agoMITView on GitHub

Optimize CLAUDE.md files for size (<8KB target) while preserving workflow-block.txt injection and Session-Continuous patterns. Use when CLAUDE.md exceeds 8KB or when users mention "CLAUDE.md too large", "optimize CLAUDE.md", "reduce CLAUDE.md size". Applies Modular Disclosure (outsourcing to separate files) and maintains injection markers for project-init compatibility.

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 6 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Check Decision Log size

    line 200
  2. Distinctive:

    If Decision Log empty: No action needed

    line 201
  3. Distinctive:

    Check for injection markers in CLAUDE.md

    line 209
  4. Very specific:

    If missing: Re-run /project-init or manually inject

    line 210
  5. Distinctive:

    Consider running this skill when CLAUDE.md > 8KB

    line 253
  6. Distinctive:

    Not auto-triggered (manual decision)

    line 254
  7. Very specific:

    Fix: Ensure heading is ## Decision Log (exact)

    line 284
  8. Distinctive:

    Fix: Ensure this exact string exists in CLAUDE.md (in heading or content)

    line 292

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

CLAUDE.md Restructure

Optimize CLAUDE.md files for session-continuous projects. Target: <8KB while preserving workflow-block.txt injection.

Quick Start

Most common workflow:

  1. Analyze current state:
    python3 scripts/analyze_claude_md.py CLAUDE.md
  2. Externalize Workflow (biggest impact, ~8KB savings):
    python3 scripts/externalize_workflow.py CLAUDE.md --dry-run
    python3 scripts/externalize_workflow.py CLAUDE.md
  3. Migrate Decision Log (if >10 entries):
    python3 scripts/migrate_decision_log.py CLAUDE.md --dry-run
    python3 scripts/migrate_decision_log.py CLAUDE.md
  4. Apply Modular Disclosure (outsource resolved sections):
    python3 scripts/apply_progressive_disclosure.py CLAUDE.md
  5. Verify result:
    python3 scripts/analyze_claude_md.py CLAUDE.md
    # Expected: Exit code 0 (Healthy <8KB)

When to Use

TriggerAction
CLAUDE.md > 8KBRun full workflow
Decision Log > 10 entriesMigrate Decision Log
"CLAUDE.md too large"Analyze + recommend
Session-refresh token budget highConsider optimization
New project from project-initCheck injection markers

Core Principles

1. Workflow Reference (nicht Inline-Injection)

Best Practice (seit TASK-026): Workflow-Dokumentation wird referenziert, nicht inline eingebettet.

"❌ Don't: @-file docs (embeds entire file on every run)" "✅ Do: 'For complex usage, see path/to/docs.md'" — Claude Code Best Practices

Vorher (Inline, ~10KB):

## Session-Continuous Workflow
[246 Zeilen vollständige Dokumentation]

Nachher (Reference, ~1.5KB):

## Session-Continuous Workflow
**Detaillierte Workflow-Dokumentation:** `${CLAUDE_PLUGIN_ROOT}/skills/project-init/references/WORKFLOW.md`
[Quick-Reference Tabellen]

Migration bestehender Projekte:

python3 scripts/externalize_workflow.py CLAUDE.md --dry-run
python3 scripts/externalize_workflow.py CLAUDE.md

Why: Claude liest die externe Datei nur bei Bedarf (via Read-Tool), nicht bei jedem Session-Start.

2. No HTML <details> Blocks

Anti-Pattern: <details> tags hide content inline instead of migrating it to separate files. This keeps file size high while giving the illusion of "Progressive Disclosure". Use Modular Disclosure (file migration with links) instead.

3. Modular Disclosure

Outsource historical/resolved content to separate files:

  • Resolved Open Questions → eigene Datei oder entfernen
  • Solved Challenges → docs/ oder entfernen
  • Reference sections → separate Datei mit Link
  • Large tables (>8 rows) → auslagern oder kuerzen

Detailed Workflows

Analysis Workflow

python3 scripts/analyze_claude_md.py CLAUDE.md

Output includes:

  • Total size in bytes
  • Section breakdown with visual bars
  • Decision Log entry count
  • Workflow injection status
  • Specific recommendations

Exit codes:

  • 0: Healthy (<8KB)
  • 1: Needs optimization (8-15KB)
  • 2: Critical (>15KB)

Decision Log Migration

# Preview changes:
python3 scripts/migrate_decision_log.py CLAUDE.md --dry-run

# Execute migration:
python3 scripts/migrate_decision_log.py CLAUDE.md

Creates:

  • docs/DECISION-LOG.md with full history
  • Backup: CLAUDE.md.pre-decision-migration.backup

Updates CLAUDE.md:

  • Replaces inline table with link
  • Keeps last 3 decisions as summary

Modular Disclosure

# Preview:
python3 scripts/apply_progressive_disclosure.py CLAUDE.md --dry-run

# Apply:
python3 scripts/apply_progressive_disclosure.py CLAUDE.md

Outsources to separate files or removes:

  • Resolved Open Questions → entfernen oder auslagern
  • Solved Challenges → entfernen oder auslagern
  • Reference sections → separate Datei mit Link
  • Large tables (>8 rows) → kuerzen oder auslagern

Template Reference

See assets/claude-md-template.txt for the optimized CLAUDE.md structure with:

  • Size-targeted sections
  • Injection markers
  • Decision Log link pattern
  • Placeholder variables

Variables:

  • {{PROJECT_NAME}}, {{PROJECT_PURPOSE}}
  • {{TECH_STACK}}, {{ARCHITECTURE_OVERVIEW}}
  • {{WORKFLOW_BLOCK}} - workflow-block.txt content
  • {{RECENT_DECISIONS}} - last 3 decisions
  • {{DATE}}

Common Scenarios

Scenario 1: CLAUDE.md Over 15KB

User says: "My CLAUDE.md is 18KB, Claude loses focus"

Workflow:

  1. Analyze: python3 scripts/analyze_claude_md.py CLAUDE.md
  2. Migrate Decision Log (saves ~3-5KB)
  3. Apply Modular Disclosure (outsource sections)
  4. Verify: Exit code 0

Scenario 2: Many Decision Log Entries

User says: "Decision Log has 25 entries"

Workflow:

  1. Migrate: python3 scripts/migrate_decision_log.py CLAUDE.md
  2. Result: docs/DECISION-LOG.md created, CLAUDE.md reduced

Scenario 3: After project-init

User says: "Just ran /project-init, CLAUDE.md already 10KB"

Workflow:

  1. This is expected (workflow-block.txt is ~8KB)
  2. Check Decision Log size
  3. If Decision Log empty: No action needed
  4. Monitor as project grows

Scenario 4: Workflow Injection Missing

User says: "Session-Continuous Workflow section missing"

Workflow:

  1. Check for injection markers in CLAUDE.md
  2. If missing: Re-run /project-init or manually inject
  3. Source: ${CLAUDE_PLUGIN_ROOT}/skills/project-init/assets/workflow-block.txt

Scenario 5: Old Workflow Block → Vault-First Compact Block

User says: "Migrate my project to Vault-First" or detected automatically

Detects three patterns:

  1. Full Inline Injection (~10KB, <!-- BEGIN:WORKFLOW-INJECTION --> markers)
  2. Old Reference-Only Block (~1.5KB, references WORKFLOW.md but no Vault-First)
  3. Old Reference Block without Feature Detection (no obsidian.com version)

Workflow:

python3 scripts/externalize_workflow.py CLAUDE.md --dry-run
python3 scripts/externalize_workflow.py CLAUDE.md

Result: Replaces any old pattern with Vault-First Compact Block (~4KB) that includes:

  • Feature Detection (obsidian.com version)
  • Dual-path: Vault-First + Local Fallback
  • session-workflow skill reference for details
  • Compact enough to stay inline in CLAUDE.md

Guardrails

RuleReason
Keep "Session-Continuous Workflow" headingMarker for project-init detection
Keep obsidian.com version Feature DetectionVault-First requires runtime detection
Backup before modificationsRecovery option
Test /run-next-tasks after changesVerify task-scheduler compatibility
Old injection markers can be removedReplaced by Vault-First Compact Block

Integration

With project-init

  • project-init injects workflow-block.txt
  • This skill preserves injection markers
  • Re-injection safe after optimization

With session-refresh

  • session-refresh triggers context optimization
  • Consider running this skill when CLAUDE.md > 8KB
  • Not auto-triggered (manual decision)

With project-doc-restructure

  • project-doc-restructure handles PROJEKT.md
  • This skill handles CLAUDE.md
  • Different algorithms for different content types

Size Targets

ComponentTargetNotes
Total CLAUDE.md<8KBErreichbar mit Vault-First Compact Block
Vault-First Compact Block~4KBFeature Detection + Dual-Path (statt ~10KB inline)
Project-specific~3KBArchitecture, guidelines, conventions
Decision Log inline<500BLink + 3 summaries
Other sectionsMinimalUse Modular Disclosure (outsource)

Mit Vault-First Compact Block: Das 8KB-Ziel ist realistisch:

  • Compact Block: ~4KB (statt ~10KB Full Injection oder ~1.5KB old reference)
  • Compact Block enthaelt: Feature Detection, Vault-First/Local Fallback, Session Lifecycle
  • Detail-Referenz: session-workflow Skill (on-demand, nicht inline)

Troubleshooting

Issue: "Exit code 2 after optimization" Cause: workflow-block.txt alone is ~8KB Fix: Accept 10-12KB as realistic target for projects with full workflow injection

Issue: "Decision Log not found" Cause: Non-standard heading format Fix: Ensure heading is ## Decision Log (exact)

Issue: "Injection markers missing after optimization" Cause: Manual editing removed markers Fix: Re-add markers around Session-Continuous Workflow section

Issue: "/project-init fails after optimization" Cause: "Session-Continuous Workflow" string removed Fix: Ensure this exact string exists in CLAUDE.md (in heading or content)

Success Criteria

After optimization:

  • Size < 12KB (realistic) or < 8KB (ideal)
  • Decision Log externalized to docs/DECISION-LOG.md
  • Workflow injection markers present
  • "Session-Continuous Workflow" string exists
  • Modular Disclosure applied (resolved sections outsourced or removed)
  • /run-next-tasks still works

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.