From agent-almanac
Refactors over-long or poorly structured SKILL.md files by extracting examples, splitting compound procedures, and reorganizing sections for progressive disclosure.
How this skill is triggered — by the user, by Claude, or both
Slash command
/agent-almanac:refactor-skill-structureThis skill is limited to the following tools:
The summary Claude sees in its skill listing — used to decide when to auto-load this skill
Refactor a SKILL.md that has exceeded the 500-line limit or developed structural problems. This skill extracts extended code examples to `references/EXAMPLES.md`, splits compound procedures into focused sub-procedures, adds cross-references for progressive disclosure, and verifies the skill remains complete and valid after restructuring.
Refactor a SKILL.md that has exceeded the 500-line limit or developed structural problems. This skill extracts extended code examples to references/EXAMPLES.md, splits compound procedures into focused sub-procedures, adds cross-references for progressive disclosure, and verifies the skill remains complete and valid after restructuring.
references/EXAMPLES.md (default: yes, if extractable content exists)Read the skill and create a section-by-section line budget to identify where the bloat is.
# Total line count
wc -l < skills/<skill-name>/SKILL.md
# Line count per section (approximate)
grep -n "^## \|^### " skills/<skill-name>/SKILL.md
Classify bloat sources:
Expected: A line budget showing which sections are over-sized and which bloat category applies to each. The largest sections are the primary refactoring targets.
On failure: If the skill is under 500 lines and no structural issues are apparent, this skill may not be needed. Verify the refactoring request is justified before proceeding.
Move code blocks longer than 15 lines to a references/EXAMPLES.md file, leaving brief inline snippets (3-10 lines) in the main SKILL.md.
Create the references directory:
mkdir -p skills/<skill-name>/references/
For each extractable code block:
references/EXAMPLES.md under a descriptive headingSee [EXAMPLES.md](references/EXAMPLES.md#heading) for the complete configuration.Structure references/EXAMPLES.md with clear headings:
# Examples
## Example 1: Full Configuration
Complete configuration file for [context]:
\```yaml
# ... full config here ...
\```
## Example 2: Multi-Variant Setup
### Variant A: Development
\```yaml
# ... dev config ...
\```
### Variant B: Production
\```yaml
# ... prod config ...
\```
Expected: All code blocks >15 lines are extracted. The main SKILL.md retains brief inline snippets for readability. Cross-references link to the extracted content. references/EXAMPLES.md is well-organized with descriptive headings.
On failure: If extracting code blocks does not reduce the line count sufficiently (still over 500), proceed to Step 3 for procedure splitting. If the skill has very few code blocks (e.g., a natural-language skill), focus on Steps 3 and 4 instead.
Identify procedure steps that perform multiple unrelated operations and split them.
Signs of a compound step:
For each compound step:
### Step N: for each operationExpected: Each procedure step does one thing. No step exceeds 30 lines. Step count may increase but each step is independently verifiable.
On failure: If splitting a step creates steps that are too granular (e.g., 20+ total steps), consider grouping related micro-steps under a single step with numbered sub-steps instead. The sweet spot is 5-12 procedure steps.
Ensure the main SKILL.md maintains readability and discoverability after extraction.
For each extraction:
[EXAMPLES.md](references/EXAMPLES.md#section-anchor)Cross-reference patterns:
See [EXAMPLES.md](references/EXAMPLES.md#full-configuration) for the complete configuration with all options.See [EXAMPLES.md](references/EXAMPLES.md#variants) for development, staging, and production variants.See [EXAMPLES.md](references/EXAMPLES.md#troubleshooting) for additional error scenarios.Expected: Every extraction has a corresponding cross-reference. A reader can follow the main SKILL.md for the common case and drill into references for details.
On failure: If cross-references make the text flow awkward, consolidate multiple references into a single note at the end of the procedure step: For extended examples including [X], [Y], and [Z], see [EXAMPLES.md](references/EXAMPLES.md).
Re-measure the SKILL.md line count after all changes.
# Check main SKILL.md
lines=$(wc -l < skills/<skill-name>/SKILL.md)
[ "$lines" -le 500 ] && echo "SKILL.md: OK ($lines lines)" || echo "SKILL.md: STILL OVER ($lines lines)"
# Check references file if created
if [ -f skills/<skill-name>/references/EXAMPLES.md ]; then
ref_lines=$(wc -l < skills/<skill-name>/references/EXAMPLES.md)
echo "EXAMPLES.md: $ref_lines lines"
fi
# Total content
echo "Total content: $((lines + ${ref_lines:-0})) lines"
Expected: SKILL.md is under 500 lines. Ideally under 400 lines to leave room for future growth. The references/EXAMPLES.md has no line limit.
On failure: If still over 500 lines after extraction and splitting, consider whether the skill should be decomposed into two separate skills. A skill covering too much ground is a sign of scope creep. Use create-skill to author the second skill and update Related Skills cross-references in both.
After refactoring, verify the skill still has all required sections and the frontmatter is intact.
Run the review-skill-format checklist:
# Quick section check
for section in "## When to Use" "## Inputs" "## Procedure" "## Common Pitfalls" "## Related Skills"; do
grep -q "$section" skills/<skill-name>/SKILL.md && echo "$section: OK" || echo "$section: MISSING"
done
grep -qE "## Validation( Checklist)?" skills/<skill-name>/SKILL.md && echo "Validation: OK" || echo "Validation: MISSING"
Expected: All sections present. No content was accidentally deleted during extraction. Cross-references in SKILL.md resolve to actual headings in EXAMPLES.md.
On failure: If a section was accidentally removed, restore it from git history: git diff skills/<skill-name>/SKILL.md to see what changed. If cross-references are broken, verify the heading anchors in EXAMPLES.md match the links in SKILL.md (GitHub-flavored markdown anchor rules: lowercase, hyphens for spaces, strip punctuation).
references/EXAMPLES.md with descriptive headingsreview-skill-format validation passes on the refactored skillgrep -c "heading-text" references/EXAMPLES.md.review-skill-format — Run format validation after refactoring to confirm the skill is still compliantupdate-skill-content — Content updates are often the trigger for structural refactoring when they push a skill over the line limitcreate-skill — Reference the canonical structure when deciding how to organize extracted contentevolve-skill — When a skill needs to be split into two separate skills, use evolution to create the derivativenpx claudepluginhub pjt222/agent-almanacAssesses oversized or multi-domain Claude Code skills and refactors by splitting or extracting references. Use for token threshold violations (SK006/SK007) or multiple independent domains.
Refines existing SKILL.md content: updates procedure steps, expands Common Pitfalls, synchronizes Related Skills, and bumps version. Use when procedures are vague, references are stale, or feedback indicates gaps.
Guides decisions on splitting Claude skill content between SKILL.md and reference files for context efficiency and reliable triggering. Use when creating or refactoring skills, SKILL.md exceeds 300-400 lines, or mentions progressive disclosure.